Skip to content

Commit 820301f

Browse files
committed
Add dynamic Sentry host configuration to helmet's connect-src directive
1 parent 83e6780 commit 820301f

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

server.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,15 @@ const fastify = Fastify({
4242
Sentry.setupFastifyErrorHandler(fastify);
4343
await fastify.register(envPlugin);
4444

45+
let sentryHost = null;
46+
if (fastify.config.BFF_SENTRY_DSN && fastify.config.BFF_SENTRY_DSN.length > 0) {
47+
sentryHost = new URL(fastify.config.BFF_SENTRY_DSN).hostname;
48+
}
49+
4550
fastify.register(helmet, {
4651
contentSecurityPolicy: {
4752
directives: {
48-
'connect-src': ["'self'", 'sdk.openui5.org', 'o1240783.ingest.us.sentry.io'],
53+
'connect-src': ["'self'", 'sdk.openui5.org', sentryHost],
4954
'script-src': isLocalDev ? ["'self'", "'unsafe-inline'"] : ["'self'"],
5055
'frame-ancestors': [fastify.config.FRAME_ANCESTORS],
5156
},

server/config/env.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ const schema = {
2929
FEEDBACK_SLACK_URL: { type: 'string' },
3030
FEEDBACK_URL_LINK: { type: 'string' },
3131
FRAME_ANCESTORS: { type: 'string' },
32+
BFF_SENTRY_DSN: { type: 'string' },
33+
VITE_SENTRY_DSN: { type: 'string' },
34+
VITE_ENVIRONMENT: { type: 'string' },
3235

3336
// System variables
3437
NODE_ENV: { type: 'string', enum: ['development', 'production'] },

0 commit comments

Comments
 (0)