Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions workflow/packages/backend/api/src/app/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,31 @@ async function setupBaseApp(): Promise<FastifyInstance> {

await app.register(formBody, { parser: (str) => qs.parse(str) })
app.setErrorHandler(errorHandler)

// FIX: CORS misconfiguration - Use specific allowed origins instead of wildcard
// This prevents cross-origin data theft from authenticated sessions
// Related to Issue #356
const allowedOrigins = process.env.ALLOWED_ORIGINS?.split(',') || [
'https://app.aixblock.io',
'https://workflow-live.aixblock.io',
];

await app.register(cors, {
origin: '*',
origin: (origin, callback) => {
// Allow requests with no origin (like mobile apps or curl requests)
if (!origin) {
return callback(null, true);
}

if (allowedOrigins.includes(origin)) {
callback(null, true);
} else {
callback(new Error('Not allowed by CORS'), false);
}
},
credentials: true,
exposedHeaders: ['*'],
methods: ['*'],
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
})
// SurveyMonkey
app.addContentTypeParser(
Expand Down