mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
Files are served private, no-cache, so every later view of an attachment, avatar or thumbnail revalidates and gets a 304, and a browser updates the stored response's headers with the 304's. The app-wide frame-ancestors 'self' that FrameBleed's restore puts on every response therefore replaced the file's own policy - an SVG's default-src 'none' and sandbox - from the second view on. The SVG body is still sanitized on every serve, so this lost a layer of defence rather than opening script execution. The app-wide framing headers are now left off a 304, so the stored 200 keeps the policy its route chose; a header a route set on the 304 itself is kept. Not recorded in Admin Panel / Problems: it fires on ordinary revalidation, not on an attempt. Thanks to xet7 !
69 lines
2.8 KiB
JavaScript
69 lines
2.8 KiB
JavaScript
//import { BrowserPolicy } from 'meteor/browser-policy-common';
|
|
import { WebApp } from 'meteor/webapp';
|
|
const { framingHeaders, framingHeadersToDropOnNotModified } = require('/models/lib/framePolicy');
|
|
|
|
// FrameBleed (restored 2026-10-02): the framing restriction below was all
|
|
// commented out when browser-policy was removed in 2022, so WeKan's pages
|
|
// could be framed by any site. It is set here, as a raw header, for every
|
|
// response; a route that sets its own Content-Security-Policy (file
|
|
// responses) replaces it with a stricter one.
|
|
const FRAMING_HEADERS = framingHeaders({
|
|
enabled: process.env.BROWSER_POLICY_ENABLED === 'true',
|
|
trustedUrl: process.env.TRUSTED_URL,
|
|
sandstorm: !!(Meteor.settings && Meteor.settings.public && Meteor.settings.public.sandstorm),
|
|
});
|
|
if (Object.keys(FRAMING_HEADERS).length) {
|
|
WebApp.rawHandlers.use((req, res, next) => {
|
|
for (const [name, value] of Object.entries(FRAMING_HEADERS)) res.setHeader(name, value);
|
|
// ...except on a 304 Not Modified: the browser would put this CSP in
|
|
// place of the stored file's own (models/lib/framePolicy.js). Node sends
|
|
// every response's head through writeHead, an implicit one included.
|
|
const writeHead = res.writeHead;
|
|
res.writeHead = function writeHeadKeepingStoredPolicy(statusCode, ...rest) {
|
|
if (Number(statusCode) === 304) {
|
|
for (const name of framingHeadersToDropOnNotModified(FRAMING_HEADERS, n => res.getHeader(n))) res.removeHeader(name);
|
|
}
|
|
return writeHead.call(this, statusCode, ...rest);
|
|
};
|
|
next();
|
|
});
|
|
}
|
|
|
|
Meteor.startup(() => {
|
|
/*
|
|
// Default allowed
|
|
BrowserPolicy.content.allowInlineScripts();
|
|
BrowserPolicy.content.allowEval();
|
|
BrowserPolicy.content.allowInlineStyles();
|
|
BrowserPolicy.content.allowOriginForAll('*');
|
|
// Allow all images from anywhere
|
|
BrowserPolicy.content.allowImageOrigin('*');
|
|
BrowserPolicy.content.allowDataUrlForAll();
|
|
*/
|
|
|
|
if (process.env.BROWSER_POLICY_ENABLED === 'true') {
|
|
// Trusted URL that can embed Wekan in iFrame.
|
|
const trusted = process.env.TRUSTED_URL;
|
|
////BrowserPolicy.framing.disallow();
|
|
//Allow inline scripts, otherwise there is errors in browser/inspect/console
|
|
//BrowserPolicy.content.disallowInlineScripts();
|
|
//BrowserPolicy.content.disallowEval();
|
|
//BrowserPolicy.content.allowInlineStyles();
|
|
//BrowserPolicy.content.allowFontDataUrl();
|
|
////BrowserPolicy.framing.restrictToOrigin(trusted);
|
|
//BrowserPolicy.content.allowScriptOrigin(trusted);
|
|
} else {
|
|
// Disable browser policy and allow all framing and including.
|
|
// Use only at internal LAN, not at Internet.
|
|
////BrowserPolicy.framing.allowAll();
|
|
}
|
|
|
|
|
|
// If Matomo URL is set, allow it.
|
|
const matomoUrl = process.env.MATOMO_ADDRESS;
|
|
if (matomoUrl) {
|
|
//BrowserPolicy.content.allowScriptOrigin(matomoUrl);
|
|
//BrowserPolicy.content.allowImageOrigin(matomoUrl);
|
|
}
|
|
});
|