Skip to content

fix(config): allow http OPENAI_API_BASE for loopback and RFC1918#372

Merged
tbckr merged 1 commit into
mainfrom
fix/issue-371-openai-api-base-local-llm
May 13, 2026
Merged

fix(config): allow http OPENAI_API_BASE for loopback and RFC1918#372
tbckr merged 1 commit into
mainfrom
fix/issue-371-openai-api-base-local-llm

Conversation

@tbckr

@tbckr tbckr commented May 13, 2026

Copy link
Copy Markdown
Owner

Summary

Closes #371.

Test plan

  • go test ./... (extended TestCreateClientAPIBaseValidation table with loopback/RFC1918/ULA/IMDS/IPv4-mapped/link-local/unspecified/CGNAT/userinfo-trick cases; new TestCreateClientAPIBaseInsecureOptOut covers the viper opt-out)
  • TestCheckCmdInsecureAPIBaseFlag exercises the --insecure-api-base flag end-to-end through cobra → viper → CreateClient
  • golangci-lint run ./... (0 issues with golangci-lint 2.12.2 / go1.26.2 via the updated flake)
  • Manual smoke: OPENAI_API_BASE=http://localhost:11434/v1 sgpt "hi" — no warning, validation passes
  • Manual smoke: OPENAI_API_BASE=http://thinkbox:8080/v1 sgpt "hi" — fails with discoverable error pointing to --insecure-api-base / insecureAPIBase: true
  • Manual smoke: OPENAI_API_BASE=http://169.254.169.254/ sgpt "hi" — still blocked (link-local explicitly rejected)

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 tbckr force-pushed the fix/issue-371-openai-api-base-local-llm branch from 7f6d66d to 242ee05 Compare May 13, 2026 14:47
@tbckr tbckr merged commit 08ccc0f into main May 13, 2026
6 checks passed
@tbckr tbckr deleted the fix/issue-371-openai-api-base-local-llm branch May 13, 2026 14:53
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.

PR 367 adds WARN line with each request

1 participant