Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escaping is being done on static HTML in results of <%= cache... %> calls and tabnav plugin output #11

Open
weyus opened this issue Jan 25, 2010 · 5 comments

Comments

@weyus
Copy link

weyus commented Jan 25, 2010

Rails 2.3.5

I installed this plugin and saw most of my page start displaying HTML source. It appears that the static HTML in the output of a call like:

<% cache "header-#{current_user.id}", 1.day.from_now do -%>
<%= render :partial => '/layouts/header' %>
<% end -%>

or

<%= start_tabnav :customer %>
<%= show_flash(:success) %>
<%= show_flash(:notice) %>
<%= show_flash(:error) %>
<%= yield %>
<%= end_tabnav %>

is being escaped, thus showing up as raw text in the browser.

@NZKoz
Copy link
Owner

NZKoz commented Jan 25, 2010

the cache case looks like it could be a bug

Could you paste the implementation of your tab / flash helpers into a gist for me to take a look at? That's either a bug in rails_xss or a change you need to make to your code.

@weyus
Copy link
Author

weyus commented Jan 25, 2010

Here's the gist: http://gist.github.com/286289

It looks like I need to call raw in front of each of these, as in:

<%= raw show_flash... %>
<%= raw start_tabnav... %>

@NZKoz
Copy link
Owner

NZKoz commented Jan 25, 2010

Yes, you'll need to either call raw in your views, or modify your helpers to pre-mark those strings as safe. e.g.

(result + css).html_safe!

A String is considered safe ONLY if we're told it's safe, we don't try to guess based on the content as this is likely to lead to security bugs. We've made efforts to ensure that all helpers which use the built-in tag helpers will be 'magically' safe, but for your kind of helpers where you're manipulating big strings, you'll have to do the marking yourself

However the cache case seems like it should work out of the box.

@weyus
Copy link
Author

weyus commented Jan 25, 2010

Many thanks.

BTW, I think this is a great feature to add to the default set of features in Rails 3.

@NZKoz
Copy link
Owner

NZKoz commented Jan 25, 2010

Yes, it's already been included ;)

grosser referenced this issue in grosser/rails_xss Aug 19, 2012
Fix escape_javascript to support SafeBuffer strings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants