@@ -96,6 +96,23 @@ module.exports = {
9696
9797 app . disable ( 'x-powered-by' ) ;
9898
99+ // Pen Test Finding #1: Add HSTS header (OTG-CONFIG-007)
100+ app . use ( ( req , res , next ) => {
101+ res . setHeader ( 'Strict-Transport-Security' , 'max-age=31536000; includeSubDomains; preload' ) ;
102+ next ( ) ;
103+ } ) ;
104+
105+ // Pen Test Finding #4: Remove information disclosure headers (OTG-INFO-009)
106+ app . use ( ( req , res , next ) => {
107+ res . removeHeader ( 'X-Powered-By' ) ;
108+ res . removeHeader ( 'Server' ) ;
109+ res . setHeader ( 'X-Content-Type-Options' , 'nosniff' ) ;
110+ res . setHeader ( 'X-Frame-Options' , 'DENY' ) ;
111+ res . setHeader ( 'Referrer-Policy' , 'strict-origin-when-cross-origin' ) ;
112+ res . setHeader ( 'Permissions-Policy' , 'camera=(), microphone=(), geolocation=()' ) ;
113+ next ( ) ;
114+ } ) ;
115+
99116 if ( db === undefined ) {
100117 db = require ( './models/index' )
101118 }
@@ -123,9 +140,17 @@ module.exports = {
123140
124141 app . use ( bodyParser . json ( { limit : '50mb' } ) )
125142
126- // setup CORS
143+ // setup CORS (Pen Test Finding #3: Tighten CORS origin handling - OTG-CLIENT-007)
127144 function corsTest ( origin , callback ) {
128- if ( origin === undefined || common . CORSWhitelist . indexOf ( origin ) !== - 1 ) {
145+ if ( origin === undefined ) {
146+ // Requests with no Origin header (server-to-server, same-origin)
147+ // In production, do not reflect CORS headers for missing origins
148+ if ( env === 'production' ) {
149+ callback ( null , false )
150+ } else {
151+ callback ( null , true )
152+ }
153+ } else if ( common . CORSWhitelist . indexOf ( origin ) !== - 1 ) {
129154 callback ( null , true )
130155 } else {
131156 logger . log ( 'warn' , 'Request from origin ' + origin + ' not allowed by CORS.' , { tag : 'CORS' } )
0 commit comments