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 __amp_source_origin from templates URLs #4670

Merged
merged 4 commits into from
Aug 24, 2016

Conversation

mkhatib
Copy link
Contributor

@mkhatib mkhatib commented Aug 23, 2016

Closes #4661

ITI: #3343

expect(() => resolveUrlAttr('a', 'href',
'/doc2?__amp_source_origin=https://google.com',
'http://acme.org/doc1'))
.to.throw(/Source origin is not allowed in/);
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@lannka
Copy link
Contributor

lannka commented Aug 23, 2016

LGTM

@lannka lannka added LGTM and removed NEEDS REVIEW labels Aug 23, 2016
@@ -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,
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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} */
Copy link
Contributor

Choose a reason for hiding this comment

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

remove @private

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@lannka
Copy link
Contributor

lannka commented Aug 23, 2016

LGTM.

@mkhatib mkhatib merged commit c9fe0d2 into ampproject:master Aug 24, 2016
@mkhatib mkhatib deleted the csrf-templates branch August 24, 2016 03:38
@molnarg
Copy link

molnarg commented Aug 24, 2016

Does this work when one or more characters of __amp_source_origin are percent encoded?

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.

3 participants