-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sandbox resources loaded via a path gateway #157
Comments
Blocking cookies is a nuclear option that may break some deployments behind reverse proxies that pass all headers. We would need |
This removes note about Clear-Site-Data. Tracked in ipfs/in-web-browsers#157 License: MIT Signed-off-by: Marcin Rataj <[email protected]>
This removes note about Clear-Site-Data. Tracked in ipfs/in-web-browsers#157 License: MIT Signed-off-by: Marcin Rataj <[email protected]>
Something to be aware of: |
This removes note about Clear-Site-Data. Tracked in ipfs/in-web-browsers#157 License: MIT Signed-off-by: Marcin Rataj <[email protected]>
Interesting fact: w3c spec suggests a discrepancy between clearing cookies and storage: According to the spec I tested behavior in Chromium 76 and Firefox 74 to see if it negatively impacts subdomain gateways in go-ipfs (ipfs/kubo#6096). This does not seem to be the case: subdomain cookies are not purged if |
Sidenote: we could reuse this on locked-down subdomain namespace ipfs/kubo#7318 (think
This could be greatly deduplicated and simplified, ideally, we would introduce everything (hardening path gateways; hardening/removing CORS from subdomains; support for long CIDs; support for CORS without compromising any local storage) in a single PR/release. |
I would like to suggest taking the restrictions on I think that in a pathed context, we can restrict this further and make those powerful capabilities unavailable. The header would look like this:
So, errr, yeah, your eyes might be bleeding right now and I'm sorry about that. Also, that list grows all the time. It's not great. There are issues about making a blanket "remove anything that might be dangerous" mode but so far they haven't been accepted. We could decide to keep some things allowed (like camera or sync XHR) if we're worried about breaking legit use cases. But at least this list (which is the most comprehensive I could find — I'm looking into whether there's a reliable way to get an up-to-date list) makes things pretty tight and safe, on top of CSP and clearing the data. |
Pretty hardcore, but for sure will do the trick of forcing people to move to subdomain gateways. I propose we do a test run: set If the sky does not fall, me and @hacdias can apply this to all path requests in go-libipfs/gateway library. |
In addition to
Some quick notes:
I did some very superficial testing on static content, and it works. If you want to play with it locally, run this with a path to a dir to serve from: #!/usr/bin/env node
import process from 'process';
import express from 'express';
const app = express();
app.use((req, res, next) => {
res.set({
'Permissions-Policy': 'accelerometer=(),ambient-light-sensor=(),attribution-reporting=(),autoplay=(),battery=(),bluetooth=(),browsing-topics=(),camera=(),ch-device-memory=(),ch-downlink=(),ch-dpr=(),ch-ect=(),ch-lang=(),ch-prefers-color-scheme=(),ch-rtt=(),ch-save-data=(),ch-ua=(),ch-ua-arch=(),ch-ua-bitness=(),ch-ua-full=(),ch-ua-full-version=(),ch-ua-full-version-list=(),ch-ua-mobile=(),ch-ua-model=(),ch-ua-platform=(),ch-ua-platform-version=(),ch-ua-reduced=(),ch-ua-wow64=(),ch-viewport-height=(),ch-viewport-width=(),ch-width=(),clipboard-read=(),clipboard-write=(),conversion-measurement=(),cross-origin-isolated=(),direct-sockets=(),display-capture=(),document-domain=(),encrypted-media=(),execution-while-not-rendered=(),execution-while-out-of-viewport=(),federated-credentials=(),focus-without-user-activation=(),fullscreen=(),gamepad=(),geolocation=(),gyroscope=(),hid=(),idle-detection=(),interest-cohort=(),join-ad-interest-group=(),keyboard-map=(),local-fonts=(),magnetometer=(),microphone=(),midi=(),navigation-override=(),otp-credentials=(),payment=(),picture-in-picture=(),publickey-credentials-get=(),run-ad-auction=(),screen-wake-lock=(),serial=(),shared-autofill=(),shared-storage=(),speaker-selection=(),storage-access-api=(),sync-script=(),sync-xhr=(),trust-token-redemption=(),unload=(),usb=(),vertical-scroll=(),wake-lock=(),web-share=(),window-placement=(),xr-spatial-tracking=()',
'Content-Security-Policy': `default-src 'self' 'unsafe-inline' 'unsafe-eval' data: ; form-action 'self'; connect-src 'self' data: ; manifest-src 'none' ; object-src 'none' ; sandbox allow-forms allow-modals allow-scripts allow-top-navigation-by-user-activation`,
'X-Content-Type-Options': 'nosniff',
'X-Frame-Options': 'sameorigin',
});
next();
});
app.use(express.static(process.argv[2]));
app.listen(8888, () => console.warn(`Listening on http://localhost:8888`)); |
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
Headers to investigate
Clear-Site-Data header
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:Content-Security-Policy
Disabling JS and various security features.
Ref. https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy
Highlights:
sandbox
directive may be the most elegant way, it would apply the same logic as<iframe>
sandbox for entire page.Prior art:
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.storage
reporting-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
dweb.link
is on https://publicsuffix.org/, but other gateways may not be)TODO
Gateway.HTTPHeaders
in go-ipfs config may be enough for initial testsThe text was updated successfully, but these errors were encountered: