-
Notifications
You must be signed in to change notification settings - Fork 46.9k
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
Ignore meta content attribute escaping to prevent invalid URLs #22041
Conversation
Hi @ihmpavel! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
Comparing: 2edf449...501df50 Critical size changesIncludes critical production bundles, as well as any change greater than 2%:
Significant size changesIncludes any change greater than 0.2%: Expand to show
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
I might be missing something, but isn't this essentially introducing a security hole? let post = await db.getPost()
function App() {
return (
<...>
<meta property='og:image' content={post.imageUrl} />
</...>
)
}
renderToString(<App />) Now let's say "'><script>alert("boom")</script><div class='" wouldn't this let it through? |
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.
this looks like an XSS hole to me
Hi, thank you for the review. I have rechecked the implementation and it is XSS for sure. I was looking in the source code, but I could not find the solution I will be happy with. I do not want to introduce a security hole, but I want to fix the current problem. Sanitizing HTML is important, but sometimes it is not working as we would like to (vercel/next.js#2006 or #13838). I was playing with some URL query parsers/servers and a lot of them could not get right params from sanitized url. ( Maybe Let me know if you have any other idea which will not be something |
Yeah (I think) I understand the high-level problem, but this solution isn’t something that would work. Let’s discuss on the linked issue. |
Summary
React automatically escapes HTML. Unfortunately for
<meta />
tags, escaping characters like&
to&
could break URLs. There are a lot of issues and there is no easy solution (at least for rawNext.js
hosted on Vercel). I know, escaping HTML is important, but it should not break URLs, which developers are not able to fix easily.This change is ignoring escaping
content
of<meta />
attribute.That means this tag
<meta property='og:image' content='https://example.com?query1=one&query2=two' />
will not become<meta property='og:image' content='https://example.com?query1=one&query2=two' />
, but stays the same. (Encoding the URL will make it fail)Also it prevents duplicating escaping
<meta property='og:image' content='https://example.com?query1=one&query2=two' />
to become<meta property='og:image' content='https://example.com?query1=one&amp;query2=two' />
.Altough we have
dangerouslySetInnerHTML
, there is no such way to change it for attributes (egcontent
in<meta />
), if it is not supported by<React.Fragment />
for insertinginnerHTML
.Some related issues
#13838
vercel/next.js#2006
garmeeh/next-seo#678
Test Plan