Skip to content

Add defensive nil checks to prevent container crashes from malformed requests#17

Merged
bbrowning merged 1 commit into
mainfrom
defensive-checks-no-crash
May 11, 2026
Merged

Add defensive nil checks to prevent container crashes from malformed requests#17
bbrowning merged 1 commit into
mainfrom
defensive-checks-no-crash

Conversation

@bbrowning
Copy link
Copy Markdown
Owner

Adds nil pointer checks throughout HTTP request handling to prevent container crashes when proxying to upstream domains that send malformed requests. The goproxy library can pass requests with nil fields under certain edge cases (corrupted parsing, malformed CONNECT requests, TLS handshake failures).

Changes:

  • Add nil checks for req, req.URL in all credential injectors and proxy handlers
  • Return graceful HTTP 400/500 error responses instead of panicking
  • Add validateRequest() helper to eliminate duplicate nil check code
  • Add errorResponse() helper for consistent error response creation
  • Add comprehensive unit tests for all nil pointer scenarios
  • Remove impossible checks (req.Header, credentials after init, ctx from goproxy)
  • Reduce hot-path logging overhead by removing logs from non-error paths

All defensive checks log with "DEFENSIVE_CHECK:" prefix for production monitoring.

…requests

Adds nil pointer checks throughout HTTP request handling to prevent container
crashes when proxying to upstream domains that send malformed requests. The
goproxy library can pass requests with nil fields under certain edge cases
(corrupted parsing, malformed CONNECT requests, TLS handshake failures).

Changes:
- Add nil checks for req, req.URL in all credential injectors and proxy handlers
- Return graceful HTTP 400/500 error responses instead of panicking
- Add validateRequest() helper to eliminate duplicate nil check code
- Add errorResponse() helper for consistent error response creation
- Add comprehensive unit tests for all nil pointer scenarios
- Remove impossible checks (req.Header, credentials after init, ctx from goproxy)
- Reduce hot-path logging overhead by removing logs from non-error paths

All defensive checks log with "DEFENSIVE_CHECK:" prefix for production monitoring.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@bbrowning bbrowning merged commit a2eef3c into main May 11, 2026
6 checks passed
@bbrowning bbrowning deleted the defensive-checks-no-crash branch May 11, 2026 12:29
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