Skip to content

fix: Enhance error handling and security measures across various endpoints - #251

Open
cguleroglu wants to merge 1 commit into
mainfrom
owasptop10
Open

fix: Enhance error handling and security measures across various endpoints#251
cguleroglu wants to merge 1 commit into
mainfrom
owasptop10

Conversation

@cguleroglu

Copy link
Copy Markdown
  • Updated error responses to avoid leaking internal error messages in vector providers.
  • Changed rate limiter to use shared cache for distributed deployments.
  • Added validation for PostgreSQL table names to prevent SQL injection.
  • Implemented DNS-aware URL safety checks to mitigate SSRF risks.
  • Improved logging for authentication failures and token usage.
  • Enhanced Content Security Policy in middleware for better security.

Summary

Describe the problem and the change in one or two paragraphs.

Changes

Validation

  • npm run lint
  • npm run test
  • npm run build
  • npm run docs:build

Release Notes

  • Docs updated when behavior changed
  • Security-sensitive changes reviewed
  • License or policy files updated if repo-facing behavior changed

…oints

- Updated error responses to avoid leaking internal error messages in vector providers.
- Changed rate limiter to use shared cache for distributed deployments.
- Added validation for PostgreSQL table names to prevent SQL injection.
- Implemented DNS-aware URL safety checks to mitigate SSRF risks.
- Improved logging for authentication failures and token usage.
- Enhanced Content Security Policy in middleware for better security.
@cguleroglu
cguleroglu requested a review from a team August 31, 2026 20:57
anilguleroglu added a commit that referenced this pull request Sep 6, 2026
…tion (F-09) (#279)

* fix(security): configurable proxy trust boundary for client IP resolution (F-09)

The remaining half of F-09 not covered by the open, conflicting PR
#251 (which fixes the auth rate limiter's process-local counter but
does not touch IP trust at all).

- getClientIp() read the raw X-Forwarded-For header directly and
  trusted its leftmost value unconditionally -- any caller who could
  reach this process at all (not only one behind the real reverse
  proxy) could set an arbitrary IP. This fed both the auth rate
  limiter's bucket key (spoof a new IP, get a fresh rate-limit window)
  and audit IP logging (spoof any IP into the audit trail). Fastify's
  own `request.ip` already exists specifically to answer this
  correctly given a configured trust boundary -- getClientIp() now
  prefers it, falling back to raw header parsing only when it is
  unavailable.
- `trustProxy: true` was hardcoded, telling Fastify to trust every hop
  regardless of whether a real proxy sits in front of this process.
  Added `network.trustedProxies` (TRUSTED_PROXIES: comma-separated
  IPs/CIDRs, or a single integer for a hop count) so an operator with
  a real reverse proxy/load balancer can scope trust to it. Unset
  (default) preserves the exact current `trustProxy: true` behaviour --
  this is an opt-in hardening lever, not a default-behavior change,
  since flipping the default would silently break IP-based rate
  limiting and audit logging for every deployment that legitimately
  sits behind a proxy today.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KQq6TnVNHRNU6Wz1eQzPpD

* review: drop the header fallbacks getClientIp no longer needs

Pre-merge review of this PR: with `request.ip` checked first, the
X-Forwarded-For and X-Real-IP branches below it are unreachable
(`request.ip` falls back to the socket address on its own) — and if one
ever did run, it would do the exact thing this PR exists to stop:
believe a header the caller can set, regardless of the trustProxy
boundary. Removed, leaving `request.ip || 'unknown'`.

Deployment note now in the function's doc comment: a proxy that sets
ONLY X-Real-IP (no X-Forwarded-For) will show up as the proxy's own
address — set X-Forwarded-For on it and list the proxy in
TRUSTED_PROXIES.

The two tests that asserted the removed fallbacks now assert the
opposite (a spoofable header is never read here).

Test plan: 7/7 in trust-proxy-and-client-ip.test.ts; full suite 5053
passed, 5 skipped, 0 failed; tsc + eslint clean.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KQq6TnVNHRNU6Wz1eQzPpD

---------

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant