Skip to content

Commit 960293c

Browse files
Merge branch 'main' into renovate/major-react-monorepo
2 parents 34aecc0 + 5d69921 commit 960293c

File tree

7 files changed

+76
-4
lines changed

7 files changed

+76
-4
lines changed

.env.template

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,7 @@ FEEDBACK_URL_LINK=
3232

3333
# frame-ancestors attribute of CSP. Separate multiple values with a space
3434
FRAME_ANCESTORS=
35+
36+
# Allowed CORS origins (comma-separated). Example: https://app.example.com,https://admin.example.com
37+
# Leave empty to use POST_LOGIN_REDIRECT as the default allowed origin
38+
ALLOWED_CORS_ORIGINS=

.github/renovate.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,14 @@
77
"group:allNonMajor",
88
"npm:unpublishSafe",
99
":disableDependencyDashboard"
10+
],
11+
"prCreation": "not-pending",
12+
"packageRules": [
13+
{
14+
"groupName": "@ui5/webcomponents packages",
15+
"matchPackageNames": [
16+
"@ui5/webcomponents{/,}**"
17+
]
18+
}
1019
]
11-
}
20+
}

package-lock.json

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"@apollo/client": "3.14.0",
2929
"@fastify/autoload": "6.3.1",
3030
"@fastify/cookie": "11.0.2",
31+
"@fastify/cors": "11.1.0",
3132
"@fastify/env": "5.0.3",
3233
"@fastify/helmet": "13.0.2",
3334
"@fastify/http-proxy": "11.3.0",

server.ts

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Fastify from 'fastify';
22
import FastifyVite from '@fastify/vite';
3+
import cors from '@fastify/cors';
34
import helmet from '@fastify/helmet';
45
import { fileURLToPath } from 'node:url';
56
import path from 'node:path';
@@ -12,8 +13,6 @@ import { injectDynatraceTag } from './server/config/dynatrace.js';
1213

1314
dotenv.config();
1415

15-
console.log(process.env);
16-
1716
const { DYNATRACE_SCRIPT_URL } = process.env;
1817
if (DYNATRACE_SCRIPT_URL) {
1918
injectDynatraceTag(DYNATRACE_SCRIPT_URL);
@@ -70,6 +69,33 @@ const fastify = Fastify({
7069
Sentry.setupFastifyErrorHandler(fastify);
7170
await fastify.register(envPlugin);
7271

72+
fastify.register(cors, {
73+
origin: isLocalDev
74+
? true // Allow all origins in local development
75+
: (origin, callback) => {
76+
// In production, validate against allowed origins
77+
const allowedOrigins =
78+
// @ts-ignore
79+
fastify.config.ALLOWED_CORS_ORIGINS && fastify.config.ALLOWED_CORS_ORIGINS.trim()
80+
? // @ts-ignore
81+
fastify.config.ALLOWED_CORS_ORIGINS.split(',')
82+
// @ts-ignore
83+
.map((o) => o.trim())
84+
// @ts-ignore
85+
.filter((o) => o)
86+
: // @ts-ignore
87+
[fastify.config.POST_LOGIN_REDIRECT]; // Fallback to POST_LOGIN_REDIRECT
88+
89+
if (!origin || allowedOrigins.includes(origin)) {
90+
callback(null, true);
91+
} else {
92+
callback(null, false);
93+
}
94+
},
95+
methods: ['GET', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE'],
96+
credentials: true, // Required for cookie-based sessions
97+
});
98+
7399
let sentryHost = '';
74100
// @ts-ignore
75101
if (fastify.config.FRONTEND_SENTRY_DSN && fastify.config.FRONTEND_SENTRY_DSN.length > 0) {
@@ -94,6 +120,10 @@ if (DYNATRACE_SCRIPT_URL) {
94120
fastify.register(helmet, {
95121
contentSecurityPolicy: {
96122
directives: {
123+
defaultSrc: ["'self'"],
124+
// styleSrc: unsafe-inline is needed for our styling
125+
styleSrc: ["'self'", "'unsafe-inline'"],
126+
imgSrc: ["'self'", 'data:'],
97127
'connect-src': ["'self'", 'sdk.openui5.org', sentryHost, dynatraceOrigin],
98128
'script-src': isLocalDev
99129
? ["'self'", "'unsafe-inline'", "'unsafe-eval'", sentryHost, dynatraceOrigin]
@@ -102,6 +132,12 @@ fastify.register(helmet, {
102132
'frame-ancestors': [...fastify.config.FRAME_ANCESTORS.split(',')],
103133
},
104134
},
135+
// Needed for https enforcement
136+
hsts: {
137+
maxAge: 31536000,
138+
includeSubDomains: true,
139+
preload: true,
140+
},
105141
});
106142

107143
fastify.register(proxy, {

server/config/env.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const schema = {
2929
FEEDBACK_SLACK_URL: { type: 'string' },
3030
FEEDBACK_URL_LINK: { type: 'string' },
3131
FRAME_ANCESTORS: { type: 'string' },
32+
ALLOWED_CORS_ORIGINS: { type: 'string' },
3233
BFF_SENTRY_DSN: { type: 'string' },
3334
FRONTEND_SENTRY_DSN: { type: 'string' },
3435
FRONTEND_SENTRY_ENVIRONMENT: { type: 'string' },

vite.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export default defineConfig({
3535
},
3636

3737
build: {
38-
sourcemap: true,
38+
sourcemap: true, // crucial for sentry
3939
target: 'esnext', // Support top-level await
4040
},
4141
});

0 commit comments

Comments
 (0)