Skip to content

Commit 3228ddb

Browse files
fix: remediate pen test findings #1, #3, #4
Finding #1 (Moderate): Add HSTS Strict-Transport-Security header - max-age=31536000 (1 year), includeSubDomains, preload Finding #3 (Low): Tighten CORS configuration - Reject CORS for requests with no Origin header in production - Remove unused dev/staging origins from shared CORSWhitelist Finding #4 (Low): Remove information disclosure headers - Strip Server and X-Powered-By headers - Add X-Content-Type-Options, X-Frame-Options, Referrer-Policy, Permissions-Policy security headers Ref: SRT Penetration Test Report v1 (March 2026) by Valiant Solutions
1 parent a4db888 commit 3228ddb

2 files changed

Lines changed: 154 additions & 131 deletions

File tree

server/app.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)