mirror of
https://github.com/root-fr/jmap-webmail.git
synced 2026-09-23 16:01:15 +00:00
37 lines
1018 B
TypeScript
37 lines
1018 B
TypeScript
export function buildCsp(nonce: string, isDev: boolean): string {
|
|
const scriptSrc = isDev
|
|
? `'self' 'nonce-${nonce}' 'unsafe-eval'`
|
|
: `'self' 'nonce-${nonce}'`;
|
|
|
|
const connectSrc = isDev ? `'self' https: ws: wss:` : `'self' https:`;
|
|
|
|
return [
|
|
`default-src 'self'`,
|
|
`script-src ${scriptSrc}`,
|
|
`style-src 'self' 'unsafe-inline'`,
|
|
`img-src 'self' data: blob: https:`,
|
|
`font-src 'self'`,
|
|
`connect-src ${connectSrc}`,
|
|
`frame-src 'self'`,
|
|
`object-src 'none'`,
|
|
`base-uri 'self'`,
|
|
`form-action 'self'`,
|
|
`frame-ancestors 'none'`,
|
|
].join("; ");
|
|
}
|
|
|
|
export function buildSecurityHeaders(
|
|
nonce: string,
|
|
isDev: boolean
|
|
): Record<string, string> {
|
|
return {
|
|
"X-Content-Type-Options": "nosniff",
|
|
"X-Frame-Options": "DENY",
|
|
"Referrer-Policy": "strict-origin-when-cross-origin",
|
|
"X-XSS-Protection": "0",
|
|
"Permissions-Policy":
|
|
"camera=(), microphone=(), geolocation=(), payment=()",
|
|
"Content-Security-Policy": buildCsp(nonce, isDev),
|
|
};
|
|
}
|