-
Notifications
You must be signed in to change notification settings - Fork 3
feat(security): adds cors #362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
7b44fd5
e408b0c
379a1ec
7e91e6a
5096ebc
caf33d7
302b288
0a6d83e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,6 @@ | ||||||||
| import Fastify from 'fastify'; | ||||||||
| import FastifyVite from '@fastify/vite'; | ||||||||
| import cors from '@fastify/cors'; | ||||||||
| import helmet from '@fastify/helmet'; | ||||||||
| import { fileURLToPath } from 'node:url'; | ||||||||
| import path from 'node:path'; | ||||||||
|
|
@@ -12,8 +13,6 @@ import { injectDynatraceTag } from './server/config/dynatrace.js'; | |||||||
|
|
||||||||
| dotenv.config(); | ||||||||
|
|
||||||||
| console.log(process.env); | ||||||||
|
|
||||||||
| const { DYNATRACE_SCRIPT_URL } = process.env; | ||||||||
| if (DYNATRACE_SCRIPT_URL) { | ||||||||
| injectDynatraceTag(DYNATRACE_SCRIPT_URL); | ||||||||
|
|
@@ -67,6 +66,28 @@ const fastify = Fastify({ | |||||||
| logger: true, | ||||||||
| }); | ||||||||
|
|
||||||||
| fastify.register(cors, { | ||||||||
| origin: isLocalDev | ||||||||
| ? true // Allow all origins in local development | ||||||||
| : (origin, callback) => { | ||||||||
| // In production, validate against allowed origins | ||||||||
| // @ts-ignore | ||||||||
| const allowedOrigins = fastify.config.ALLOWED_CORS_ORIGINS | ||||||||
| ? // @ts-ignore | ||||||||
| fastify.config.ALLOWED_CORS_ORIGINS.split(',').map((o) => o.trim()) | ||||||||
| : // @ts-ignore | ||||||||
| [fastify.config.POST_LOGIN_REDIRECT]; // Fallback to POST_LOGIN_REDIRECT | ||||||||
|
Comment on lines
+74
to
+79
|
||||||||
|
|
||||||||
| if (!origin || allowedOrigins.includes(origin)) { | ||||||||
| callback(null, true); | ||||||||
| } else { | ||||||||
| callback(new Error(`Origin ${origin} not allowed by CORS policy`), false); | ||||||||
|
||||||||
| callback(new Error(`Origin ${origin} not allowed by CORS policy`), false); | |
| callback(null, false); |
Copilot
AI
Nov 10, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The imgSrc directive includes 'https:' which allows loading images from any HTTPS source. This is overly permissive and could be a security concern. Consider specifying explicit trusted domains instead of allowing all HTTPS sources, or document why this broad permission is necessary.
| imgSrc: ["'self'", 'data:', 'https:'], | |
| // Restrict imgSrc to trusted domains only. Add more domains as needed. | |
| imgSrc: ["'self'", 'data:'], |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,7 +35,7 @@ export default defineConfig({ | |
| }, | ||
|
|
||
| build: { | ||
| sourcemap: true, | ||
| sourcemap: process.env.NODE_ENV !== 'production', | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is also changed here: #359 |
||
| target: 'esnext', // Support top-level await | ||
| }, | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fallback logic doesn't properly handle the case where
ALLOWED_CORS_ORIGINSis set to an empty string or contains only whitespace. An empty string will be split into[''], which means a request with an empty string as the origin will be considered valid.Consider adding a check for empty/whitespace-only strings: