mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -05:00
With BROWSER_POLICY_ENABLED (the Docker and Snap default) WeKan is meant to be frameable only by itself and TRUSTED_URL, so another site cannot load it in an invisible frame and trick a signed-in user into clicking through it (clickjacking). When browser-policy was removed on 2022-04-08, every line of server/policy.js was commented out, and since then the app's pages carried no framing header at all; only file responses did. Every response now gets Content-Security-Policy: frame-ancestors 'self' plus the TRUSTED_URL origins, and X-Frame-Options: SAMEORIGIN when no trusted origin is set; a malformed TRUSTED_URL never widens it, and Sandstorm, which always frames WeKan, and a disabled policy send nothing. build.sh and build.bat run the test server with the default policy. FrameBleed moves from the recorded gaps to guarded, with unit, negative and browser tests. A framed load cannot be told from a normal one, so there is nothing to record in Problems. Thanks to xet7 !
59 lines
2.2 KiB
JavaScript
59 lines
2.2 KiB
JavaScript
//import { BrowserPolicy } from 'meteor/browser-policy-common';
|
|
import { WebApp } from 'meteor/webapp';
|
|
const { framingHeaders } = 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);
|
|
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);
|
|
}
|
|
});
|