Sandbox remote file responses at the browser relay boundary
This commit is contained in:
+17
-1
@@ -7,6 +7,11 @@ import {
|
||||
} from "./peerTransport.js";
|
||||
import { PeerRegistry } from "./peerRegistry.js";
|
||||
|
||||
// Peer files are untrusted content, never privileged control-UI documents.
|
||||
// Apply this even for older peers whose /files endpoint has no sandbox header.
|
||||
const contentPolicy =
|
||||
"sandbox; default-src 'none'; script-src 'none'; connect-src 'none'; style-src 'unsafe-inline'; img-src 'self' data:; media-src 'self' data:; base-uri 'none'; form-action 'none'; frame-ancestors 'self'";
|
||||
|
||||
const allowed = (path) =>
|
||||
path === "/files" ||
|
||||
path === "/chat-uploads" ||
|
||||
@@ -75,7 +80,18 @@ export class PeerRelay extends PeerRegistry {
|
||||
response.statusCode >= 300 && response.statusCode < 400
|
||||
? 502
|
||||
: response.statusCode,
|
||||
{ ...safe, "Cache-Control": "no-store" },
|
||||
{
|
||||
...safe,
|
||||
"Cache-Control": "private, no-store",
|
||||
// Multiple CSP policies intersect: preserve a peer's stricter
|
||||
// restrictions while always imposing the local sandbox boundary.
|
||||
"Content-Security-Policy": response.headers[
|
||||
"content-security-policy"
|
||||
]
|
||||
? [response.headers["content-security-policy"], contentPolicy]
|
||||
: contentPolicy,
|
||||
"X-Content-Type-Options": "nosniff",
|
||||
},
|
||||
);
|
||||
response.pipe(res);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user