Skip to content

Restrict MCP access keys by IP address - #5

Merged
ruibaby merged 3 commits into
mainfrom
feat/restrict-mcp-access-keys-by-ip
Aug 24, 2026
Merged

Restrict MCP access keys by IP address#5
ruibaby merged 3 commits into
mainfrom
feat/restrict-mcp-access-keys-by-ip

Conversation

@ruibaby

@ruibaby ruibaby commented Aug 24, 2026

Copy link
Copy Markdown
Member

What changed

  • Add optional IPv4, IPv6, and CIDR allowlists to MCP access keys.
  • Provide a multiline Console textarea that accepts one address or CIDR per line; leaving it empty keeps the key unrestricted.
  • Normalize and validate allowlist entries when access keys are created or updated.
  • Enforce configured allowlists during authentication before updating the key last-used time.
  • Expose IP restrictions through the management API and show their status in the access-key list.
  • Document reverse-proxy trust requirements and the security boundaries of IP restrictions.

Security impact

Restricted access keys are accepted only when the resolved remote address matches an allowed entry from the same address family. IPv4 ranges never match IPv6 clients, and IPv6 ranges never match IPv4 clients.

CIDR masks must use unsigned decimal notation and stay within the address-family limit. Authentication fails closed when a restricted key has an unknown remote address or invalid stored configuration. A missing or empty allowlist preserves unrestricted access.

Deployments behind a reverse proxy must ensure that untrusted clients cannot control forwarded-address headers or bypass the trusted proxy.

Console

The create and edit forms use a multiline textarea for allowed IP addresses. The access-key list distinguishes unrestricted keys from keys with configured IP restrictions.

Verified against a running Halo 2.26.0 Console at /console/mcp: the textarea, per-line examples, unrestricted hint, and list status render correctly with no browser console errors.

Testing

  • git diff --check
  • ./gradlew check
  • Halo 2.26.0 Console runtime verification

@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: 70cd325526

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/main/java/run/halo/mcpserver/McpIpAllowlist.java Outdated
@ruibaby
ruibaby merged commit ff436aa into main Aug 24, 2026
1 check passed
@ruibaby
ruibaby deleted the feat/restrict-mcp-access-keys-by-ip branch August 24, 2026 06:50
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