Skip to content

Keep backend credentials off environment proxies and cross-host redirects - #234

Merged
thushan merged 7 commits into
mainfrom
fix/backend-client-no-proxy
Oct 27, 2026
Merged

thushan merged 7 commits into
mainfrom
fix/backend-client-no-proxy

Conversation

@thushan

@thushan thushan commented Oct 26, 2026 •

Copy link
Copy Markdown
Owner

Summary

Model discovery used an http.Client with no transport, so it honoured HTTP_PROXY/HTTPS_PROXY. That sent backend credentials (auth: bearer or basic, X-Api-Key, custom headers:) through an environment proxy. Discovery and health checks also followed cross-host redirects, which replayed X-Api-Key and custom headers to the new host.

Discovery and health now share factory.NewBackendHTTPClient, which:

  • never uses a proxy;
  • follows only same-origin redirects, plus a same-host http to https upgrade;
  • compares hosts with ASCII case folding only.

The proxy engines are untouched; only their comments change.

Type of change

  • Bug fix
  • Documentation

How was this tested?

New tests:

  • TestDiscoveryClient_IgnoresEnvironmentProxy
  • TestDiscoveryClient_DoesNotReplayCredentialsOnCrossHostRedirect
  • TestHealthClient_RefusesCrossHostRedirect
  • TestRefuseCrossOriginRedirect: ports, default ports, downgrade, σ/ς, Kelvin K and IPv6 zone cases
  • TestNewBackendHTTPClient_DoesNotReplayHeadersAcrossHosts

The discovery and health tests fail against 1cda972.

A live run on integration/test-october (85f9244) used a backend on a non-loopback address with HTTP_PROXY pointing at a capture listener. On this fix the listener saw 0 requests. On 1cda972 it saw 1, the discovery request.

The http to https upgrade isn't exercised live, because there is no TLS fixture. Unit tests cover it.

Checklist

  • make ready passes at e1d2a6d
  • Tests added or updated for the change
  • Documentation updated: configuration/endpoint-auth.md "Proxies and Redirects", plus the v0.0.30 release note
  • No new dependencies added

Summary by CodeRabbit

  • Bug Fixes
    • Health checks and model discovery now connect directly to configured backends instead of using environment proxy settings.
    • Redirects are followed only when the destination uses the same host and port. Same-host HTTP-to-HTTPS upgrades are allowed; other redirects fail, and credentials are not sent to cross-host redirect destinations.
    • Non-loopback backends previously accessed through an environment proxy must now be reachable directly from the Olla host.
  • Documentation
    • Release notes and endpoint authentication guidance now explain proxy and redirect behavior.

@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 68b6618 and e1d2a6d.

Files selected for processing: 13
  • docs/content/about/release-notes.md
  • docs/content/configuration/endpoint-auth.md
  • internal/adapter/discovery/http_client.go
  • internal/adapter/factory/client.go
  • internal/adapter/factory/client_test.go
  • internal/adapter/health/checker.go
  • internal/adapter/health/client_transport_test.go
  • internal/adapter/proxy/olla/service.go
  • internal/adapter/proxy/olla/service_transport_test.go
  • internal/adapter/proxy/sherpa/service.go
  • internal/adapter/proxy/sherpa/service_transport_test.go
  • internal/app/services/discovery.go
  • internal/app/services/discovery_client_test.go

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

Walkthrough

The change centralises backend HTTP client creation. Health checks and model discovery now bypass environment proxies and restrict redirects. Tests and documentation cover credential handling, direct connections, and cross-host redirect refusal.

Changes

Backend HTTP policy

Layer / File(s) Summary
Backend transport and redirect policy
internal/adapter/factory/client.go, internal/adapter/factory/client_test.go
Adds backend transport and client constructors. Clients ignore environment proxies and permit only same-host redirects, including HTTP-to-HTTPS upgrades.
Health and discovery client integration
internal/adapter/discovery/http_client.go, internal/adapter/health/checker.go, internal/app/services/discovery.go
Health checks and model discovery use the backend client factory with their existing timeout and connection-pool settings.
Credential and proxy validation
internal/adapter/health/client_transport_test.go, internal/app/services/discovery_client_test.go
Tests verify direct backend access, API-key delivery to the backend, and refusal of cross-host redirects.
Proxy and redirect documentation
docs/content/configuration/endpoint-auth.md, docs/content/about/release-notes.md, internal/adapter/proxy/...
Documents direct connections, credential use, and permitted redirect behaviour. Updates transport comments for Olla and Sherpa.准

Priority: Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant DiscoveryService
  participant HealthChecker
  participant BackendHTTPClient
  participant BackendEndpoint
  DiscoveryService->>BackendHTTPClient: discover models with endpoint credentials
  HealthChecker->>BackendHTTPClient: check endpoint health with endpoint credentials
  BackendHTTPClient->>BackendEndpoint: connect directly without environment proxy
  BackendEndpoint-->>BackendHTTPClient: return response or redirect
  BackendHTTPClient-->>DiscoveryService: follow permitted redirect or return error
  BackendHTTPClient-->>HealthChecker: follow permitted redirect or report unhealthy
Loading

Possibly related PRs

  • thushan/olla#231: Adds TEI model discovery and health checks that inherit the backend client policy from this change.
Merge Risk: Minimal · up to e1d2a

The supplied evidence identifies no issue that would block merging after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 65.38% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 26 functions across 11 files. (2 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly summarises the main change: preventing backend credentials from using environment proxies and blocking cross-host redirects.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 65.38% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 26 functions across 11 files. (2 skipped: 2 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@thushan
thushan merged commit ba60a23 into main Oct 27, 2026
6 checks passed
@thushan
thushan deleted the fix/backend-client-no-proxy branch October 27, 2026 08:04
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