Skip to content

feat(server): add --allowed-host flag for DNS-rebinding allowlist - #1128

Merged
wbxl2000 merged 1 commit into
MoonshotAI:mainfrom
sailist:feat/server-allowed-host
Jun 26, 2026
Merged

feat(server): add --allowed-host flag for DNS-rebinding allowlist#1128
wbxl2000 merged 1 commit into
MoonshotAI:mainfrom
sailist:feat/server-allowed-host

Conversation

@sailist

@sailist sailist commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

No linked issue — problem explained below.

Problem

The server's DNS-rebinding Host check rejects any Host outside the default allowlist with a bare 403 Invalid Host header. Users who front kimi server with a reverse proxy or reach it via a custom domain have two friction points:

  • There is no CLI-level way to allow an extra host — the only escape hatch is the KIMI_CODE_ALLOWED_HOSTS environment variable.
  • The 403 message does not name the rejected host or tell the user how to allow it, so the failure is opaque.

What changed

  • Added a kimi server run --allowed-host <host...> flag. It is repeatable and comma-separated, and a leading dot matches a domain suffix (e.g. --allowed-host .example.com). The value is threaded through parseServerOptionsspawnDaemonChild (for daemon mode) → startServerBackgroundstartServer.
  • startServer now merges the CLI-provided hosts with KIMI_CODE_ALLOWED_HOSTS, so both sources feed the same allowlist for the HTTP and WebSocket Host checks.
  • Replaced the static Invalid Host header message with formatHostErrorMessage(), which names the rejected host and prints the exact fix, e.g. allow this host with KIMI_CODE_ALLOWED_HOSTS=evil.com or 'kimi server run --allowed-host evil.com'.
  • Updated packages/server/SECURITY.md to document the flag and added unit + e2e coverage for the flag parsing, daemon arg threading, and the new 403 message.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset. (changeset included: .changeset/server-allowed-host-flag.md)
  • Ran gen-docs skill, or this PR needs no doc update. (packages/server/SECURITY.md updated inline to cover the flag.)

- add `kimi server run --allowed-host <host...>` (repeatable or
  comma-separated; leading dot matches a domain suffix) and thread it
  through daemon spawn into startServer
- merge CLI allowed hosts with KIMI_CODE_ALLOWED_HOSTS for both the HTTP
  and WebSocket Host checks
- include the rejected host and allow guidance in the 403 error message
@changeset-bot

changeset-bot Bot commented Jun 26, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 62389ee

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@moonshot-ai/kimi-code Patch
@moonshot-ai/server Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Jun 26, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@62389ee
npx https://pkg.pr.new/@moonshot-ai/kimi-code@62389ee

commit: 62389ee

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 62389eee15

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +98 to +100
.flatMap((entry) => entry.split(','))
.map((entry) => entry.trim())
.filter((entry) => entry.length > 0);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Normalize allowed host entries before forwarding

When a user passes the actual Host header value to the new --allowed-host flag, common values like app.example.com:58627 or mixed-case hosts are forwarded unchanged, but isAllowedHost() lowercases and strips the port only from the incoming request before comparing against extra. In that scenario the newly added flag still rejects the same host it was meant to allow, so the CLI parser should normalize entries the same way the request side is normalized.

Useful? React with 👍 / 👎.

@wbxl2000
wbxl2000 merged commit 0886bff into MoonshotAI:main Jun 26, 2026
9 of 10 checks passed
@github-actions github-actions Bot mentioned this pull request Jun 26, 2026
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Jul 11, 2026
…onshotAI#1128)

- add `kimi server run --allowed-host <host...>` (repeatable or
  comma-separated; leading dot matches a domain suffix) and thread it
  through daemon spawn into startServer
- merge CLI allowed hosts with KIMI_CODE_ALLOWED_HOSTS for both the HTTP
  and WebSocket Host checks
- include the rejected host and allow guidance in the 403 error message

(cherry picked from commit 0886bff)
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