Skip to content

Commit 6310d3b

Browse files
committed
fix: harden CAPTCHA URL, raise rate limit, replace shell-expanded JWT secret
1 parent 52da2e1 commit 6310d3b

3 files changed

Lines changed: 14 additions & 3 deletions

File tree

config/cap.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,26 @@ async function fetchWithTimeout(url, options = {}, timeout = 10000) {
1919
}
2020
}
2121

22+
function normalizeUrl(base) {
23+
return base.endsWith('/') ? base : base + '/';
24+
}
25+
2226
export async function verifyCap(token) {
2327
if (!token) return false;
28+
const url = `${normalizeUrl(CAP_ENDPOINT)}siteverify`;
2429
try {
25-
const res = await fetchWithTimeout(`${CAP_ENDPOINT}siteverify`, {
30+
const res = await fetchWithTimeout(url, {
2631
method: 'POST',
2732
headers: { 'Content-Type': 'application/json' },
2833
body: JSON.stringify({ secret: CAP_SECRET, response: token }),
2934
});
3035
const data = await res.json();
36+
if (data.success !== true) {
37+
console.error('[CAP] Verification failed:', JSON.stringify(data));
38+
}
3139
return data.success === true;
32-
} catch {
40+
} catch (err) {
41+
console.error('[CAP] Service unreachable at', url, ':', err.message);
3342
return false;
3443
}
3544
}

middleware/auth.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ const JWT_SECRET = process.env.JWT_SECRET;
44

55
if (!JWT_SECRET) {
66
console.error('Missing JWT_SECRET environment variable');
7+
} else if (/[\$\(\)]/.test(JWT_SECRET)) {
8+
console.error('JWT_SECRET contains unresolved shell expansion characters ($(), backticks). Generate a proper random key (e.g. openssl rand -hex 32) and hardcode it in .env');
79
}
810

911
export function authenticateToken(req, res, next) {

server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ app.use(cookieParser(process.env.COOKIE_SECRET));
7070

7171
const authLimiter = rateLimit({
7272
windowMs: 15 * 60 * 1000,
73-
max: 10,
73+
max: 20,
7474
message: { error: 'Too many attempts, try again later' },
7575
standardHeaders: true,
7676
legacyHeaders: false,

0 commit comments

Comments
 (0)