Skip to content

feat(proxy): enforce upstream failover timeout window and sanitize X-Request-ID against CRLF injection - #7

Merged
ATLURI0001 merged 1 commit into
mainfrom
feat/proxy-failover-window-and-header-crlf-guard
Nov 14, 2026
Merged

ATLURI0001 merged 1 commit into
mainfrom
feat/proxy-failover-window-and-header-crlf-guard

Conversation

@ATLURI0001

Copy link
Copy Markdown
Owner

Technical Deep-Dive & Defensive Hardening

Background & Failure Mode Analysis

  1. Unbounded Next Upstream Windows: While Nginx upstream retry attempts were capped via proxy_next_upstream_tries 2;, the overall retry window lacked an explicit timeout bound (proxy_next_upstream_timeout). Under sustained cascading upstream failure or slow network partitions, requests could hang up to full connection/read timeout limits across retries.
  2. HTTP Header Injection Protection: The upstream demo application reflected incoming X-Request-ID headers directly back into downstream JSON payloads and HTTP response headers without sanitization. If an untrusted upstream or client injected carriage returns (\r) or line feeds (\n), it could trigger header splitting or malformed response frames in legacy clients.

Implementation Details

  • Nginx Upstream Retry Window Bound: Added proxy_next_upstream_timeout 10s; to nginx/snippets/proxy.conf, ensuring that client requests fail over promptly rather than lingering across hanging upstreams.
  • Header Value Sanitization: Implemented sanitize_header_val helper in apps/demo/app.py stripping \r and \n characters from X-Request-ID values before propagation into headers and responses.
  • Invariant Assertions: Updated tests/test_project.py to assert the bounded failover window and header sanitization invariants.

Testing & Verification

  • python -m pytest tests/test_project.py
  • Result: 17 passed in 0.06s.

@ATLURI0001
ATLURI0001 merged commit c95491e into main Nov 14, 2026
0 of 2 checks passed
@ATLURI0001
ATLURI0001 deleted the feat/proxy-failover-window-and-header-crlf-guard branch November 14, 2026 07:41
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