amphtml icon indicating copy to clipboard operation
amphtml copied to clipboard

auto-redirect executes within ad

Open coreybyrnes opened this issue 8 years ago • 7 comments

I was attempting to execute an automatic redirect (without user interaction) from within a DFP ad to make sure AMP would not allow it, but found a case where the automatic redirect can execute. I'll document my test cases here - cases 3 & 4 present what I believe to be the bug:

case 1 : redirect via window.top.location = "https://www.google.com" >>> the ad does not display, an "ad" icon placeholder appears

case 2 : redirect inside a setTimeout timer >>> the ad does not display, an "ad" icon placeholder appears

case 3 : redirect via window.top.location but comment it out, then immediately follow it with another window.top.location >>> the ad displays and immediately redirects the page

case 4 : redirect via window.top.location but comment it out, then immediately follow it with a redirect inside a setTimeout timer >>> the ad displays and redirects the page when the timer completes

So it seems AMP sees the initial redirect as commented and doesn't continue to check for further redirects? When the initial redirect is not commented, the ad does not display.

Here's a demo url I've put together - it's currently demonstrating case 4 so you can see the ad display before it automatically redirects without user interaction: http://rev.cbsi.com/corey/test/amp/amp_demo_200x200_redirect.html#development=1

coreybyrnes avatar Jan 30 '18 19:01 coreybyrnes

/cc @lannka

aghassemi avatar Jan 30 '18 23:01 aghassemi

AMP did not apply any restrictions on automatic redirect. DFP may have done something inside their iframe. But it's a good point, Can AMP use the sandbox = allow-top-navigation-by-user-activation attribute to prevent redirection without user interaction?

zhouyx avatar Jan 30 '18 23:01 zhouyx

@zhouyx Interesting. I'm wondering why AMP shows the "ad" placeholder for case 1 and case 2 then - I just assumed the script was being parsed by AMP and any attempt to redirect was being killed. I will schedule a creative to demo case 1 so your team can review...

As for sandboxing, the allow-top-navigation-by-user-activation flag has very limited browser support at this point so I wouldn't suggest it unless you had browser conditionals attached. The allow-scripts and allow-popups flags seem to be best at this point in order to allow scripts to run but not allow the top page to be auto-redirected and still allow for clicks with _blank set on their target attribute.

coreybyrnes avatar Jan 31 '18 00:01 coreybyrnes

Perhaps I was too quick with my testing yesterday? Not sure, but I just built a demo page for case 1 (simple immediate auto-redirect via window.top.location = "https://www.google.com") and the redirect executes immediately.

http://rev.cbsi.com/corey/test/amp/amp_demo_300x600_redirect.html#development=1

@zhouyx @lannka Our team was almost certain that AMP was implementing some sort of sandbox so that ads could not execute redirects or other potentially harmful scripts. Irrelevant, but when I look at the DOM I do see a sandbox=true but it's on the tag and not the ad iframe. If AMP truly doesn't implement any sort of sandboxing tactic I guess we can close this, but it does leave a giant hole for malicious ads.

From what I'm reading here, is sandboxed: https://www.ampproject.org/docs/reference/components/amp-iframe#sandbox

And I think the first paragraph here is reinforces why we thought amp-ads were sandboxed by default: https://www.ampproject.org/docs/reference/components/amp-ad#behavior

Can you provide some clarification on this? Thanks!

coreybyrnes avatar Jan 31 '18 15:01 coreybyrnes

This issue seems to be in Pending Triage for awhile. @zhouyx Please triage this to an appropriate milestone.

ampprojectbot avatar Jun 05 '18 08:06 ampprojectbot

I don't think we apply sandbox to ad iframe. to @lannka

zhouyx avatar Jul 16 '18 19:07 zhouyx

Let's continue the "enabling ad sandbox" topic here #14240

lannka avatar Aug 03 '18 22:08 lannka