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
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/sanitizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

'Source origin is not allowed in %s', attrValue);

const isProxyHost = isProxyOrigin(windowLocation);
const baseUrl = parseUrl(getSourceUrl(windowLocation));

Expand Down
7 changes: 7 additions & 0 deletions test/functional/test-sanitizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ describe('sanitizeHtml', () => {

describe('resolveUrlAttr', () => {

it('should throw if __amp_source_origin is set', () => {
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.

});

it('should be called by sanitizer', () => {
expect(sanitizeHtml('<a href="/path"></a>')).to.match(/http/);
expect(sanitizeHtml('<amp-img src="/path"></amp-img>')).to.match(/http/);
Expand Down