Repository navigation
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
Conversation
…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]>
…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]>
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]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changelog category (leave one):
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_HOSTis not a loopback address refuses to start withLOOM_MCP_AUTH_MODE=openor with aLOOM_JWT_SECRETbelow 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, unlessLOOM_ALLOW_INSECURE=1;loom doctorand/v1/healthreport both conditions.scripts/serve.sh, run from a checkout, treats a non-loopbackLOOM_LISTEN_HOSTas the bind address when the environment does not setLOOM_BIND_HOST(the image sets both). The development compose file and the per-worktree ClickHouse start script publish ClickHouse on127.0.0.1only.Why
require_safe_bindalready 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=openruns every MCP tool with no principal, so anyone who can reach the port reads and writes memory.The development compose file published ClickHouse's HTTP and native ports on
LOOM_BIND_HOST. A developer who set that to0.0.0.0to 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_bindtakes requiredmcp_openandweak_keysarguments, 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, unlessallow_insecureis 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.pypassesweak_keys()andsettings.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.pyand the health problems call the same function, and the refusal names each key.server/observability/problems.py:insecure_bind_mcp_openandinsecure_bind_weak_keysit beside the auth-off and dev-secret problems,errororwarnunderLOOM_ALLOW_INSECURE=1as those are, so a running server andloom doctorshow what the next start would refuse.scripts/serve.sh: the startup checks readLOOM_BIND_HOST, while uvicorn listens onLOOM_LISTEN_HOST; setting only the second to0.0.0.0on a launch from a checkout skipped every check (the image sets both). WhenLOOM_BIND_HOSTis 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 on127.0.0.1.dev/docker-compose.dev.yml: both ClickHouse port mappings bind127.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, thebind_hostandallow_insecuresetting 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, thejwt_secret,jwt_public_keys_json,jwt_end_user_issuers_jsonandmcp_auth_modecomments with their regenerated reference, schema and example,scripts/serve.sh,tests/unit/test_web_exposure.py,tests/unit/test_serve_launcher.pyandtests/unit/test_health_problems.py, plusserver/auth/machines.py(its inline-key check useskeyring.MIN_RSA_BITS) anddev/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, andLOOM_ALLOW_INSECURE=1keeps the old behaviour on purpose.The size rules are written out in
keyringrather than taken from PyJWT's own key-length checks, because the declared PyJWT floor predates those checks.Compatibility, rollout and rollback
LOOM_MCP_AUTH_MODE=openswitches 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.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 withLOOM_ALLOW_INSECURE=1;root_is_weakis 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 ownlifespanrefuses 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 (aswarnunder the override) and not on loopback; every ClickHouse port in the dev compose file and the start script binds127.0.0.1;pytest tests/unit/test_serve_launcher.py: a non-loopback listen address with no bind address reaches the server asLOOM_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 onmain.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 typecheckandmake test-unitpass; the integration suite passes if server behaviour changed.docs/reference/configuration.mdand thedocs/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).main; no merged migration is edited.hooks/,lib/,bin/,skills/,.mcp.json, the Codexplugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version.npm --prefix frontend run build) and its tests pass, iffrontend/changed.docs/describe the system as it now is, and this description names any operator steps and wire changes.tests/unit/test_public_copy.py).git commit -s), as CONTRIBUTING.md asks.🤖 Generated with Claude Code