Skip to content
Open
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 extensions/amp-ad-exit/0.1/amp-ad-exit.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ export class AmpAdExit extends AMP.BaseElement {
.map(substituteVariables)
.forEach((url) => this.pingTrackingUrl_(url));
}
if (!Services.urlForDoc(this.element).isProtocolValid(target.finalUrl)) {
user().error(TAG, 'Invalid exit URL protocol: ' + target.finalUrl);
return;
}
const finalUrl = substituteVariables(target.finalUrl);
// TODO(wg-monetization): clean up unused HostServices.
if (HostServices.isAvailable(this.getAmpDoc())) {
Expand Down
31 changes: 31 additions & 0 deletions extensions/amp-ad-exit/0.1/test/test-amp-ad-exit.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,37 @@ describes.realWin(
);
});

it('should reject exit URLs with an invalid protocol', async () => {
const el = await makeElementWithConfig({
targets: {
js: {'finalUrl': /* eslint no-script-url: 0 */ 'javascript:alert(1)'},
data: {'finalUrl': 'data:text/html,<script>alert(1)</script>'},
},
});
const open = env.sandbox.stub(win, 'open');
const impl = await el.getImpl();

allowConsoleError(() =>
impl.executeAction({
method: 'exit',
args: {target: 'js'},
event: makeClickEvent(1001),
satisfiesTrust: () => true,
})
);
allowConsoleError(() =>
impl.executeAction({
method: 'exit',
args: {target: 'data'},
event: makeClickEvent(1001),
satisfiesTrust: () => true,
})
);

expect(open).to.not.have.been.called;
win.document.body.removeChild(el);
});

it('should enable attribution tracking when given `browserAdConversion`', async () => {
env.sandbox
.stub(AmpAdExit.prototype, 'detectAttributionReportingSupport')
Expand Down
Loading