rails3 xss escaping

1 view
Skip to first unread message

Marcelo Barbudas

unread,
Aug 30, 2010, 2:06:32 PM8/30/10
to Ruby on Rails: Talk
Hi.

Is there a way to disable the default xss escaping of everything in
rails3?

What's the proper way of doing string concatenations like below with
rails3 if xss escaping can not be disabled:
"something #{link_to('something else') if value == true}"

--
M.

Robert Walker

unread,
Aug 30, 2010, 2:45:39 PM8/30/10
to rubyonra...@googlegroups.com
Marcelo Barbudas wrote:
> Hi.
>
> Is there a way to disable the default xss escaping of everything in
> rails3?

I don't know of a way to disable it entirely, that's sort of the point.
Safe by default.

When you want to bypass the escaping you can use to use the 'raw'
method:

<%= raw my_unsafe_string %>

Think of this as the opposite of the old 'h' method.

> What's the proper way of doing string concatenations like below with
> rails3 if xss escaping can not be disabled:
> "something #{link_to('something else') if value == true}"

In helpers it's also possible to mark the string as html_safe:

"something #{link_to('something else') if value == true}".html_safe

Read this as, "I'm telling you that this is safe so don't escape it."
--
Posted via http://www.ruby-forum.com/.

Reply all
Reply to author
Forward
0 new messages