Skip to content

config: validate OPENAI_API_BASE against SSRF risks#367

Merged
tbckr merged 1 commit into
tbckr:mainfrom
SAY-5:security/validate-openai-api-base-358
May 5, 2026
Merged

config: validate OPENAI_API_BASE against SSRF risks#367
tbckr merged 1 commit into
tbckr:mainfrom
SAY-5:security/validate-openai-api-base-358

Conversation

@SAY-5

@SAY-5 SAY-5 commented May 5, 2026

Copy link
Copy Markdown
Contributor

Validates OPENAI_API_BASE as an absolute https URL with a non-empty host before applying it; without this, a hostile env var or config file silently redirects the Authorization: Bearer header to an attacker-controlled endpoint. The check is hostname-agnostic to preserve compatibility with Azure OpenAI, OpenRouter, and self-hosted backends fronted by TLS.

Closes #358.

Signed-off-by: SAY-5 <saiasish.cnp@gmail.com>
@SAY-5 SAY-5 requested a review from tbckr as a code owner May 5, 2026 11:01
@codecov

codecov Bot commented May 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.81818% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.80%. Comparing base (abd2da9) to head (8576def).
⚠️ Report is 328 commits behind head on main.

Files with missing lines Patch % Lines
pkg/api/api.go 81.81% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #367      +/-   ##
==========================================
+ Coverage   75.80%   78.80%   +2.99%     
==========================================
  Files          20       21       +1     
  Lines        1298     1151     -147     
==========================================
- Hits          984      907      -77     
+ Misses        226      155      -71     
- Partials       88       89       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tbckr tbckr enabled auto-merge (squash) May 5, 2026 12:14
@tbckr tbckr disabled auto-merge May 5, 2026 12:14
@tbckr tbckr merged commit 262af09 into tbckr:main May 5, 2026
7 checks passed
tbckr added a commit that referenced this pull request May 13, 2026
PR #367 enforced https-only on OPENAI_API_BASE to close #358, which
broke local LLM setups (Ollama, LiteLLM, vLLM in containers) that
legitimately use plain http on loopback or private networks.

The validator now accepts:
- https for any host (unchanged)
- http for localhost, 127.0.0.0/8, ::1, RFC1918 (10/8, 172.16/12,
  192.168/16) and RFC4193 ULA (fc00::/7)

Link-local (169.254/16 IMDS, fe80::/10) and 0.0.0.0/8 are rejected
explicitly so the IMDS exfiltration vector from #358 stays blocked.

Single-label LAN hostnames (e.g. http://thinkbox:8080/v1) can't be
classified by IP literal and need an explicit opt-out via the new
--insecure-api-base persistent flag or insecureAPIBase: true in
config.yaml. The opt-out is deliberately not bound to an env var:
#358's threat model assumes attacker control of the environment, so
an env-var opt-out would undo the validation guarantee.

When validation passes, the override is logged at debug instead of
warn (PR #367 emitted a warn line per request, which interleaved
with stderr in scripts).

Closes #371.
tbckr added a commit that referenced this pull request May 13, 2026
PR #367 enforced https-only on OPENAI_API_BASE to close #358, which
broke local LLM setups (Ollama, LiteLLM, vLLM in containers) that
legitimately use plain http on loopback or private networks.

The validator now accepts:
- https for any host (unchanged)
- http for localhost, 127.0.0.0/8, ::1, RFC1918 (10/8, 172.16/12,
  192.168/16) and RFC4193 ULA (fc00::/7)

Link-local (169.254/16 IMDS, fe80::/10) and 0.0.0.0/8 are rejected
explicitly so the IMDS exfiltration vector from #358 stays blocked.

Single-label LAN hostnames (e.g. http://thinkbox:8080/v1) can't be
classified by IP literal and need an explicit opt-out via the new
--insecure-api-base persistent flag or insecureAPIBase: true in
config.yaml. The opt-out is deliberately not bound to an env var:
#358's threat model assumes attacker control of the environment, so
an env-var opt-out would undo the validation guarantee.

When validation passes, the override is logged at debug instead of
warn (PR #367 emitted a warn line per request, which interleaved
with stderr in scripts).

Closes #371.
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.

security: unvalidated OPENAI_API_BASE enables SSRF and API key exfiltration

2 participants