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

Escape attributes regardless of whether it's SafeBuffer or not #1028

Merged
merged 2 commits into from Jul 15, 2020

Conversation

k0kubun
Copy link
Member

@k0kubun k0kubun commented Jun 22, 2020

Fixes #993, fixes #1019

Like rails helpers fixed in CVE-2016-6316, an attribute should be HTML-escaped even if it's a SafeBuffer.

@k0kubun k0kubun requested a review from amatsuda June 22, 2020 05:25
@@ -607,9 +607,12 @@ def haml_tag_if(condition, *tag)
# @param text [String] The string to sanitize
# @return [String] The sanitized string
def html_escape(text)
ERB::Util.html_escape(text)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ActiveSupport monkey-patches this method for html_safe?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely like seeing the CGI version vs leaning on ActiveSupport

Copy link
Member

@HamptonMakes HamptonMakes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one change of breaking out that test, and you are good-to-merge from my perspective.

lib/haml/escapable.rb Show resolved Hide resolved
@@ -607,9 +607,12 @@ def haml_tag_if(condition, *tag)
# @param text [String] The string to sanitize
# @return [String] The sanitized string
def html_escape(text)
ERB::Util.html_escape(text)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely like seeing the CGI version vs leaning on ActiveSupport

test/template_test.rb Outdated Show resolved Hide resolved
@k0kubun k0kubun dismissed HamptonMakes’s stale review July 14, 2020 17:09

Fixed commented places

@HamptonMakes HamptonMakes self-requested a review July 15, 2020 21:50
@HamptonMakes
Copy link
Member

I think you misunderstood what I meant about the files... let me show you in a next PR.

@gurgeous
Copy link

Pardon my ignorance here - won't this double escape?

# in rails console
Haml::Engine.new("%p{title: html_escape('hi &')}").render
=> "<p title='hi &amp;amp;'></p>\n"

That seems incorrect and is causing problems for my app. Should we adopt the Rails fix and only escape the quotes? See rails/rails@v4.2.7...v4.2.7.1

        def tag_option(key, value, escape)
          if value.is_a?(Array)
            value = escape ? safe_join(value, " ") : value.join(" ")
          else
            value = escape ? ERB::Util.unwrapped_html_escape(value) : value
          end
          %(#{key}="#{value.gsub(/"/, '&quot;'.freeze)}")
        end

@k0kubun
Copy link
Member Author

k0kubun commented Feb 18, 2021

Could you open a separate issue or pull request? Because that is an intended behavior in this PR, it seems like a new feature. Double escaping could happen for many other cases when you escape something where escaping automatically happens, and that place is where you don't need to escape it since Haml 5+.

@gurgeous
Copy link

Yes, of course, thank you for the quick response!

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

Successfully merging this pull request may close these issues.

escape_attrs wraps incorrectly? attribute with safe-buffer containing a apostrophe is not escaped
3 participants