Repository navigation
A namespace's classify endpoint off the gateway is reached only over https at a public address it vetted - #318
Merged
Merged
Conversation
…https at a public address it vetted memory.set(classify=true) posted the value to whatever URL a namespace admin stored, including loopback, private and link-local addresses, and returned the failure's text in degraded. Off the gateway the endpoint must now be https (namespace.register refuses another scheme), the call goes to the public address the host was vetted to with no redirect and no gateway identity headers, and degraded names only the failure's kind. LOOM_MEMORY_CLASSIFY_PRIVATE_HOSTS names the operator's exceptions. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…endpoint is refused, and test a name that resolves inward Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
… most 64 KiB of it Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…d parse its URL as the call does httpx decodes a compressed body in one step before any length check, so an answer is read raw with Accept-Encoding: identity and a compressed one is refused unread. classify_refusal reads the host with urlsplit, as pinned_target does, so registration and the call agree on which host a URL names. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…way is not required, and registration stores and checks what the call reads Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…t as its IDNA form, and log a refused host once per namespace - classify_refusal refuses a URL carrying a user name or password off the gateway: the call drops it and namespace.get would hand it back. - A URL at a listed gateway host is held to https at the default port also while the gateway is not required; a test pins it and the docs say so. - webhooks.pinned_target sends the IDNA form of the host as Host and SNI: httpx encodes header values as ASCII, so a Unicode name failed every call. - classify takes the org and namespace, and the refused-host warning is logged once per (org, namespace). - Tests that drove a classifier off the gateway's hosts through the model client now list that host as a gateway host. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…ateway path, and spell hosts by UTS 46 - classify_refusal refuses a URL with a control, whitespace or non-printable character, one httpx reads no host in, and one whose urlsplit host, spelled by catalog.ascii_host, is not the host httpx reads: a tab, a control character, an over-long URL or a fullwidth name read as off the gateway to the check and reached the gateway's host at the call. - A URL carrying a user name or password is refused on every path. - catalog.ascii_host spells a host as the lists do (UTS 46 IDNA via the idna package, lower case, no trailing dot); the gateway and both private host lists spell their entries with it, and pinned_target resolves, matches and sends (Host, SNI) that ASCII name. - _post_vetted passes both schemes: classify_refusal already refused http for an unlisted host. - idna is a declared dependency. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
… bare name or address, and keep a null answer apart from a refused host - _post_vetted raises a private _HostRefused for a refused host, so a classifier answering JSON null is noted as a malformed payload. - _one_host returns the parsed parts with the one host, and also refuses a host that is not a bare name or address literal (a zone id, a percent-encoded name); classify_refusal reads the gateway rule from that host without parsing again. - catalog.host_list_refusal checks LOOM_INFERENCE_GATEWAY_HOSTS and both private host lists at load: an entry with a port, brackets, a scheme, a path, a wildcard, a zone or a name IDNA cannot encode is refused, never dropped. The private-host settings say "hostnames or IP literals, no port"; the reference, schema and example are regenerated. - security.md states the refusals on every path in their own sentence. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
A Compose service name carries one, and httpx and urlsplit read it alike, so refusing it broke private classifier and webhook hosts for no gain. `%`, a port, brackets, a wildcard, a zone, a scheme and a path stay refused. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
zlareb1
force-pushed
the
sec/classify-endpoint-public-only
branch
from
November 7, 2026 06:44
0a8be9b to
a961356
Compare
…rule in the security page - host_list_refusal's message also names a zone, percent-encoding and a name IDNA cannot encode. - security.md says namespace.register refuses a host that is not a bare name or address literal (a zone id, a percent-encoded name). Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…y_endpoint may be where it is declared urlsplit reads an explicit :443 as 443 while httpx, which sends the call, reads it as the default port, so https://gateway.example:443/c was refused on the gateway path. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…he gateway path once, and describe both paths - Off-gateway lookups run on a four-thread pool of the classifier's (hosts.vet_host and webhooks.pinned_target take the pool): a burst at a name that never answers fills it, never asyncio's shared one. - _gateway_branch decides from the normalised host whether a classifier is a model call; classify_refusal and via_gateway both read it. - The classify module, write path, private-hosts setting and the namespaces page describe the gateway and the vetted paths; the field's comment feeds the regenerated namespace operation page. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…ssifier from one decision - A namespace holds at most two of the classifier's four lookup threads, pending or running, until each lookup's thread is done; a call past that is refused at once and noted as endpoint busy, so one namespace whose names never answer cannot take every thread from the others. - classify_route returns (refusal, via gateway) from the one normalised host; classify reads both from that call and classify_refusal is its first half. - vet_host runs the lookup with run_in_executor on the given pool, and its docstring names the classifier among the gate's users. - security.md states the cross-tenant bound; the namespaces page says a gateway refusal of the call's identity fails the write. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…kup holds a thread past its call A per-namespace share of a lookup pool is beaten by a principal who creates more namespaces. The lookup now runs on the event loop with dnspython's async resolver (A and AAAA, from the system's resolv.conf), so the call's deadline or a cancelled write ends it and nothing of it outlives the call. The results are vetted as vet_host vets any other; a host LOOM_MEMORY_CLASSIFY_PRIVATE_HOSTS lists is still looked up by getaddrinfo, /etc/hosts included. The pool, the per-namespace counter and the busy refusal are gone, and dnspython is a declared dependency. The namespaces page, the classify_endpoint field comment and the generated namespace operation page say a URL at a listed gateway host must be https at the default port even while the gateway is not required. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…v.conf when it changes - vet_host looks every host not on an operator's allowlist up with the in-loop resolver, so webhooks, tracker sources and the egress proxy no longer leave a lookup thread past their deadline either; the in_loop flag is gone. An allowlisted host keeps getaddrinfo. - The in-loop resolver is rebuilt when /etc/resolv.conf's modification time changes, and fails closed without the file; the unreachable CancelledError branch is dropped. - dnspython is locked at 2.8.0 (ISC). - Tests: a real dnspython resolver against a local UDP nameserver (an A answer with no AAAA, an NXDOMAIN, a name never answered cut by the deadline with no thread, and the resolver's own shorter lifetime); the fake resolver answers a missing record kind with an empty answer; resolv.conf is read again when it changes. The unit network guard also refuses a datagram to a remote address and a dnspython lookup at the system's nameservers; tests that stub a lookup stub both through tests/unit/_hosts.py. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…d close the unit guard's localhost gap - The fake resolver answers one name's A and times out on its AAAA: the A address comes back and vet_host accepts it. - The unit network guard refuses every dnspython lookup at the system's nameserver, localhost included (dnspython reads no /etc/hosts), and a test shows it refuses and records one. - The code-index operations page says how the egress proxy resolves a name; a webhooks docstring is reflowed and two blank lines left by an edit go. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…'s setup - The never-answering lookup test asserts the write is noted TimeoutError. - The guard's comment is reflowed, the real functions are captured together, and the socket and dnspython patches sit together. - vet_host's signature is back on one line. 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):
Off the inference gateway, a namespace's
classify_endpointmust be https with no user name or password, andmemory.set(classify=true)posts only to the public address its host resolves to, with no redirect and no gateway identity headers; a failed call is reported indegradedby its kind alone.LOOM_MEMORY_CLASSIFY_PRIVATE_HOSTSnames the hosts an operator allows on a private address, over http too.Why
namespace.registermakes the creator of a new namespace its admin, and an admin sets the namespace'sclassify_endpoint. While the gateway is not required (the default), the URL was not checked, andmemory.setwithclassify=trueposted the memory's value there with the model client, whose hook only enforces the gateway's host list. So any principal of an org could make the server send a JSON POST to a loopback, private or link-local address and port of its choice (the metadata endpoint, ClickHouse's HTTP port, the extractor, other services in the cluster), and the exception text returned in the write'sdegradedfield told a refused connection, a timeout, a non-JSON answer and an HTTP status apart: a port scanner of the server's network. The reranker was already closed this way (a URL is refused; only operator-configured names pass).Design
LOOM_INFERENCE_GATEWAY_HOSTS(classify_route). Such a URL must be https at the default port of a listed host, also while the gateway is not required: another port of the gateway's host is inward reach, and listing that host inLOOM_MEMORY_CLASSIFY_PRIVATE_HOSTSdoes not open it. Any other endpoint is off the gateway.classify_refusal, whichnamespace.registerand the call both run, reads one host for every decision. httpx (the gateway check and the model call) andurlsplit(the off-gateway call) parse a URL differently:urlsplitdrops a tab, httpx refuses a control character or a URL over its length limit and reads"", and Python's IDNA 2003 codec maps a fullwidth name to ASCII. Each of these read as off the gateway to the check and reached the gateway's host at the call. So any URL with a control, whitespace or non-printable character is refused, and so is one where httpx reads no host or theurlsplithost, normalised bycatalog.ascii_host(lower case, no trailing dot, a non-ASCII name as its UTS 46 IDNA form from theidnapackage), is not the host httpx reads, or that host is not a bare name or address literal (catalog.is_bare_host: a zone id such as[fe80::1%25eth0]or a percent-encoded name is refused)._one_hostreturns the parsed parts with that host, so one host is read for every decision, and each later parse reads the same string the same way. That one host is compared against the gateway hosts and the private-host allowlist, each entry normalised the same way.namespace.getwould hand the credential back). Off the gateway the scheme must be https unless the host is listed inLOOM_MEMORY_CLASSIFY_PRIVATE_HOSTS(then plain http is allowed too). Registration stores the endpoint stripped, as the call reads it.classifyoff the gateway calls_post_vetted:webhooks.pinned_targetresolves the host, refuses any loopback, private, link-local, multicast or other non-public address (unwrapping IPv4-mapped and NAT64 forms), and returns the vetted address; the POST goes to that address with the name asHostand as the TLS server name, on its own client that follows no redirect. A rebinding name cannot move the connection after the check. The gateway's identity headers are sent only on the gateway path. An operator-listed private host is reached by its name.asyncio.timeout(LOOM_MEMORY_CLASSIFY_TIMEOUT_S), as the webhook sender's do, and the answer is streamed and read to at most 64 KiB (_MAX_ANSWER_BYTES; the answer is a few dozen bytes), so neither a name whose server never answers, nor an answer that trickles or streams gigabytes, holds the write or the server's memory.hosts.vet_hostnow looks every host a caller names up on the event loop with dnspython's async resolver (hosts._resolve_in_loop: A and AAAA from the system'sresolv.conf), not bygetaddrinfoin a thread. The caller's deadline, or a cancelled request, ends the lookup, and nothing of it outlives the call. This covers the classifier and every other user of the gate: memory and task webhooks, tracker sources and the repository-job egress proxy. The answers are vetted as before. A host an operator allowlisted (allow_private:LOOM_MEMORY_CLASSIFY_PRIVATE_HOSTS,LOOM_MEMORY_WEBHOOK_PRIVATE_HOSTS, the tracker's private-host switch) is still looked up bygetaddrinfo./etc/hostsand nsswitch are not read; no search domains are applied, so a single-label name that resolved through a search domain before now does not resolve and is refused; and A records come before AAAA, wheregetaddrinfoordered them by RFC 6724. An operator who needs any of these for a classifier, webhook or tracker host lists it in that caller's private-host setting; the repository-job egress proxy has no such setting, so a git remote or submodule needs its full DNS name./etc/resolv.confand built again when the file's modification time changes, so a container whose DNS server moves keeps resolving without a restart. Without the file, the lookup fails closed.classify_routereturns (refusal, via gateway),classify()reads both from that one call, andclassify_refusalis its first half.webhooks.pinned_targetnormalises the host withascii_host(UTS 46, sofaß.exampleisxn--fa-hia.example, not IDNA 2003'sfass.example), resolves that ASCII name, matches it against the allowlist, and sends it asHostand the TLS server name: httpx encodes header values as ASCII, so a Unicode name failed every call. This fixes the webhook senders too, and their allowlist (LOOM_MEMORY_WEBHOOK_PRIVATE_HOSTS) matches a name in either spelling._post_vettedpasses both schemes, sinceclassify_refusalalready refused http for an unlisted host.idnais now a declared dependency (it came only through httpx), anddnspython(ISC licence, pure Python, locked at 2.8.0) a new one for the in-loop lookup.LOOM_MEMORY_CLASSIFY_PRIVATE_HOSTS,LOOM_MEMORY_WEBHOOK_PRIVATE_HOSTSandLOOM_INFERENCE_GATEWAY_HOSTSare checked at load by one rule (catalog.host_list_refusal): each entry, spelled byascii_host, must be a bare hostname or IP literal, so an entry with a port, brackets, a scheme, a path, a wildcard, a zone or a name IDNA cannot encode stops the server at start instead of matching nothing. A_in a label is accepted (a Compose service name has one, and both parsers read it alike), so the gateway list now accepts_too, which it refused before.:443counts as the default port:urlsplitreads it as 443 and httpx, which sends the call, as no port._NotCalledin_post_vetted, apart from the answer, so a classifier that answers JSONnullis notedmalformed payload, not taken for a refusal.degradednote names the exception's type only, and the warning for a refused host is logged once per (org, namespace) (_REFUSED_LOGGED), asclassifynow takes the org and namespace.webhooks._tlsis renamedtls, as two modules use it.Alternative considered: accept only names from an operator map, as the reranker does. That breaks every namespace that stores a classifier URL today; a public https classifier is a legitimate use, and the vetted, pinned connection removes the inward reach.
Scope and risk
server/memory/domain/classify_endpoints.py,server/memory/app/classify.py,server/core/webhooks.py(the rename and the IDNA host),server/memory/app/write.py(passes the org and namespace),server/settings/catalog.py(the newLOOM_MEMORY_CLASSIFY_PRIVATE_HOSTSsetting, the load-time check of the three host-list settings, andascii_host, which those lists now spell their entries with) with the regenerated reference, schema and example,pyproject.tomlanduv.lock(idnaanddnspython),docs/architecture/security.md,docs/operations/code-index-operations.md(how the egress proxy resolves a name) anddocs/features/namespaces-and-sharing.md, the unit tests and one integration test's sample URL,server/core/hosts.py(the in-loop lookup),tests/unit/conftest.py(the network guard also refuses a datagram to a remote address and a dnspython lookup at the system's nameservers),tests/unit/_hosts.py(one helper that answers both lookups),server/identity/api/models.py(the field's comment, with the regenerateddocs/reference/operations/namespace.md). While the gateway is required, the gateway path gains only the refusals of a URL whose parsers disagree or that carries a user name or password.Compatibility, rollout and rollback
namespace.registerrefuses a non-httpsclassify_endpointwith 422 while the gateway is not required (unless its host is listed inLOOM_MEMORY_CLASSIFY_PRIVATE_HOSTS). It also refuses, on the gateway path too, a URL carrying a user name or password or a control, whitespace or non-printable character, or one whose host httpx andurlsplitread apart (an over-long URL, a fullwidth host) or that is not a bare name or address literal (a zone id, a percent-encoded name); and, while the gateway is not required butLOOM_INFERENCE_GATEWAY_HOSTSis set, a URL at a listed gateway host that is not https at the default port (before,http://gateway.example:8080/cwas accepted and called; listing the host as private does not change that). A stored http endpoint on a host not listed is no longer called (the config read drops it and logs once; the write keeps the caller's type), and an https endpoint whose host resolves inward is not posted to (degradednotesendpoint host refused).degradedfor a failed classifier carries the exception's type, not its text.LOOM_MEMORY_CLASSIFY_PRIVATE_HOSTS,LOOM_MEMORY_WEBHOOK_PRIVATE_HOSTSandLOOM_INFERENCE_GATEWAY_HOSTSnow refuse at load an entry that is not a bare hostname or IP literal (before, the private lists took any string, and a gateway entry IDNA could not encode was dropped).LOOM_INFERENCE_GATEWAY_HOSTSnow accepts an entry with_.resolv.confalone: not/etc/hostsor nsswitch, with no search domains (a single-label name is now refused), and A before AAAA.LOOM_MEMORY_CLASSIFY_PRIVATE_HOSTS. A webhook receiver or tracker host that only/etc/hostsor a search domain names is either listed in its private-host setting or given its full DNS name; a git remote or submodule the egress proxy fetches is given its full DNS name.Tests
pytest tests/unit/test_classify_endpoint_off_gateway.py tests/unit/test_call_site_knobs.py tests/unit/test_llm_gateway.py: off the gateway an http, ftp or loopback-port URL is refused at registration and https is accepted; an operator-listed private host may use http;https://127.0.0.1:8123/, the metadata address, a private address,[::1]and[::ffff:127.0.0.1]are never posted to; a call goes to the vetted address withHostand SNI set, no redirect followed and no identity headers, and a failure is noted asConnectionRefusedErrorwithout its text; a public-looking name that resolves to a private address is never posted to; a listed private host is reached by name over http with no Host or SNI override; a lookup that never answers ends at the classifier's deadline with nothing of it left running, and so does an answer that trickles (both notedTimeoutError), and an answer over 64 KiB is not read whole; registration's refusal of plain http names no gateway; a URL with no host or an invalid port is refused at registration, and a padded one is stored stripped; a classifier at a listed gateway host goes through the model client though the gateway is not required, andhttp://gateway.example:8080/cand another https port of that host are refused there even with the host listed as private; a URL with a user name, a password or both is refused, on the gateway path too; a tab in the host, a control character in the fragment, a 70,000-character fragment and a fullwidth spelling of a listed gateway host are each refused at registration and never posted; a private host listed asxn--bcher-kva.localmatchesbücher.localand the reverse; a zone id, a percent-encoded host and a fullwidth host at the default port are refused and never posted; a JSONnullanswer is notedmalformed payload; each of the three host-list settings refuses at load an entry with a port, brackets, a wildcard, a zone, a path or a name IDNA cannot encode, and the private lists load names, IDNs, a name with_and address literals in their ASCII spelling;test_a_private_host_with_an_underscore_is_accepted:http://my_classifier:8080/clisted as private is accepted and posted to by name;https://gateway.example:443/cis accepted at a listed gateway host, required or not, andclassify()sends it to the model client; two namespaces bursting at names that never answer all end at the deadline with no lookup left running and none in a thread, while a third namespace's classifier answers; a write cancelled from outside mid-lookup leaves no lookup running, and the namespace's next classification runs; against a real dnspython resolver and a nameserver on a local UDP socket: an A answer with no AAAA (NOERROR, no data) resolves and an NXDOMAIN is refused; a name that is never answered ends at the classifier's deadline with no thread used, and dnspython's own lifetime, when shorter, ends it first (endpoint host refused); the resolver is read again whenresolv.confchanges and fails closed without it; the fake resolver answers a missing record kind with an empty answer, as dnspython does; the in-loop lookup reads A and AAAA, keeps one kind's answer when the other's query times out, and fails only when both do; the unit network guard refuses and records a dnspython lookup at the system's nameserver,localhostincluded; a listed private host is looked up by the system resolver; an IDN host is posted with its IDNA form asHost; a refused host is logged once per namespace; a 302 is not followed through real httpx handling.tests/unit/test_task_webhook_deliver.py:pinned_targetreturns the UTS 46 IDNA form of a Unicode host asHostand SNI (faß.exampleasxn--fa-hia.example), refuses a name IDNA cannot encode, and resolves and matches the allowlist by the ASCII name in either spelling.test_model_call_customer.py,test_model_call_refusals.pyandtest_degradations.pydrove a classifier at a host off the gateway's list through the model client; they now list that host as a gateway host (or drop the off-list call, which the off-gateway file covers), and pass.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 traced who can set the endpoint and what the call reached, and checked the pinned connection against the webhook sender it reuses.
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