Skip to content

fix(security): harden image proxy DNS rebinding, upload memory limits, and origin audit logging - #771

Draft
jermaine7511261 wants to merge 1 commit into
Stack-Cairn:mainfrom
jermaine7511261:fix/security-hardening
Draft

fix(security): harden image proxy DNS rebinding, upload memory limits, and origin audit logging#771
jermaine7511261 wants to merge 1 commit into
Stack-Cairn:mainfrom
jermaine7511261:fix/security-hardening

Conversation

@jermaine7511261

Copy link
Copy Markdown

Summary

This PR addresses several security findings from a source code audit of the agent-gateway component.

Changes

1. Image Proxy DNS Rebinding Protection (image_proxy.go)

  • Problem: The image proxy validated outbound URLs using safeurl with IP blocklist, but did not resolve DNS before the actual request. DNS rebinding attacks could return a safe IP during validation and a malicious (internal) IP during the request.
  • Fix: Added DNS resolution check in validateImageProxyURL that resolves the hostname and verifies all resolved IPs are not in blocked ranges before allowing the request.

2. Per-File Upload Size Limit (upload.go)

  • Problem: The upload endpoint had a 100 MiB total limit but no per-file limit. A single large file could cause memory exhaustion.
  • Fix: Added maxPerFileUploadBytes = 20 MiB per-file limit with io.LimitReader to prevent unbounded memory allocation. Returns 413 Request Entity Too Large with the specific file name when exceeded.

3. WebSocket Origin Audit Logging (origin.go)

  • Problem: WebSocket upgrades without an Origin header (non-browser clients) were silently allowed with no audit trail.
  • Fix: Added slog.Debug logging when no Origin header is present, recording the remote address for security audit purposes.

4. Outbound Ports Documentation (outbound_http.go)

  • Problem: buildOutboundAllowedPorts() allocates a 65535-element []int slice (~512 KB) at init time, passed as variadic arguments to safeurl.
  • Fix: Added documentation explaining the trade-off and a buildOutboundAllowedPortsCompact() alternative for future optimization if the library supports range-based configuration.

Testing

  • All changes are backward-compatible
  • Image proxy DNS check gracefully handles DNS failures (returns error)
  • Upload limit is enforced per-file, not changing total limit behavior
  • Origin logging uses Debug level (no production noise)

Related

Source code audit of the agent-gateway Go codebase, focusing on SSRF, memory safety, and security observability.

- image_proxy: add DNS resolution check before outbound request to prevent
  DNS rebinding SSRF attacks. Resolves hostname and verifies IP is not in
  blocked ranges before making the HTTP request.
- upload: add per-file size limit (20 MiB) to prevent memory exhaustion
  from large individual file uploads within the 100 MiB total limit.
- origin: log WebSocket upgrades without Origin header for audit trail.
  Non-browser clients are still allowed but their access is now recorded.
- outbound_http: document buildOutboundAllowedPorts memory allocation
  and add compact alternative for future optimization.

Ref: source code audit findings
@StackCairn
StackCairn marked this pull request as draft September 7, 2026 01:15
@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

PR governance checks failed — this PR has been converted to draft.

  • No linked issue: the PR body must contain Closes #123 / Fixes #123 / Resolves #123. This project requires an issue before a PR — see the contribution guidelines.

Fix the items above, then click Ready for review to re-run the checks.

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