Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

link_to XSS problem

#3952
not_safe = "<i>XSS is fun</i>"
link_to(not_safe, some_path)

produces:

<a href=\"hi\"><i>XSS is fun</i></a>

when I believe it should instead check .html_safe? on the "name" arg, and escape it if it is not safe, producing:

<a href=\"hi\">&lt;i&gt;XSS is fun&lt;/i&gt;</a>

Reported by Greg Hazel · February 13th, 2010 @ 07:52 PM

State: resolved
Milestone: 2.3.6
Assigned to: Michael Koziarski Michael Koziarski
Importance: Medium

Activity

  1. Ryan Bigg
    Ryan Bigg

    -1

    I cannot reproduce this on the latest edge. Perhaps it has recently been fixed?

    March 3rd, 2010 @ 09:32 PM

  2. Greg Hazel
    Greg Hazel

    This was with 2.3.5. It does look like it's fixed in Rails 3.

    Backport?

    March 3rd, 2010 @ 09:40 PM

  3. Santiago Pastorino
    Santiago Pastorino
    • State changed from new to wontfix

    That's the expected behavior. On 2.3 if you want to escape unsafe text you have to do it explicitly or use http://github.com/rails/rails_xss to activate xss protection.
    Please continue helping but tag the issues with the appropiate rails version

    March 4th, 2010 @ 12:03 AM

  4. Santiago Pastorino
    Santiago Pastorino
    • Tag changed from html_safe link_to to html_safe link_to, 2.3.x

    March 4th, 2010 @ 12:06 AM

  5. Greg Hazel
    Greg Hazel

    Using rails_xss does not fix the problem. The unsafe HTML is included in the link_to tag, and marked as safe!

    March 4th, 2010 @ 12:07 AM

  6. Jeremy Kemper
    Jeremy Kemper
    • State changed from wontfix to open
    • Assigned user set to Michael Koziarski
    • Milestone set to 2.3.6

    March 4th, 2010 @ 02:01 AM

  7. Santiago Pastorino
    Santiago Pastorino

    First of all, that's the expected behavior without rails_xss.
    But anyways sorry i wasn't clear enough, I should have said that it works on latest 2-3-stable branch and using http://github.com/rails/rails_xss
    That was already fixed with the Backport José and i did of master branch.

    See links below:
    http://github.com/rails/rails/commit/9ca6df83f606a0fb8be3815328111d...
    http://github.com/rails/rails_xss/commit/8a6fc54a9b3a715fb3c73d8c73...

    Perhaps i shouldn't change the state to wontfix but resolved or duplicate

    March 4th, 2010 @ 11:12 AM

  8. Greg Hazel
    Greg Hazel

    Oh! I wasn't aware of http://github.com/rails/rails_xss I'm currently using http://github.com/NZKoz/rails_xss with 2.3.5

    Should I switch? Should everyone?

    March 4th, 2010 @ 11:15 AM

  9. Santiago Pastorino
    Santiago Pastorino

    http://github.com/rails/rails_xss doesn't work with 2.3.5.
    You should use it with the next 2.3.6 or for now 2-3-stable branch

    March 4th, 2010 @ 11:22 AM

  10. Greg Hazel
    Greg Hazel

    Hm. I guess I'll wait for 2.3.6.

    March 4th, 2010 @ 11:23 AM

  11. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to resolved

    March 4th, 2010 @ 11:55 AM

  12. Greg Hazel
    Greg Hazel

    This bug still exists using Rails 2.3.8 and http://github.com/rails/rails_xss

    not_safe = "<i>XSS is fun</i>"
    link_to(not_safe, "/")
    
    # =>
    
    <a href=\"/\"><i>XSS is fun</i></a>
    

    May 26th, 2010 @ 01:08 AM

  13. Santiago Pastorino
    Santiago Pastorino

    Please can you upload a zip with your app?

    May 26th, 2010 @ 01:33 AM

  14. Greg Hazel
    Greg Hazel

    This shows the bug, but maybe I am just not including all the right helpers, since it does work from a template.

    foo.rb

    class << self
      include ActionView::Helpers::UrlHelper
      include ActionView::Helpers::TagHelper
    end
    not_safe = "<i>XSS is fun</i>"
    puts link_to(not_safe, "/").inspect
    
    > ruby script/runner foo.rb
    "<a href=\"/\"><i>XSS is fun</i></a>"
    

    May 26th, 2010 @ 02:02 AM

  15. Santiago Pastorino
  16. Greg Hazel
    Greg Hazel

    Indeed it does! Thanks! This ticket is done, from my perspective.

    May 26th, 2010 @ 10:26 PM