Skip to content

fix(security): harden open proxy fallback against SSRF and key leak - #6859

Open
Solaris-star wants to merge 1 commit into
ChatGPTNextWeb:mainfrom
Solaris-star:fix/6813-6814-proxy-security
Open

fix(security): harden open proxy fallback against SSRF and key leak#6859
Solaris-star wants to merge 1 commit into
ChatGPTNextWeb:mainfrom
Solaris-star:fix/6813-6814-proxy-security

Conversation

@Solaris-star

Copy link
Copy Markdown

Summary

The open proxy fallback (app/api/proxy.ts) had two related issues:

  1. Unauthenticated SSRF via Open Proxy Fallback Route (x-base-url header) #6813 SSRF: any unauthenticated client could set x-base-url to an arbitrary URL (including internal/metadata hosts) and the server would fetch it.
  2. Server OpenAI API Key Exfiltration via Incomplete URL Substring Check in Proxy Handler #6814 key exfiltration: baseUrl.includes("api.openai.com") injected the server OpenAI key for attacker hosts such as http://attacker.com?q=api.openai.com.

Changes

  • Require auth() like other provider handlers
  • Parse x-base-url with the URL constructor (http/https only)
  • Block obvious SSRF targets (loopback, RFC1918, link-local, CGNAT 100.64/10, metadata-ish hosts)
  • Inject the server OpenAI key only when hostname === "api.openai.com"

Testing

  • Local helper checks for OpenAI hostname exactness and private/CGNAT/metadata blocking
  • Full Next.js suite not run here; please run CI

Fixes #6813
Fixes #6814

The fallback proxy accepted any x-base-url without auth and used a
substring check for api.openai.com, allowing unauthenticated SSRF and
server API key exfiltration via attacker hosts containing that string.

Require auth like other providers, parse x-base-url as a real URL,
block private/loopback/CGNAT/metadata hosts, and only inject the server
OpenAI key when the hostname is exactly api.openai.com.

Fixes ChatGPTNextWeb#6813
Fixes ChatGPTNextWeb#6814

Signed-off-by: Solaris-star <820622658@qq.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

1 participant