Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions backend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ DATABASE_URL="postgresql://user:password@localhost:5432/flowfi?schema=public"
# Server
PORT=3001
NODE_ENV=development
CORS_ALLOWED_ORIGINS="https://app.flowfi.xyz,https://flowfi.xyz"

# Stellar Network (Testnet/Mainnet)
STELLAR_NETWORK=testnet
Expand Down
44 changes: 43 additions & 1 deletion backend/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,53 @@ import { globalRateLimiter } from './middleware/rate-limiter.middleware.js';
import v1Routes from './routes/v1/index.js';

const app = express();
const isProduction = process.env.NODE_ENV === 'production';
const allowedOrigins = (process.env.CORS_ALLOWED_ORIGINS ?? '')
.split(',')
.map((origin) => origin.trim())
.filter(Boolean);

// Apply global rate limiter first
app.use(globalRateLimiter);

app.use(cors());
app.disable('x-powered-by');

// Helmet-equivalent core headers without external dependency.
app.use((req: Request, res: Response, next: NextFunction) => {
res.setHeader('X-Content-Type-Options', 'nosniff');
res.setHeader('X-Frame-Options', 'DENY');
res.setHeader('Referrer-Policy', 'no-referrer');
res.setHeader('X-DNS-Prefetch-Control', 'off');
res.setHeader('X-Download-Options', 'noopen');
res.setHeader('X-Permitted-Cross-Domain-Policies', 'none');
if (isProduction) {
res.setHeader('Strict-Transport-Security', 'max-age=31536000; includeSubDomains');
}
next();
});

app.use(cors({
origin(origin, callback) {
if (!isProduction) {
callback(null, true);
return;
}

// Allow non-browser clients (no Origin header)
if (!origin) {
callback(null, true);
return;
}

if (allowedOrigins.includes(origin)) {
callback(null, true);
return;
}

callback(new Error('CORS origin not allowed'));
},
credentials: true,
}));
app.use(express.json());

// Sandbox mode detection (before versioning)
Expand Down
Loading