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

Sanitize href values #249

Merged
merged 2 commits into from
May 30, 2019
Merged

Conversation

coreyward
Copy link
Contributor

Previously links like <a href="javascript:alert('hi')">Foo</a> were passed through unsanitized while [javascript:alert('hi')](Foo) was sanitized. This change makes both sanitized, and also escapes any other href attributes.

This fixes #239. This also includes a change to prevent element name case from subverting the HTML element blacklist.

@codecov
Copy link

codecov bot commented May 14, 2019

Codecov Report

Merging #249 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #249      +/-   ##
==========================================
+ Coverage   99.72%   99.72%   +<.01%     
==========================================
  Files           1        1              
  Lines         363      365       +2     
  Branches       57       58       +1     
==========================================
+ Hits          362      364       +2     
  Misses          1        1
Impacted Files Coverage Δ
index.js 99.72% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9570018...024d45a. Read the comment docs.

@codecov
Copy link

codecov bot commented May 14, 2019

Codecov Report

Merging #249 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #249      +/-   ##
==========================================
+ Coverage   99.72%   99.72%   +<.01%     
==========================================
  Files           1        1              
  Lines         365      367       +2     
  Branches       58       59       +1     
==========================================
+ Hits          364      366       +2     
  Misses          1        1
Impacted Files Coverage Δ
index.js 99.72% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8d32453...4ddd526. Read the comment docs.

@quantizor
Copy link
Owner

@coreyward this'll need a rebase - merged another PR that handled the uppercase version of script & style tags

@coreyward
Copy link
Contributor Author

@probablyup Done. Went ahead and dropped the functionally-identical commit.

version "1.2.7"
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-1.2.7.tgz#4851b664a3783e52003b3c66eb0eee1074933aa4"
integrity sha512-Pxm6sI2MeBD7RdD12RYsqaP0nMiwx8eZBXCa6z2L+mRHm2DYrOYwihmhjpkdjUHwQhslWQjRpEgNq4XvBmaAuw==
fsevents@^1.0.0, fsevents@^1.2.3, fsevents@^1.2.7, fsevents@^1.2.9:
Copy link
Owner

Choose a reason for hiding this comment

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

can you drop these lockfile changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was deliberate to get Node v12+ support. I can pull it but it shouldn’t impact downstream dependents, it’ll just mean I can’t contribute.

@@ -374,6 +374,8 @@ function attributeValueToJSXPropValue(key, value) {

return styles;
}, {});
} else if (key === 'href') {
Copy link
Owner

Choose a reason for hiding this comment

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

is this needed for src too on image tags for example?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call, I believe so. I’ll check and add support for this if needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, it looks like only ≤ IE6 are affected by this (modern browsers don't execute javascript-scheme src attrs), and since ReactDOM doesn't work on IE6, I think we're in the clear.

Copy link
Owner

Choose a reason for hiding this comment

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

Ok but we still need it for href?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep; React will gleefully pass these through and browsers interpret them.

@quantizor quantizor changed the title Sanitize href values, fix script/style sanitization Sanitize href values May 29, 2019
Copy link
Owner

@quantizor quantizor left a comment

Choose a reason for hiding this comment

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

Thanks, this is great!

@quantizor quantizor merged commit 62977a6 into quantizor:master May 30, 2019
@quantizor
Copy link
Owner

Released as 6.10.2 😄

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.

Link sanitization for javascript: urls not working
2 participants