auto-redirect executes within ad
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
/cc @lannka
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 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.
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
From what I'm reading here,
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!
This issue seems to be in Pending Triage for awhile. @zhouyx Please triage this to an appropriate milestone.
I don't think we apply sandbox to ad iframe. to @lannka
Let's continue the "enabling ad sandbox" topic here #14240