-
Notifications
You must be signed in to change notification settings - Fork 3.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
Sanitize __amp_source_origin from templates URLs #4670
Conversation
expect(() => resolveUrlAttr('a', 'href', | ||
'/doc2?__amp_source_origin=https://google.com', | ||
'http://acme.org/doc1')) | ||
.to.throw(/Source origin is not allowed in/); |
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.
nit: need to indent 4 spaces more.
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.
Done.
LGTM |
@@ -286,6 +286,9 @@ function resolveAttrValue(tagName, attrName, attrValue) { | |||
* @private Visible for testing. | |||
*/ | |||
export function resolveUrlAttr(tagName, attrName, attrValue, windowLocation) { | |||
user().assert(attrValue.indexOf('__amp_source_origin') == -1, |
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.
Shall we extract a shared constant for __amp_source_origin
?
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.
I think this is fine, the other option is to import the constant defined in another file (since this string is being used in multiple files now) which might add more to the obfuscation. Not sure, @erwinmombay?
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's declared in url.js
, how about just import from there.
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.
Done
@@ -38,7 +38,7 @@ let cache; | |||
const AMP_JS_PARAMS_REGEX = /[?&]amp_js[^&]*/; | |||
|
|||
/** @private @const {string} */ |
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.
remove @private
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.
Done
LGTM. |
Does this work when one or more characters of __amp_source_origin are percent encoded? |
Closes #4661
ITI: #3343