Skip to content

Commit 944f580

Browse files
committed
feat(security): add no-op middleware for CSP in development environment
1 parent aad8300 commit 944f580

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

apps/web/app/lib/security.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,29 @@ const allowedOrigins = [env.ALLOWED_ORIGIN_1, env.ALLOWED_ORIGIN_2].filter(
3131
);
3232

3333
// Security middleware configurations
34-
export const apiSecurity = createApiSecurity(allowedOrigins, logger);
34+
// For development, create a no-op middleware to disable CSP
35+
export const apiSecurity =
36+
process.env.NODE_ENV === 'development'
37+
? (req: any, res: any, next: any) => {
38+
// Skip API security in development to avoid CSP issues
39+
next();
40+
}
41+
: createApiSecurity(allowedOrigins, logger);
3542
export const authSecurity = createAuthSecurity(allowedOrigins, logger);
3643
export const formSecurity = createFormSecurity(allowedOrigins, logger);
3744
export const passwordResetSecurity = createPasswordResetSecurity(
3845
allowedOrigins,
3946
logger
4047
);
41-
export const staticSecurity = createStaticSecurity();
48+
// For development, we'll disable CSP entirely to allow inline scripts
49+
// In production, use the default secure CSP
50+
export const staticSecurity =
51+
process.env.NODE_ENV === 'development'
52+
? (req: any, res: any, next: any) => {
53+
// Skip CSP in development
54+
next();
55+
}
56+
: createStaticSecurity();
4257

4358
// API security middleware
4459
export const validateApiKey = createValidateApiKey(logger);

apps/web/server/app.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import express from 'express';
33
import 'react-router';
44

55
// Import security middleware
6-
import { apiSecurity, formatApiResponse } from '../app/lib/security';
6+
import {
7+
apiSecurity,
8+
formatApiResponse,
9+
staticSecurity,
10+
} from '../app/lib/security';
711

812
declare module 'react-router' {
913
interface AppLoadContext {
@@ -14,6 +18,7 @@ declare module 'react-router' {
1418
export const app = express();
1519

1620
// Apply security middleware
21+
app.use(staticSecurity);
1722
app.use(apiSecurity);
1823
app.use(formatApiResponse);
1924

0 commit comments

Comments
 (0)