Skip to content

Harden relay security and diagnostics#3

Open
AmirrezaFarnamTaheri wants to merge 9 commits into
IR-NETLIFY:masterfrom
AmirrezaFarnamTaheri:master
Open

Harden relay security and diagnostics#3
AmirrezaFarnamTaheri wants to merge 9 commits into
IR-NETLIFY:masterfrom
AmirrezaFarnamTaheri:master

Conversation

@AmirrezaFarnamTaheri
Copy link
Copy Markdown

  • Add safe retries for GET, HEAD, and OPTIONS on transient 502/503/504 responses
  • Release retry response bodies before retrying
  • Restrict CORS to same-origin requests and filter preflight headers
  • Return clear 400 invalid_x_host errors for malformed targets
  • Block reserved/private targets with literal, hostname, and DNS-based checks
  • Bound DNS validation cache growth with pruning and a hard cap
  • Remove unsafe duplicate response collapsing to preserve streaming behavior
  • Improve diagnostics for retry, cache, CORS, cookie, redirect, and reserved-route state

Validation:

  • node --check netlify/edge-functions/relay.js
  • mocked relay smoke checks
  • npm run build
  • git diff --check

Keep the one-click x-host relay flow compatible with existing default servers and generated VLESS configs while improving production behavior inside the Edge Function only.

Adds hardened target parsing, loop/private-network blocking, expanded hop-by-hop header filtering, upstream timeout handling, automatic CORS preflight/response support, redirect and cookie rewriting, local diagnostics/help routes, root page caching/fallback, relay diagnostic headers, and structured request logs.

Validation: node --check netlify/edge-functions/relay.js; mocked handler smoke checks for diagnostics, CORS, SSRF blocking, proxy passthrough, redirect rewriting, cookie rewriting, preserved auth/cookie/range headers; npm run build; git diff --check.
Improve resilience and spike efficiency without changing the one-click dynamic x-host behavior.

Retries are limited to idempotent methods and retry only transient upstream failures. Duplicate suppression is limited to unauthenticated GET/HEAD requests without cookies or range headers, preserving default server, session, upload, and VLESS generator compatibility.

Validation: node --check netlify/edge-functions/relay.js; extended mocked handler smoke checks for diagnostics, CORS, SSRF blocking, proxy passthrough, redirect and cookie rewriting, safe retry recovery, and duplicate GET collapsing; npm run build; git diff --check.
Constrain browser CORS to same-origin requests, filter preflight headers against an explicit allowlist, and avoid credentialed origin reflection for arbitrary sites.

Map malformed absolute x-host values to a client-side invalid_x_host 400, add reserved-hostname suffix checks, and use Deno.resolveDns when available to block hostnames resolving to private addresses. Diagnostics now reports whether DNS-backed private-network blocking is active.

Validation: node --check netlify/edge-functions/relay.js; review-fix mocked handler smoke checks covering malformed x-host, cross-origin CORS denial, same-origin CORS allow, header filtering, DNS private target blocking, passthrough, retries, and duplicate GET collapsing; npm run build; git diff --check.
Remove unsafe in-flight response collapsing so GET/HEAD responses keep normal streaming semantics and avoid unread clone tee branches.

Release transient retry response bodies before retrying, and bound the DNS validation cache with lightweight pruning plus a hard entry cap.

Validation: node --check netlify/edge-functions/relay.js; Qodo reliability smoke checks for malformed x-host, CORS restrictions, DNS private target blocking, retry body cancellation, independent duplicate GET streaming, large GET passthrough, DNS cache cap path; npm run build; git diff --check.
Expose retry and duplicate-suppression state in diagnostics, and tag denied CORS preflights with x-relay-error for clearer logs and support triage.

Validation: node --check netlify/edge-functions/relay.js; final polish mocked smoke checks for diagnostics, CORS denial error code, same-origin preflight, malformed x-host, DNS private target blocking, retry body cancellation, duplicate GET streaming, and large GET passthrough; npm run build; git diff --check.
Expose pass-through cache behavior, absent relay rate limiting, redirect and cookie handling, retry body release, and reserved routes in diagnostics so operators can see which brainstorm features were intentionally adapted or left out for one-click compatibility.

Validation: node --check netlify/edge-functions/relay.js; final diagnostics mocked smoke checks for diagnostics fields, CORS restrictions, malformed x-host, DNS private target blocking, retry body cancellation, duplicate GET streaming, and large GET passthrough; npm run build; git diff --check.
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