amphtml icon indicating copy to clipboard operation
amphtml copied to clipboard

Unknown path prefix in url <AMP cache domain> for remote HTML on page with referer canonical meta tag

Open keithwrightbos opened this issue 9 years ago • 11 comments

Steps to reproduce:

  • go to AMP cache page with amp-ad doubleclick and remote HTML. Example: https://www.google.com/amp/www.etonline.com/taylor-swifts-epic-look-what-you-made-me-do-music-video-decoded-86168%3famp
  • draw3p within remote HTML fails with stacktrace: Error: Unknown path prefix in url https://www-etonline-com.cdn.ampproject.org/​​​ at na.g.assert (log.js:319) at Ua (url.js:384) at window.draw3p (url.js:368) at remote.html?1504040004635:25

Issues does not occur when going directly to publisher page: http://www.etonline.com/taylor-swifts-epic-look-what-you-made-me-do-music-video-decoded-86168?amp

keithwrightbos avatar Aug 30 '17 21:08 keithwrightbos

Code trace shows that passes window.document.referrer to url#getSourceUrl which fails because referrer is just the domain ("https://www-etonline-com.cdn.ampproject.org/") and not a full path (thus missing path).

const path = url.pathname.split('/'); const prefix = path[1]; user().assert(prefix == 'a' || prefix == 'c' || prefix == 'v', 'Unknown path prefix in url %s', url.href);

keithwrightbos avatar Aug 30 '17 21:08 keithwrightbos

Issue is due to publisher setting <meta content="origin" name="referrer"> in the head of their AMP document which is causing frames to lose access to anything but the domain. Perhaps the AMP code should be more tolerant of this case and simply verify that the domain matches expectations?

keithwrightbos avatar Aug 30 '17 21:08 keithwrightbos

Thank you. We’ve asked the site time to make this change.

Related to domain permissions, if the site had a CSP policy in place with the below values, would this bug have been mitigated? Or would AMP have still been blocked by the bad meta tag? frame-ancestors 'self' *.etonline.com *.ampproject.org;

boyadamsam avatar Aug 30 '17 21:08 boyadamsam

The issue is unique to how AMP verifies the referer of the remote HTML frame by using document.referrer so unrelated to CSP. The site could remove (or loosen) the referrer restriction via the meta tag and use a CSP to control which iframes are allowed to load. This assumes they only want to allow remote HTML based iframes. I believe other extensions (especially amp-iframe) use cross domain iframes which would be constrained by the CSP.

keithwrightbos avatar Aug 31 '17 00:08 keithwrightbos

Thanks @keithwrightbos for debugging into this. If I understand the investigation correctly, the error is thrown here.

In remote.html, the pub whitelisted host origins to avoid being embedded in unknown host page. However, in this case, the host page is "misconfigured" so AMP runtime can't verify its canonical origin (it needs full referrer URL to be able to convert a CDN URL to canonical URL).

IMO, pub has a valid use case, we should be able to fail gracefully. In this case, we can't extract the canonical origin from referrer URL, then we should just fallback to the CDN origin. Pub can still have the whole thing functioning by adding the CDN origin to its whitelist.

lannka avatar Sep 13 '17 17:09 lannka

This issue hasn't been updated in awhile. @lannka Do you have any updates?

ampprojectbot avatar Dec 18 '17 21:12 ampprojectbot

@keithwrightbos @lannka

I've arrived to this issue because I'm having this same error. This in not only happening inside a remote.html IFRAME, you can also reproduce it if the AMP page being loaded from the AMP cache contains

  1. The <meta content="origin" name="referrer"> in the head
  2. An anchor linking to another AMP page, that will load outside the AMP cache (i.e https://amp.example.com/path)

If a user taps the AMP link the AMP runtime of the second page will throw this error when trying to parse the referral, since it does not have access to the path of the referral (due <meta content="origin" name="referrer"> restriction)

The error stacktrace starts in amp-analytics but the page view call seems to be done properly

oliverfernandez avatar Jan 08 '18 12:01 oliverfernandez

This issue hasn't been updated in awhile. @lannka Do you have any updates?

ampprojectbot avatar Jun 05 '18 12:06 ampprojectbot

This issue hasn't been updated in awhile. @lannka Do you have any updates?

ampprojectbot avatar Sep 11 '18 13:09 ampprojectbot

This issue hasn't been updated in awhile. @lannka Do you have any updates?

ampprojectbot avatar Jan 09 '19 11:01 ampprojectbot

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Dec 24 '20 23:12 stale[bot]