diff --git a/main/routes/bills.ts b/main/routes/bills.ts index ad330f7e4..550f91330 100644 --- a/main/routes/bills.ts +++ b/main/routes/bills.ts @@ -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)) { diff --git a/tests/secure-network-lan-integrity.test.ts b/tests/secure-network-lan-integrity.test.ts index 036af5364..6c4eed469 100644 --- a/tests/secure-network-lan-integrity.test.ts +++ b/tests/secure-network-lan-integrity.test.ts @@ -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');