Skip to content

expose --host-header: make Ollama and other host-checking services work (0.7.1) - #11

Merged
longzhi merged 2 commits into
mainfrom
feat/host-header
Oct 14, 2026
Merged

longzhi merged 2 commits into
mainfrom
feat/host-header

Conversation

@longzhi

@longzhi longzhi commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Problem

Exposing Ollama (the README's headline example, expose ai 11434) returned 403 even with the right key, through every provider. Ollama only answers requests whose Host is localhost/a loopback address; Cloudflare, Pangolin and Tailscale all forward the public host name. Vite and Rails dev servers do the same. The earlier demo used a mock model, so this went unnoticed.

Change

expose ... --host-header <host> (opt-in):

  • Cloudflare: tunnel ingress originRequest.httpHostHeader
  • Pangolin: resource setHostHeader
  • Tailscale: refused with an explanation (tailscale serve can't rewrite Host)

Off by default because ordinary web apps (Rails, for one) need the real host name for links and redirects. README (EN/ZH) examples and CLAUDE.md updated. VERSION 0.7.1.

Tested on the test machine (real Ollama, qwen2.5:1.5b)

  • Cloudflare --auth bearer --host-header localhost: with key 200 and the model answers (~2.8 s round trip); without key 403 at the edge
  • Pangolin --auth password --host-header localhost: with credentials 200; without 401
  • Tailscale + --host-header: refused with the hint
  • shellcheck

Found on the way, not fixed here: Pangolin --auth token returns 401 even with the right token, with or without --host-header and on other ports too — a separate pre-existing issue.

🤖 Generated with Claude Code

longzhi and others added 2 commits October 14, 2026 11:49
…angolin)

Ollama, Vite and similar dev servers refuse requests whose Host isn't
localhost, so exposing them returned 403 even with the right key.
Cloudflare: ingress originRequest.httpHostHeader; Pangolin: setHostHeader.
Tailscale serve can't rewrite Host, so the flag is refused there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 14, 2026 03:57

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@longzhi
longzhi merged commit af686d6 into main Oct 14, 2026
2 checks passed
@longzhi

longzhi commented Oct 14, 2026

Copy link
Copy Markdown
Contributor Author

Correction: the description says Pangolin --auth token returns 401 even with the right token. That's wrong. Token mode works.

The test script pulled the token with grep -o "Token: [^ ]*" | tail -1. That matched the curl example line and kept its closing ", so the token it sent was 27 characters instead of 26. With the token parsed correctly, a resource on 11434 with --host-header localhost returns 200 for both the P-Access-Token-Id/P-Access-Token headers and ?p_token=<id>.<token>, and 401 without credentials. Details and the lesson are in #12.

🤖 Generated with Claude Code

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.

2 participants