mirror of
https://github.com/aljazceru/ditto.git
synced 2026-01-09 08:34:20 +01:00
31 lines
849 B
TypeScript
31 lines
849 B
TypeScript
import { AppMiddleware } from '@/app.ts';
|
|
import { Conf } from '@/config.ts';
|
|
|
|
const csp = (): AppMiddleware => {
|
|
return async (c, next) => {
|
|
const { host, protocol } = Conf.url;
|
|
const wsProtocol = protocol === 'http:' ? 'ws:' : 'wss:';
|
|
|
|
const policies = [
|
|
'upgrade-insecure-requests',
|
|
`script-src 'self'`,
|
|
`connect-src 'self' blob: ${Conf.localDomain} ${wsProtocol}//${host}`,
|
|
`media-src 'self' ${Conf.mediaDomain}`,
|
|
`img-src 'self' data: blob: ${Conf.mediaDomain}`,
|
|
`default-src 'none'`,
|
|
`base-uri 'self'`,
|
|
`frame-ancestors 'none'`,
|
|
`style-src 'self' 'unsafe-inline'`,
|
|
`font-src 'self'`,
|
|
`manifest-src 'self'`,
|
|
`frame-src 'self' https:`,
|
|
];
|
|
|
|
c.res.headers.set('content-security-policy', policies.join('; '));
|
|
|
|
await next();
|
|
};
|
|
};
|
|
|
|
export { csp };
|