-
Notifications
You must be signed in to change notification settings - Fork 26
Description
Motivation
Websites loaded via path gateway are able to access cookies and storage of the entire domain. While we are moving to subdomain gateways (#89), requests made to path gateways will continue to lack origin isolation between content roots. Some will be redirected to subdomain ones, but we should look into other means of improving the situation.
TL;DR
- subdomain gateways will provide Origin isolation
- path gateways do not
- Various headers can be leveraged for limiting what can be used on the origin of path gateway.
Headers to investigate
Clear-Site-Data header
The
Clear-Site-Data headerclears browsing data (cookies, storage, cache) associated with the requesting website. It allows web developers to have more control over the data stored locally by a browser for their origins.
– https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Clear-Site-Data
We could leverage Clear-Site-Data header and send a hint to user agent to clear any preexisting cookies and storage. This is a "nuclear option", but could incentivize users to switch to subdomain gateways when access Web APIs relying on Origin is required.
Note: this requires native subdomain support (ipfs/kubo#6498) to land first.
To purge cookies and storage without reloading any contexts, below header would be returned with every response from /ipfs/{cid} and /ipns/{foo} paths:
Clear-Site-Data: "cookies", "storage"
Content-Security-Policy
Disabling JS and various security features.
Ref. https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy
Highlights:
sandboxdirective may be the most elegant way, it would apply the same logic as<iframe>sandbox for entire page.
Prior art:
- blogpost: https://blog.web3.storage/posts/badbits-and-goodbits-csp-in-w3link
- web3.storage returns:
content-security-policy: default-src 'self' 'unsafe-inline' 'unsafe-eval' blob: data: https://*.w3s.link https://*.nftstorage.link https://*.dweb.link https://ipfs.io/ipfs/ https://*.githubusercontent.com https://tableland.network https://*.tableland.network ; form-action 'self'; navigate-to 'self'; connect-src 'self' blob: data: https://*.w3s.link https://*.nftstorage.link https://*.dweb.link https://ipfs.io/ipfs/ https://*.githubusercontent.com https://tableland.network https://*.tableland.network ; report-to csp-endpoint ; report-uri https://csp-report-to.web3.storagereporting-endpoints: csp-endpoint="https://csp-report-to.web3.storage"
Feature-Policy
Another way of disabling various APIs and behaviors
Ref. https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Feature-Policy
- Relaxing the same-origin restriction requires mutual opt-in from two websites. Still, it would not hurt if we explicitly disabled this via [Feature-Policy/document-domain](Ref. https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Feature-Policy/document-domain) (
dweb.linkis on https://publicsuffix.org/, but other gateways may not be)
TODO
- create PoC proxy to validate the idea
- setting
Gateway.HTTPHeadersin go-ipfs config may be enough for initial tests
- setting
- document behavior in Firefox (
- document behavior in Chromium
- document behavior in Safari