Skip to content

security: rule-store fail-closed, cookie CSRF, log hygiene, protected workspace paths and model endpoint SSRF - #436

Merged
BaaRai merged 6 commits into
mainfrom
fix/security-hardening
Nov 21, 2026
Merged

BaaRai merged 6 commits into
mainfrom
fix/security-hardening

Conversation

@BaaRai

@BaaRai BaaRai commented Nov 21, 2026

Copy link
Copy Markdown
Owner

Security hardening across the interception rules, cookie sessions, log sink, workspace file manager and the model endpoint probe. No behavior change on the normal path; the operator-facing behavior is unchanged except where a request was unsafe before.

  • Rule-store fail-closed: when the interception rules cannot be read, tool calls are blocked instead of allowed, with an explicit message and one log line per outage. A rule whose pattern does not compile now blocks the calls it would target. An unreadable enabled-tools list still falls back to the defaults, as before.
  • Cookie-authenticated state changes: POST, PUT, PATCH and DELETE authenticated by the cookie alone must carry a same-origin signal (Origin or Sec-Fetch-Site consistent with the requested host), otherwise 403. Bearer tokens, GET and HEAD are not affected, and the setup and login routes stay reachable.
  • Log sink: the one-time setup token is no longer written to the log the API exposes, but to the server console. Credentials in proxy addresses are masked at write time, on stderr, and on read-back, including rows already persisted.
  • Workspace: the capture store paths (CA, index, blobs) are refused for read and write, and a delete that would remove one of them is refused.
  • Model endpoint ranges: shared (carrier-grade NAT) and benchmark ranges are refused for literal hosts, resolved names, redirects and at dial time. An upstream error body is no longer echoed; only the status is reported.
  • NAT64 and 6to4: for the well-known NAT64 prefix and 6to4, the embedded IPv4 address is judged exactly like a direct IPv4 address, so hosts behind a DNS64 resolver can still reach public IPv4 providers.

Tests cover each item, including the cross-origin request refusal, the log masking, the delete guard, the reserved ranges for literal and resolved hosts, and the embedded IPv4 cases. The full Go suite, gofmt, vet and the Linux, Windows and Darwin builds pass.

Limits stated in the commits: the path and rule filtering remains a confinement layer, not a sandbox; other IPv6 forms that embed an IPv4 (local-use NAT64, Teredo, IPv4-compatible, operator-specific prefixes) are not treated; a database outage blocks tool calls by design; behind a TLS proxy that rewrites the host, the cookie check depends on Sec-Fetch-Site.

A failed rule load left the enabled-tools set nil, so IsToolEnabled
answered false for every tool and the guard returned before any rule
ran; Match, MatchBuiltin and MatchPersistence answered "no match" on
the same error. A database outage therefore let every tool call run
unchecked.

Now, when the rules or the enabled-tools setting cannot be read,
IsToolEnabled answers true so the call reaches the rule path, and the
three matchers return a deny. The error is logged once per outage. A
failed read of the enabled-tools setting counts as a failed load
instead of silently selecting the defaults.

A deny or ask rule whose pattern does not compile is no longer skipped:
it matches every call as a deny until it is fixed or disabled. A broken
allow rule still allows nothing.
… origin

requireAuth accepted the artex_token cookie on its own for every method
and checked neither Origin nor Sec-Fetch-Site. The handlers decode a
JSON body whatever its Content-Type, so a page on another origin of the
same site (another port of the host, a sibling subdomain) could send a
text/plain POST that the browser sends without a preflight and with the
cookie: POST /api/mcp stored a server entry with a command.

A POST, PUT, PATCH or DELETE whose session comes from the cookie must
now be same-origin: Sec-Fetch-Site is same-origin, or Origin names the
scheme, host and port the request was sent to. Anything else, including
a request with neither header, is answered 403. Requests that carry a
bearer token are not checked, nor are GET and HEAD. The /api/auth/*
routes stay outside requireAuth, so setup and login are unchanged. The
web console sends the bearer token on every state-changing request.
…g sink

The log sink keeps every standard-logger line in a ring, persists it to
server_logs and serves it through /api/logs, /api/logs/history and
/api/logs/stream to any session. Two secrets went through it.

The one-time setup token was logged with log.Printf. It is now printed
on stderr directly, with the same wording, so `docker compose logs` and
the journal still show it; the sink gets a line that says where it was
printed.

A global proxy with user:password was logged in full when the browser
MCP was synced and when a stored value failed validation at startup,
and was written with its credentials into the --proxy-server argument
of the browser MCP row, which GET /api/mcp lists. The log lines and the
row now carry the proxy without its userinfo. A stored address that
does not parse is not written to the row at all.

As a second line of defence the sink masks the password of any
scheme://user:password@ it is given, in the ring and on stderr, and
rows persisted earlier are masked when they are read back.
…ce deletes

The workspace file manager refused traffic/_ca and traffic/_index by
path, but DELETE /api/workspace/delete on their parent, traffic,
removed the whole tree: the capture CA private key, the exchange index
and the blobs went with it. The blob store, traffic/_blobs, was not
denied at all and could be listed, read and downloaded.

traffic/_blobs joins the denied prefixes, and a delete is refused with
400 when a denied prefix lies beneath the entry it would remove. A
symlink to such a directory is still removed as a link.
…g upstream model errors

POST /api/llm/models treated every address outside RFC 1918, loopback,
link-local, multicast and the metadata addresses as public. It now
also refuses 100.64.0.0/10, 198.18.0.0/15, 192.0.0.0/24, 240.0.0.0/4,
NAT64 64:ff9b::/96 and 6to4 2002::/16, for literal hosts, resolved
names, redirects and at dial time. An endpoint listed in
ARTEX_LLM_PRIVATE_ENDPOINTS may still sit in 100.64.0.0/10 or
198.18.0.0/15, as it may in RFC 1918 space; the other ranges are never
allowed.

A non-200 answer was returned with the first 512 bytes of its body,
which let a caller read what any reachable host answers. The answer
now carries the status only.
POST /api/llm/models refused 64:ff9b::/96 and 2002::/16 as a whole. A
DNS64 resolver answers with a 64:ff9b::/96 address for every IPv4-only
name, so on a NAT64 network every public provider was refused and no
setting brought it back.

An address in 64:ff9b::/96 (the IPv4 address in the low 32 bits) or in
2002::/16 (the IPv4 address in bits 16 to 47) is now judged as the
IPv4 address it embeds, by the rule a bare IPv4 address gets: private,
loopback, link-local, metadata, reserved, carrier-grade NAT and
unspecified addresses stay refused, a public one is accepted. The rule
is the same for literal hosts, resolved names, redirects and at dial
time, and an endpoint listed in ARTEX_LLM_PRIVATE_ENDPOINTS gets behind
such an address what it gets as a bare IPv4 address.
@BaaRai
BaaRai merged commit a767315 into main Nov 21, 2026
6 checks passed
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