Skip to content

A server whose LOOM_BIND_HOST is not loopback refuses MCP open mode and a signing or verifying key below the minimum size, and the dev ClickHouse stays on loopback - #327

Merged
zlareb1 merged 13 commits into
mainfrom
sec/unsafe-public-configs
Nov 7, 2026
Merged

zlareb1 merged 13 commits into
mainfrom
sec/unsafe-public-configs

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Backward Incompatible Change

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

A server whose LOOM_BIND_HOST is not a loopback address refuses to start with LOOM_MCP_AUTH_MODE=open or with a LOOM_JWT_SECRET below RFC 7518's minimum key size (an HMAC secret shorter than 32 bytes or an RSA key under 2048 bits; only the length is checked), or a gateway or inline end-user issuer key under 2048 bits, unless LOOM_ALLOW_INSECURE=1; loom doctor and /v1/health report both conditions. scripts/serve.sh, run from a checkout, treats a non-loopback LOOM_LISTEN_HOST as the bind address when the environment does not set LOOM_BIND_HOST (the image sets both). The development compose file and the per-worktree ClickHouse start script publish ClickHouse on 127.0.0.1 only.

Why

require_safe_bind already refused a public bind with auth off or with the development secret. Two settings with the same effect were not covered:

  • LOOM_MCP_AUTH_MODE=open runs every MCP tool with no principal, so anyone who can reach the port reads and writes memory.
  • A root key below RFC 7518's minimum size (an HMAC secret shorter than 32 bytes, an RSA key under 2048 bits) is weaker than the signature algorithm assumes; a short secret is usually a short password, which one captured token lets an attacker brute-force offline, and a key that signs any token mints any token.

The development compose file published ClickHouse's HTTP and native ports on LOOM_BIND_HOST. A developer who set that to 0.0.0.0 to reach the dashboard from another machine also exposed ClickHouse, which runs with the development password and access management on.

Design

  • server/boot.py: require_safe_bind takes required mcp_open and weak_keys arguments, so a caller cannot leave a check off by omission, and refuses a non-loopback bind for each with a message that names the setting, unless allow_insecure is set. The check sits with the existing ones, so it runs at the same point of start-up, before anything connects.
  • server/auth/keyring.py: root_is_weak() is true for a PEM RSA private key under 2048 bits (MIN_RSA_BITS; its modulus is public in the JWKS) and for any other root whose UTF-8 encoding is under 32 bytes (MIN_HMAC_BYTES, the HS256 key-length guidance of RFC 7518 section 3.2; the root also seals stored keys, so a secret PyJWT refuses as an HMAC key counts). server/main.py passes weak_keys() and settings.mcp_auth_mode == "open".
  • server/auth/keyring.py: weak_keys() names every key below the minimum: LOOM_JWT_SECRET, a gateway key (gateway:<kid>) and an end-user issuer's inline key (end_user:<issuer>:<kid>). Each verifying RSA key is loaded the way the verifier loads it (PEM or OpenSSH, through PyJWT), since its modulus is public and one under 2048 bits is as weak as a short root. Keys fetched from an end-user issuer's JWKS URL arrive at runtime and are not checked, nor are machine-trust keys. A key PyJWT cannot load verifies nothing and is skipped, so an odd value never crashes the start. main.py and the health problems call the same function, and the refusal names each key.
  • server/observability/problems.py: insecure_bind_mcp_open and insecure_bind_weak_key sit beside the auth-off and dev-secret problems, error or warn under LOOM_ALLOW_INSECURE=1 as those are, so a running server and loom doctor show what the next start would refuse.
  • scripts/serve.sh: the startup checks read LOOM_BIND_HOST, while uvicorn listens on LOOM_LISTEN_HOST; setting only the second to 0.0.0.0 on a launch from a checkout skipped every check (the image sets both). When LOOM_BIND_HOST is unset and the listen address is not loopback, the launcher exports it as the bind address. A container published on loopback still sets both, as documented.
  • dev/ci_start_clickhouse.sh, which the dev-setup guide uses for each worktree's ClickHouse, publishes both ports on 127.0.0.1.
  • dev/docker-compose.dev.yml: both ClickHouse port mappings bind 127.0.0.1. The Loom container reaches ClickHouse over the compose network, so nothing else changes.

Scope and risk

server/boot.py, server/auth/keyring.py, server/main.py, the dev compose file, the bind_host and allow_insecure setting comments with their regenerated reference, schema and example, docs/operations/deployment.md, docs/architecture/security.md, docs/reference/mcp.md, docs/reference/environment.md, .env.example, server/observability/problems.py, the jwt_secret, jwt_public_keys_json, jwt_end_user_issuers_json and mcp_auth_mode comments with their regenerated reference, schema and example, scripts/serve.sh, tests/unit/test_web_exposure.py, tests/unit/test_serve_launcher.py and tests/unit/test_health_problems.py, plus server/auth/machines.py (its inline-key check uses keyring.MIN_RSA_BITS) and dev/ci_start_clickhouse.sh. A deployment that binds publicly with MCP open mode or a weak root key no longer starts; the error names the setting, and LOOM_ALLOW_INSECURE=1 keeps the old behaviour on purpose.

The size rules are written out in keyring rather than taken from PyJWT's own key-length checks, because the declared PyJWT floor predates those checks.

Compatibility, rollout and rollback

  • Wire: none.
  • Operator steps: a public deployment running LOOM_MCP_AUTH_MODE=open switches to token auth, and one with a weak root key rotates to an HMAC secret of at least 32 bytes or an RSA key of at least 2048 bits. Someone who reached the dev ClickHouse from another machine now goes through an SSH tunnel.
  • Rollback: revert.

Tests

pytest tests/unit/test_web_exposure.py: a public bind refuses MCP open mode and a weak root key, and starts with either on loopback or with LOOM_ALLOW_INSECURE=1; root_is_weak is true for a 31-byte HMAC secret (ASCII or multi-byte), a short secret PyJWT refuses as an HMAC key and a 1024-bit RSA key, false for 32 bytes, 32 bytes of multi-byte characters and a 2048-bit RSA key; the server's own lifespan refuses a public bind with MCP open mode and with a 31-byte secret before it connects to anything; an EC root key is not weak; a 1024-bit gateway key in PEM or OpenSSH form and a 1024-bit inline end-user issuer key are named, a 2048-bit or unparsable one is not, and an EC or Ed25519 key returned by an RSA loader that does not check the type is not; the refusal names the key; the exposure problems report MCP open mode and a weak root key on a reachable bind (as warn under the override) and not on loopback; every ClickHouse port in the dev compose file and the start script binds 127.0.0.1; pytest tests/unit/test_serve_launcher.py: a non-loopback listen address with no bind address reaches the server as LOOM_BIND_HOST, an explicit one is kept, and the IPv6 wildcard is checked, and a loopback (127.0.0.1, ::1, localhost) or unset listen address leaves it to the settings. The refusal cases fail on main.

AI assistance in the code (leave one; writing this description with AI is fine):

  • AI-generated (an agent wrote most of the diff): Claude Code. I checked each start-up path against the settings it reads and read the diff and its tests.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • make format-check, make lint, make typecheck and make test-unit pass; the integration suite passes if server behaviour changed.
  • Generated files are regenerated in this PR, not by hand: the SDK op tables, docs/reference/configuration.md and the docs/reference/ tables (python scripts/codegen/docs_reference.py), the reach manifest, schemas/schema.sql (make schema-dump) and the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.py).
  • A new migration is additive and numbered after the latest on main; no merged migration is edited.
  • A behaviour change to any file a plugin ships (hooks/, lib/, bin/, skills/, .mcp.json, the Codex plugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version.
  • The frontend builds (npm --prefix frontend run build) and its tests pass, if frontend/ changed.
  • Docs under docs/ describe the system as it now is, and this description names any operator steps and wire changes.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers; the history goes in this description (tests/unit/test_public_copy.py).
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.

🤖 Generated with Claude Code

zlareb1 and others added 8 commits November 6, 2026 23:31
…t root secret, and the dev stack keeps ClickHouse on loopback

require_safe_bind refused a non-loopback bind with auth off or the dev secret, but not with LOOM_MCP_AUTH_MODE=open (every MCP tool runs with no principal) or an HMAC root secret under 32 bytes (one token lets it be guessed offline); both are refused now unless LOOM_ALLOW_INSECURE=1. The dev compose published ClickHouse, with the dev password and access management, on LOOM_BIND_HOST; it publishes on 127.0.0.1 only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…asses both checks their inputs

The check is keyring.root_is_weak: an HMAC root under 32 bytes or an RSA root under 2048 bits, whose modulus the JWKS serves. Both flags are required arguments, and a lifespan test proves startup refuses. The setting comments, the security page and the MCP reference name the refusals.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ess, and the weak-key wording names the RFC minimums

scripts/serve.sh sets an unset LOOM_BIND_HOST to a non-loopback LOOM_LISTEN_HOST, so the startup checks cannot be skipped by setting only the listen address. root_is_weak reads the RSA size from the public half; the lifespan test fails fast if startup passes the check; RSA keys for the tests are made in the test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…auncher test covers IPv6 and loopback spellings

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…achable bind, and a weak gateway key is refused too

A gateway RSA key in LOOM_JWT_PUBLIC_KEYS_JSON under 2048 bits verifies tokens as the root does, so it is refused like a weak root key. The setting comments, .env.example and the docs name the refusals.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
… issuer keys included, and the refusal names each one

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…tched from a JWKS is dropped, and the key checks share one helper

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…amed for keys, and the comments say which keys are checked

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1 zlareb1 changed the title A server reachable by others refuses to start with MCP open or a short root secret, and the dev stack keeps ClickHouse on loopback A server reachable by others refuses MCP open mode and a signing or verifying key below the minimum size, and the dev ClickHouse stays on loopback Nov 7, 2026
zlareb1 and others added 3 commits November 7, 2026 07:47
…y checks, and the docs name the keys left unchecked

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…size constants

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1 zlareb1 changed the title A server reachable by others refuses MCP open mode and a signing or verifying key below the minimum size, and the dev ClickHouse stays on loopback A server whose bind address is not loopback refuses MCP open mode and a signing or verifying key below the minimum size, and the dev ClickHouse stays on loopback Nov 7, 2026
@zlareb1 zlareb1 changed the title A server whose bind address is not loopback refuses MCP open mode and a signing or verifying key below the minimum size, and the dev ClickHouse stays on loopback A server whose LOOM_BIND_HOST is not loopback refuses MCP open mode and a signing or verifying key below the minimum size, and the dev ClickHouse stays on loopback Nov 7, 2026
@zlareb1
zlareb1 merged commit 2527557 into main Nov 7, 2026
31 of 32 checks passed
@zlareb1
zlareb1 deleted the sec/unsafe-public-configs branch November 7, 2026 09:12
@zlareb1 zlareb1 mentioned this pull request Nov 12, 2026
3 tasks done
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