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 all commits
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
4 changes: 4 additions & 0 deletions src/sanitizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
isProxyOrigin,
parseUrl,
resolveRelativeUrl,
SOURCE_ORIGIN_PARAM,
} from './url';
import {parseSrcset} from './srcset';
import {user} from './log';
Expand Down Expand Up @@ -286,6 +287,9 @@ function resolveAttrValue(tagName, attrName, attrValue) {
* @private Visible for testing.
*/
export function resolveUrlAttr(tagName, attrName, attrValue, windowLocation) {
user().assert(attrValue.indexOf(SOURCE_ORIGIN_PARAM) == -1,
'Source origin is not allowed in %s', attrValue);

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

Expand Down
4 changes: 2 additions & 2 deletions src/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ let cache;
/** @private @const Matches amp_js_* paramters in query string. */
const AMP_JS_PARAMS_REGEX = /[?&]amp_js[^&]*/;

/** @private @const {string} */
const SOURCE_ORIGIN_PARAM = '__amp_source_origin';
/** @const {string} */
export const SOURCE_ORIGIN_PARAM = '__amp_source_origin';

/**
* @typedef {({
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/);
});

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