ollama - 💡(How to fix) Fix HIGH: Cloud proxy forwards X-Forwarded-For and X-Real-IP — clients can spoof origin IP to ollama.com

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Code Example

func copyProxyRequestHeaders(dst, src http.Header) {
    connectionTokens := connectionHeaderTokens(src)
    for key, values := range src {
        if isHopByHopHeader(key) || isConnectionTokenHeader(key, connectionTokens) {
            continue
        }
        dst.Del(key)
        for _, value := range values {
            dst.Add(key, value)
        }
    }
}

---

var clientProxyHeaders = []string{
    "Forwarded",
    "X-Forwarded-For",
    "X-Forwarded-Host",
    "X-Forwarded-Proto",
    "X-Forwarded-Port",
    "X-Real-IP",
    "X-Request-ID",
    "X-Client-IP",
}

func copyProxyRequestHeaders(dst, src http.Header) {
    // ... existing hop-by-hop logic ...
    for _, h := range clientProxyHeaders {
        dst.Del(h)
    }
}
RAW_BUFFERClick to expand / collapse

CWE-348: Cloud Proxy Forwards Untrusted Client Headers — IP Spoofing / Request Forgery

Severity: HIGH (CVSS 7.5)

Location

server/cloud_proxy.gocopyProxyRequestHeaders():

func copyProxyRequestHeaders(dst, src http.Header) {
    connectionTokens := connectionHeaderTokens(src)
    for key, values := range src {
        if isHopByHopHeader(key) || isConnectionTokenHeader(key, connectionTokens) {
            continue
        }
        dst.Del(key)
        for _, value := range values {
            dst.Add(key, value)
        }
    }
}

Only hop-by-hop headers (Connection, Keep-Alive, Transfer-Encoding, etc.) are stripped. All other client-supplied headers are forwarded verbatim to ollama.com including:

  • X-Forwarded-For
  • X-Forwarded-Host
  • X-Forwarded-Proto
  • X-Real-IP
  • Forwarded
  • X-Forwarded-Port

Impact

An attacker sending requests through the cloud proxy can:

  1. Spoof origin IP by setting X-Forwarded-For: 1.2.3.4 — bypassing rate limits, IP bans, or geographic restrictions on ollama.com
  2. Forge request origin — upstream services see spoofed client metadata
  3. Inject arbitrary HTTP headers that affect upstream request processing
  4. Bypass abuse detection — make malicious traffic appear to come from trusted IPs

This affects all cloud-proxied endpoints:

  • /api/generate / /api/chat (when model is :cloud)
  • /v1/chat/completions / /v1/completions / /v1/embeddings
  • /v1/images/generations / /v1/images/edits
  • /v1/messages

Remediation

Strip proxy/source headers from the incoming client request before forwarding:

var clientProxyHeaders = []string{
    "Forwarded",
    "X-Forwarded-For",
    "X-Forwarded-Host",
    "X-Forwarded-Proto",
    "X-Forwarded-Port",
    "X-Real-IP",
    "X-Request-ID",
    "X-Client-IP",
}

func copyProxyRequestHeaders(dst, src http.Header) {
    // ... existing hop-by-hop logic ...
    for _, h := range clientProxyHeaders {
        dst.Del(h)
    }
}

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

ollama - 💡(How to fix) Fix HIGH: Cloud proxy forwards X-Forwarded-For and X-Real-IP — clients can spoof origin IP to ollama.com