Skip to content

Commit 3c554cf

Browse files
committed
feat: update CSP directives for Google services and refine fallback route matching to exclude static files
1 parent dfa1a44 commit 3c554cf

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

src/infrastructure/express/server.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,16 @@ app.use(
9696
"'self'",
9797
'data:',
9898
'https://www.google-analytics.com',
99-
'https://analytics.google.com'
99+
'https://analytics.google.com',
100+
'https://www.googletagmanager.com'
100101
],
101102
fontSrc: ["'self'", 'https://fonts.gstatic.com'],
102-
connectSrc: ["'self'", 'https://www.google-analytics.com', 'https://analytics.google.com'],
103+
connectSrc: [
104+
"'self'",
105+
'https://www.google-analytics.com',
106+
'https://analytics.google.com',
107+
'https://stats.g.doubleclick.net'
108+
],
103109
objectSrc: ["'none'"],
104110
frameSrc: ["'none'"],
105111
baseUri: ["'self'"],
@@ -228,7 +234,8 @@ const fallbackFileLimiter = rateLimit({
228234
legacyHeaders: false
229235
});
230236

231-
app.get('*all', fallbackFileLimiter, (_req, res) => {
237+
// Serve index.html as fallback only for page routes, returning a standard 404 for missing static files
238+
app.get(/^\/(?!api|_astro|.*\.(?:css|js|png|jpg|jpeg|gif|svg|ico|txt|xml)$).*$/, fallbackFileLimiter, (_req, res) => {
232239
res.sendFile(path.join(__dirname, '../../../public/index.html'));
233240
});
234241

0 commit comments

Comments
 (0)