|
| 1 | +/** |
| 2 | + * HTTP Headers Configuration for Cloudflare Pages |
| 3 | + * This file is the source of truth for static/_headers generation |
| 4 | + * Run: npm run build:headers |
| 5 | + */ |
| 6 | + |
| 7 | +interface HeadersConfig { |
| 8 | + paths: Array<{ |
| 9 | + pattern: string; |
| 10 | + headers: Record<string, string[] | Record<string, string[]>>; |
| 11 | + }>; |
| 12 | +} |
| 13 | + |
| 14 | +const config: HeadersConfig = { |
| 15 | + paths: [ |
| 16 | + { |
| 17 | + pattern: '/*', |
| 18 | + headers: { |
| 19 | + 'Content-Security-Policy': { |
| 20 | + // Allow AJAX/fetch requests to status page, marketing site, HubSpot, and Google services |
| 21 | + 'connect-src': [ |
| 22 | + '\'self\'', |
| 23 | + 'https://status.maxmind.com', |
| 24 | + 'https://www.maxmind.com', |
| 25 | + // HubSpot API endpoint |
| 26 | + // https://legacydocs.hubspot.com/docs/faq/how-do-i-create-a-custom-domain-for-my-forms |
| 27 | + 'https://api.hubspot.com', |
| 28 | + // HubSpot static assets used by conversations embed |
| 29 | + // eslint-disable-next-line max-len |
| 30 | + // https://developers.hubspot.com/beta-docs/guides/apps/authentication/working-with-oauth#frequently-asked-questions |
| 31 | + 'https://forms.hsforms.com', |
| 32 | + 'https://*.googleapis.com', |
| 33 | + 'https://*.google-analytics.com', |
| 34 | + 'https://*.analytics.google.com', |
| 35 | + 'https://*.googletagmanager.com', |
| 36 | + 'https://*.g.doubleclick.net', |
| 37 | + // Google |
| 38 | + // eslint-disable-next-line max-len |
| 39 | + // https://developers.google.com/tag-platform/tag-manager/csp#google_analytics_4_google_analytics |
| 40 | + 'https://*.google.com', |
| 41 | + ], |
| 42 | + 'default-src': [ |
| 43 | + '\'self\'', |
| 44 | + ], |
| 45 | + // Google Fonts and Vertex search (indirectly loaded when setting up the searchbox) |
| 46 | + 'font-src': [ |
| 47 | + '\'self\'', |
| 48 | + 'https://fonts.gstatic.com', |
| 49 | + ], |
| 50 | + 'form-action': [ |
| 51 | + '\'self\'', |
| 52 | + ], |
| 53 | + 'frame-ancestors': [ |
| 54 | + '\'self\'', |
| 55 | + ], |
| 56 | + // HubSpot calls-to-action (pop-ups) and chatflows |
| 57 | + // eslint-disable-next-line max-len |
| 58 | + // https://knowledge.hubspot.com/website-pages/use-hubspot-content-on-external-sites#calls-to-action |
| 59 | + // Google Vertex search |
| 60 | + 'frame-src': [ |
| 61 | + '\'self\'', |
| 62 | + 'https://app.hubspot.com', |
| 63 | + 'https://www.google.com', |
| 64 | + 'https://www.googletagmanager.com', |
| 65 | + ], |
| 66 | + 'img-src': [ |
| 67 | + '\'self\'', |
| 68 | + 'data:', |
| 69 | + 'https:', |
| 70 | + ], |
| 71 | + 'object-src': [ |
| 72 | + '\'none\'', |
| 73 | + ], |
| 74 | + 'script-src': [ |
| 75 | + '\'self\'', |
| 76 | + '\'report-sample\'', |
| 77 | + '\'unsafe-inline\'', |
| 78 | + // HubSpot tracking code |
| 79 | + // eslint-disable-next-line max-len |
| 80 | + // https://developers.hubspot.com/beta-docs/guides/api/tracking-code-api/tracking-code-quickstart-guide#frequently-asked-questions |
| 81 | + 'https://js.hs-scripts.com', |
| 82 | + // HubSpot analytics |
| 83 | + // https://knowledge.hubspot.com/reports/install-the-hubspot-tracking-code |
| 84 | + 'https://js.hs-analytics.net', |
| 85 | + // HubSpot cookie banner |
| 86 | + // https://knowledge.hubspot.com/privacy-and-consent/add-a-cookie-banner-to-your-website |
| 87 | + 'https://js.hs-banner.com', |
| 88 | + // HubSpot conversations (live chat widget, chat flow) |
| 89 | + // https://knowledge.hubspot.com/chatflows/install-the-hubspot-tracking-code-for-chat |
| 90 | + 'https://js.usemessages.com', |
| 91 | + // HubSpot form widgets |
| 92 | + // https://legacydocs.hubspot.com/docs/methods/forms/advanced_form_options |
| 93 | + 'https://js.hsforms.net', |
| 94 | + 'https://www.maxmind.com', |
| 95 | + // Google |
| 96 | + // eslint-disable-next-line max-len |
| 97 | + // https://developers.google.com/tag-platform/tag-manager/csp#google_analytics_4_google_analytics |
| 98 | + 'https://cloud.google.com', |
| 99 | + 'https://www.gstatic.com', |
| 100 | + 'https://www.googleadservices.com', |
| 101 | + 'https://www.google.com', |
| 102 | + 'https://*.googletagmanager.com', |
| 103 | + ], |
| 104 | + // Google Fonts API and Vertex search |
| 105 | + // Google static assets |
| 106 | + 'style-src': [ |
| 107 | + '\'self\'', |
| 108 | + '\'unsafe-inline\'', |
| 109 | + 'https://fonts.googleapis.com', |
| 110 | + 'https://www.gstatic.com', |
| 111 | + ], |
| 112 | + }, |
| 113 | + 'Feature-Policy': [ |
| 114 | + 'accelerometer \'none\'', |
| 115 | + 'autoplay \'none\'', |
| 116 | + 'camera \'none\'', |
| 117 | + 'encrypted-media \'none\'', |
| 118 | + 'fullscreen \'none\'', |
| 119 | + 'geolocation \'none\'', |
| 120 | + 'gyroscope \'none\'', |
| 121 | + 'magnetometer \'none\'', |
| 122 | + 'microphone \'none\'', |
| 123 | + 'midi \'none\'', |
| 124 | + 'payment \'none\'', |
| 125 | + 'picture-in-picture \'none\'', |
| 126 | + 'usb \'none\'', |
| 127 | + 'sync-xhr \'none\'', |
| 128 | + ], |
| 129 | + 'Permissions-Policy': [ |
| 130 | + 'accelerometer=()', |
| 131 | + 'ambient-light-sensor=()', |
| 132 | + 'autoplay=()', |
| 133 | + 'battery=()', |
| 134 | + 'camera=()', |
| 135 | + 'display-capture=()', |
| 136 | + 'document-domain=()', |
| 137 | + 'encrypted-media=()', |
| 138 | + 'execution-while-not-rendered=()', |
| 139 | + 'execution-while-out-of-viewport=()', |
| 140 | + 'fullscreen=()', |
| 141 | + 'gamepad=()', |
| 142 | + 'geolocation=()', |
| 143 | + 'gyroscope=()', |
| 144 | + 'hid=()', |
| 145 | + 'idle-detection=()', |
| 146 | + 'magnetometer=()', |
| 147 | + 'microphone=()', |
| 148 | + 'midi=()', |
| 149 | + 'payment=()', |
| 150 | + 'picture-in-picture=()', |
| 151 | + 'publickey-credentials-get=()', |
| 152 | + 'screen-wake-lock=()', |
| 153 | + 'serial=()', |
| 154 | + 'speaker-selection=()', |
| 155 | + 'usb=()', |
| 156 | + 'web-share=()', |
| 157 | + 'xr-spatial-tracking=()', |
| 158 | + ], |
| 159 | + 'Referrer-Policy': [ |
| 160 | +'strict-origin-when-cross-origin', |
| 161 | +], |
| 162 | + 'Strict-Transport-Security': [ |
| 163 | + 'max-age=63072000', |
| 164 | + 'includeSubDomains', |
| 165 | + 'preload', |
| 166 | + ], |
| 167 | + 'X-Content-Type-Options': [ |
| 168 | +'nosniff', |
| 169 | +], |
| 170 | + 'X-Frame-Options': [ |
| 171 | +'DENY', |
| 172 | +], |
| 173 | + 'X-XSS-Protection': [ |
| 174 | +'1', |
| 175 | +'mode=block', |
| 176 | +], |
| 177 | + }, |
| 178 | + }, |
| 179 | + ], |
| 180 | +}; |
| 181 | + |
| 182 | +export default config; |
0 commit comments