-
Notifications
You must be signed in to change notification settings - Fork 142
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
Backport tests and fix for CVE-2018-3740 to 2.x branch. Resolves #187 #188
Conversation
# Leading and trailing whitespace around URLs is ignored at parse | ||
# time. Stripping it here prevents it from being escaped by the | ||
# libxml2 workaround below. | ||
attr.value = attr.value.strip |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems at this point it is already possible that attr
has been unlinked, but the do
loop continues with the same attr
. Should the new code somehow be made conditional on whether attr
has been unlinked yet, for performance reasons? (No use doing the strip
and the gsub
if attr
is already sanitized, I take it?)
Getting the same failures on Travis. As I said I'm getting the same failures on a fresh checkout of On a closer look, there seems to be one additional failure on this branch than on the
EDIT: just changing the expected result is not acceptable because |
It's the
After the
So it seems that in I am now omitting the The five remaining failures are those that are already present on vanilla |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
The test failures on the 2.x branch are most likely due to changes in the output of newer versions of Nokogiri that didn’t exist when the tests were written. As long as the output produced by modern Nokogiri is safe and sane, it should be fine to update the expected output to match Nokogiri’s current output.
EDIT: just changing the expected result is not acceptable because
<img src>
is (I assume) not valid HTML.
<img src>
isn’t technically valid, but it is safe, and safety is more important than validity. I would prefer this output over skipping stripping/escaping on space-only values. It would also be fine to remove the empty src
attribute, since it’s useless (more on this in my diff comments).
Thanks for the comments, @rgrove! Will get to work on them. |
* Only strip attribute when it concerns a url * Fix expected test output for image tag with empty src
Green lights. Please have a look at the new implementation in I took the liberty of bumping version and updating HISTORY for your convenience (though do change the release date if you don't get round to cutting the gem today). |
See #187
I'm getting six test failures locally, but upon inspection it seems that I already get these when I checkout the
2.x
branch unmodified. The failures are all of this form:That is, there is an unexpected
<
before "script". We'll see what happens on Travis.The newly backported tests in
test_malicious_html.rb
andtest_clean_element.rb
all pass, though.