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

[CSS Sanitizer] Allow more css length units #178

Merged
merged 7 commits into from
Nov 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/loofah/html5/scrub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Loofah
module HTML5 # :nodoc:
module Scrub
CONTROL_CHARACTERS = /[`\u0000-\u0020\u007f\u0080-\u0101]/
CSS_KEYWORDISH = /\A(#[0-9a-fA-F]+|rgb\(\d+%?,\d*%?,?\d*%?\)?|-?\d{0,3}\.?\d{0,10}(cm|r?em|ex|in|mm|pc|pt|px|%|,|\))?)\z/
CSS_KEYWORDISH = /\A(#[0-9a-fA-F]+|rgb\(\d+%?,\d*%?,?\d*%?\)?|-?\d{0,3}\.?\d{0,10}(ch|cm|r?em|ex|in|lh|mm|pc|pt|px|Q|vmax|vmin|vw|vh|%|,|\))?)\z/
CRASS_SEMICOLON = { :node => :semicolon, :raw => ";" }

class << self
Expand Down
42 changes: 42 additions & 0 deletions test/html5/test_sanitizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,48 @@ def test_css_rem_value
assert_match %r/10rem/, sane.inner_html
end

def test_css_ch_value
html = "<div style=\"width:60ch;\">"
sane = Nokogiri::HTML(Loofah.scrub_fragment(html, :escape).to_xml)
assert_match %r/60ch/, sane.inner_html
end

def test_css_vw_value
html = "<div style=\"font-size: calc(16px + 1vw);\"></body>"
sane = Nokogiri::HTML(Loofah.scrub_fragment(html, :escape).to_xml)
assert_match %r/1vw/, sane.inner_html
end

def test_css_vh_value
html = "<div style=\"height: 100vh;\"></body>"
sane = Nokogiri::HTML(Loofah.scrub_fragment(html, :escape).to_xml)
assert_match %r/100vh/, sane.inner_html
end

def test_css_Q_value
html = "<div style=\"height: 10Q;\"></body>"
sane = Nokogiri::HTML(Loofah.scrub_fragment(html, :escape).to_xml)
assert_match %r/10Q/, sane.inner_html
end

def test_css_lh_value
html = "<p style=\"line-height: 2lh;\"></body>"
sane = Nokogiri::HTML(Loofah.scrub_fragment(html, :escape).to_xml)
assert_match %r/2lh/, sane.inner_html
end

def test_css_vmin_value
html = "<div style=\"width: 42vmin;\"></body>"
sane = Nokogiri::HTML(Loofah.scrub_fragment(html, :escape).to_xml)
assert_match %r/42vmin/, sane.inner_html
end

def test_css_vmax_value
html = "<div style=\"width: 42vmax;\"></body>"
sane = Nokogiri::HTML(Loofah.scrub_fragment(html, :escape).to_xml)
assert_match %r/42vmax/, sane.inner_html
end

def test_css_function_sanitization_leaves_safelisted_functions_calc
html = "<span style=\"width:calc(5%)\">"
sane = Nokogiri::HTML(Loofah.scrub_fragment(html, :strip).to_html)
Expand Down