Skip to content

Commit

Permalink
Sanitize HTML attributes that come from extended attributes. Fixes #114.
Browse files Browse the repository at this point in the history
  • Loading branch information
bhollis committed Dec 16, 2013
1 parent c35f215 commit 7363179
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/maruku/output/to_html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ def html_element(name, content="", attributes={})

Array(HTML4Attributes[name]).each do |att|
if v = @attributes[att]
attributes[att.to_s] = v.to_s
attributes[CGI.escapeHTML(att.to_s)] = CGI.escapeHTML(v.to_s)
end
end
content = yield if block_given?
Expand Down
22 changes: 22 additions & 0 deletions spec/block_docs/attribute_sanitize.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Make sure extended attributes get escaped when generating HTML: https://github.com/bhollis/maruku/issues/114
*** Parameters: ***
{} # params
*** Markdown input: ***
*foo*{: style='ball & chain'}

*foo*{: style='ball\008 chain'}

*foo*{: style='ball\" badAttribute=\"chain'}
*** Output of inspect ***
md_el(:document, [
md_par(md_em("foo", [["style", "ball & chain"]])),
md_par(md_em("foo", [["style", "ball\\008 chain"]])),
md_par(md_em("foo", [["style", "ball\" badAttribute=\"chain"]]))
])
*** Output of to_html ***
<p><em style="ball &amp; chain">foo</em>
</p>
<p><em style="ball\008 chain">foo</em>
</p>
<p><em style="ball&quot; badAttribute=&quot;chain">foo</em>
</p>

2 comments on commit 7363179

@distler
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd prefer to remove illegal characters (like U+0008), rather than allow them through.

@bhollis
Copy link
Owner Author

Choose a reason for hiding this comment

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

More sanitization added in 1911554.

Please sign in to comment.