You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
749 B
25 lines
749 B
import helmet from 'helmet';
|
|
import type { Request, Response } from 'express';
|
|
|
|
export const policies = (allowIframe: boolean) => (
|
|
req: Request,
|
|
res: Response,
|
|
next: (err?: unknown) => void,
|
|
) => {
|
|
helmet({
|
|
frameguard: allowIframe ? false : { action: 'sameorigin' },
|
|
referrerPolicy: { policy: ['no-referrer-when-downgrade'] },
|
|
contentSecurityPolicy: {
|
|
directives: {
|
|
defaultSrc: ["'self'"],
|
|
scriptSrc: ["'self'", "'unsafe-inline'", "'unsafe-eval'"],
|
|
styleSrc: ["'self'", "'unsafe-inline'"],
|
|
fontSrc: ["'self'", 'data:'],
|
|
connectSrc: [
|
|
"'self'",
|
|
(req.protocol === 'http' ? 'ws://' : 'wss://') + req.get('host'),
|
|
],
|
|
},
|
|
},
|
|
})(req, res, next);
|
|
};
|
|
|