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
6 changes: 1 addition & 5 deletions main/routes/bills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5529,11 +5529,7 @@ router.patch(
});
}

const clientIp =
req.ip ||
(req.headers['x-forwarded-for'] as string) ||
req.socket.remoteAddress ||
'unknown';
const clientIp = req.ip || req.socket.remoteAddress || 'unknown';
const canonicalIp = normalizeIpForRateLimit(clientIp);
const rateLimitKey = `pin:${canonicalIp}:payment-method-correction`;
if (isPinRateLimited(rateLimitKey)) {
Expand Down
12 changes: 12 additions & 0 deletions tests/secure-network-lan-integrity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,20 @@ function httpsJson(
});
}

/** Client-supplied forwarding headers can be forged, so no backend code may read them. */
function assertNoForwardedHeaderReads(): void {
const root = path.join(__dirname, '..', 'main');
const offenders = (fs.readdirSync(root, { recursive: true }) as string[]).filter(
(file) =>
file.endsWith('.ts') &&
/x-forwarded-for|x-real-ip/i.test(fs.readFileSync(path.join(root, file), 'utf8')),
);
assert.deepEqual(offenders, [], 'client addresses come from the socket, never from headers');
}

async function main() {
console.log('Secure Network client-address integrity suite');
assertNoForwardedHeaderReads();
const lan = lanAddress();
if (!lan) {
console.log(' not run: this machine has no private LAN interface to act as a second device');
Expand Down
Loading