Security rules

NGB082: Spoofable client IP used for access control

Reports server code that makes an access-control decision from a client IP taken from forwarding headers (X-Forwarded-For, X-Real-IP, True-Client-IP, CF-Connecting-IP, X-Client-IP, Forwarded) or from Express req.ip / req.ips while app.set('trust proxy', true) trusts every hop: comparisons with IP literals, allowlist / blocklist lookups and CIDR helpers in if / ternary / logical conditions..

Property Value
Rule ID NGB082
Category Angular SSR security
Default severity high
CWE CWE-290, CWE-348
Built-in presets recommended: error, strict: error

Confidence is reported per finding (high, medium, low) and is independent of severity. See Reading findings.

What it checks

Reports server code that makes an access-control decision from a client IP taken from forwarding headers (X-Forwarded-For, X-Real-IP, True-Client-IP, CF-Connecting-IP, X-Client-IP, Forwarded) or from Express req.ip / req.ips while app.set('trust proxy', true) trusts every hop: comparisons with IP literals, allowlist / blocklist lookups and CIDR helpers in if / ternary / logical conditions.

Why it matters

These headers are plain request headers: any client can send X-Forwarded-For: 127.0.0.1. Proxies append to the header rather than replace it, so the left-most value is always attacker-chosen, and trust proxy: true makes Express return exactly that value as req.ip. Admin endpoints, internal APIs or IP-based bypasses guarded this way are open to everyone.

Detection behavior and supported patterns

  • Header reads: req.headers['x-forwarded-for'], req.get('x-real-ip'), req.header('True-Client-IP'), also after .split(',')[0].trim() / || fallback, directly in the condition or through a local variable
  • req.ip / req.ips when the project calls app.set('trust proxy', true)
  • Decisions: ip === '127.0.0.1', ip.startsWith('10.'), ALLOWED_IPS.includes(ip), blocked.has(ip), ipRangeCheck(ip, …), isPrivate(ip) in an if, ternary or && / || condition

Example

TypeScript
const ip = req.headers['x-forwarded-for']?.split(',')[0];if (ip !== '127.0.0.1') return res.sendStatus(403);

Safer alternative

TypeScript
app.set('trust proxy', 1); // exactly one trusted reverse proxyif (!ADMIN_NETWORK.contains(req.ip)) return res.sendStatus(403);

Remediation

Do not authorize by IP from request headers. If IP checks are needed, configure Express trust proxy with the exact number of trusted hops or the proxy addresses and use req.ip, or use the socket address (req.socket.remoteAddress) when there is no proxy — and prefer real authentication for privileged endpoints.

False-positive considerations

  • Code behind a proxy that strips and rewrites these headers (e.g. Cloudflare-only origins reading CF-Connecting-IP with origin firewalling) is not exploitable; document an exception naming that control.

Known limitations

  • Checks performed in helper functions that receive the IP as a parameter are not followed.
  • Proxy-specific settings (a trusted hop count, trust proxy: 'loopback') make req.ip reliable and are not reported; the proxy deployment itself is not visible.
  • Rate limiting keyed by these headers (bypassable, but not an authorization decision) is not reported.

References

Run it

Shell
ngbastion explain NGB082