ampproject / ampproject/amphtml
Make 3p iframe subdomains unique but deterministic.
- Dominant language
- JavaScript
- Stars
- 14.9k
- Forks
- 4.1k
- PR merge metrics
- No merged PRs in 30d
Description
## Summary
Make 3p iframe subdomains unique but deterministic.
## Motivation
Currently, the 3p iframes that are used for ads and other sandboxed features utilize fully random hostnames on each page load. All 3p iframes on the current page use the same origin so that, among themselves, they are same-origin but cross-origin to the parent document. However, on each page load, the hostname/origin that is used to create the 3p iframes is generated based on a new random value. So, multiple accesses to the same page will never utilize the same origin for the 3p iframes.
I suspect that the above was done in order to protect from information leakage between unaffiliated AMP requests (ie not leaking information between different pages). This is a very valid privacy and security issue that should remain in place, however utilizing a fully-random hostname causes issues for some implementation, such as an ad network that might try to cache information in localStorage, for instance. The use of the random origins means that a new localStorage instance will be used on each and every page load.
For the above reasons, I propose changing the 3p hostname generation logic to move away from `d-.ampproject.net` to using something like `d-.ampproject.net`. (Base32/SHA256 was chosen simply because that's the fallback mechanism used by the cache domain generation algorithm already.) This would maintain the cross-origin requirement with the top-level document and also maintain the origin separation between unaffiliated AMP documents (ie between pages coming from `example1.com` vs `example2.com`), helping to secure against information leakage, however it would also mean that the 3p iframes use repeating, deterministic
origins allowing things like localStorage to work as intended.
## Launch tracker
TBD
/cc @ampproject/wg-ads
Contributor guide
Assessment
This issue has not been assessed yet.