({
isDevelopment = false,
connectSrcUrls,
}: ContentSecurityPolicyOptions = {})
| 67 | export function getContentSecurityPolicyHeaderName(mode: ContentSecurityPolicyMode): string | null { |
| 68 | if (mode === 'off') return null; |
| 69 | if (mode === 'report-only') return 'Content-Security-Policy-Report-Only'; |
| 70 | return 'Content-Security-Policy'; |
| 71 | } |
| 72 | |
| 73 | export function buildContentSecurityPolicy({ |
| 74 | isDevelopment = false, |
| 75 | connectSrcUrls, |
| 76 | }: ContentSecurityPolicyOptions = {}): string { |
| 77 | const configuredConnectSrcUrls = connectSrcUrls ?? getConfiguredConnectSrcOrigins(); |
| 78 | const scriptSrc = compactUnique([ |
| 79 | "'self'", |
| 80 | "'unsafe-inline'", |
| 81 | "'wasm-unsafe-eval'", |
| 82 | isDevelopment ? "'unsafe-eval'" : null, |
| 83 | 'https://www.googletagmanager.com', |
| 84 | 'https://utt.impactcdn.com', |
| 85 | 'https://login.kilo.ai', |
| 86 | 'https://login-test.kilo.ai', |
| 87 | 'https://js.stripe.com', |
| 88 | 'https://*.js.stripe.com', |
| 89 | 'https://checkout.stripe.com', |
| 90 | 'https://challenges.cloudflare.com', |
| 91 | 'https://widget.usepylon.com', |
| 92 | 'https://assets.churnkey.co', |
| 93 | ]); |
| 94 | |
| 95 | const connectSrc = compactUnique([ |
| 96 | "'self'", |
| 97 | 'https://auth.kilo.ai', |
| 98 | 'https://us.i.posthog.com', |
| 99 | 'https://us-assets.i.posthog.com', |
| 100 | 'https://api.stripe.com', |
| 101 | 'https://r.stripe.com', |
| 102 | 'https://m.stripe.com', |
| 103 | 'https://checkout.stripe.com', |
| 104 | 'https://utt.impactcdn.com', |
| 105 | 'https://cdn.jsdelivr.net', |
| 106 | 'https://unpkg.com', |
| 107 | 'https://widget.usepylon.com', |
| 108 | 'https://assets.churnkey.co', |
| 109 | 'https://api.churnkey.co', |
| 110 | 'https://*.churnkey.co', |
| 111 | KILO_CHAT_R2_ATTACHMENT_ORIGIN, |
| 112 | isDevelopment ? 'http://localhost:*' : null, |
| 113 | isDevelopment ? 'ws://localhost:*' : null, |
| 114 | ...configuredConnectSrcUrls.map(originFromUrl), |
| 115 | ]); |
| 116 | |
| 117 | const directives: Record<string, string[]> = { |
| 118 | 'default-src': ["'self'"], |
| 119 | 'base-uri': ["'self'"], |
| 120 | 'object-src': ["'none'"], |
| 121 | 'frame-ancestors': ["'self'"], |
| 122 | 'form-action': ["'self'"], |
| 123 | 'script-src': scriptSrc, |
| 124 | 'connect-src': connectSrc, |
| 125 | 'img-src': [ |
| 126 | "'self'", |
no test coverage detected