Skip to content

Security review: close all eighteen findings - #171

Merged
sykosyber merged 3 commits into
mainfrom
claude/security-review-fixes
Nov 4, 2026
Merged

sykosyber merged 3 commits into
mainfrom
claude/security-review-fixes

Conversation

@sykosyber

@sykosyber sykosyber commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Class: R
Agent-platform: claude
Admitted-by: none yet (draft; Mateo's review)

Before: six trust decisions in SyberWork could be steered from outside their boundary. A percent-escaped host passed the HTTPS guard and was dialed as loopback; a source URL could put the case input in its host; an action URL could store a secret in its query; an observer token could stall a case and read every case; syberwork backup wrote through a planted manifest.json link; an environment proxy received credentialed requests. Five smaller defects (int4 reservations on PostgreSQL, publish timeouts that leave children running, Compose on all interfaces with a literal password, an empty bind address, users.json read once) sat beside them.

After: each of those is refused or closed, and so are the review's seven remaining items (F6, F11, F14 to F18), with a regression test per finding in tests/test_security_review.py. The golden traces and the wire are unchanged.

Review ids are in brackets. The six high findings and the traced follow-ups were reproduced on main at f953b95 before they were changed (a throwaway script against the package; the int4 abort against a live local PostgreSQL 16). Of the remaining items, F6 was reproduced on main; F11 and F14 to F18 were confirmed by reading the code path the review names.

The six high findings

1. Host check and dial target disagree [F1]

  • Repro on main: guard_request("https://%31%32%37.0.0.1/x") returned (the name failed DNS, which the guard allowed) while urllib.request.Request(...).host == "127.0.0.1".
  • Fix (syberlabs/targets.py): trusted_origin accepts only an IP literal or plain ASCII LDH labels (IDNA as xn--), and requires the host urllib.request.Request would dial to equal the host it classified. guard_request now refuses a name it cannot resolve (or that resolves to nothing). It raises urllib.error.URLError, so every caller keeps its existing unreachable code (planner_unavailable, source_unavailable/destination_unreachable, status_unavailable, metric_unavailable, PollFailed). refresh_fact, reconcile, the planner, settle and outcome were adjusted so that code is what they report and no request is made.
  • Tests: HostCheckMatchesDialTarget (encoded loopback, encoded metadata IP, non-LDH and non-ASCII hosts refused without a lookup; DNS failure refused; an unresolvable source is source_unavailable with no request). tests/test_witness.py previously asserted that a DNS failure was allowed; it now asserts the refusal.

2. A source URL may put {key} in the host [F2]

  • Repro on main: install_source("s", {"url": "https://{key}.example.com/r", "auth_env": "T"}) was stored.
  • Fix (Work.install_source): exactly one {key}, in the path, no other braces, no query (the rule status_url already had). Finding 1's host rule refuses a braced host on its own too.
  • Tests: SourceKeyStaysInThePath.

3. A query string is stored as part of the action [F3]

  • Repro on main: registry("actions") returned https://orders.example/po?api_key=s3cret.
  • Fix (Work.install_action): the write URL takes no query and no template; status_url takes no query. SYBERWORK_PLANNER_URL with a query is now planner_unconfigured (tests/test_console.py updated). Publish and outcome URLs already refused one. trusted_origin itself still accepts a query, because publish and settle build GitHub API reads with ?per_page= at request time.
  • Tests: ActionUrlCarriesNoQuery.
  • Note: already-installed definitions are immutable and are not rewritten. A cell that installed one with a query keeps it until a new action name is published.

4. An observer token can stall a case and read all of them [F7, F8]

  • Repro on main: after a verified part_number from inventory, a supplier attestation of part_number (what POST /api/cases/{id}/facts does) made admission deny with untrusted_fact_source:part_number.
  • Fix, writes (Work.attest, used by the facts route): a manual, unverified attestation of a key the case's contract relies on (a required fact, an argument binding such as fact:quote.id, or a resolution's evidence) is refused with attestation_denied, unless a required fact names that same source and does not ask for verification. Keys the contract never reads are still recorded unverified, as before (the existing HostileSchema test keeps passing). Admission itself is unchanged.
  • Fix, reads (syberwork/server.py): /api/cases*, /api/contracts*, /api/certificates and /metrics/* need a role beyond observer (403 forbidden); GET /api/builder/* too (409 forbidden, the builder's existing status for its writes). /api/me, /api/console and the sources role listing are unchanged.
  • Tests: ObserverCannotStallOrRead.
  • Console effect: an observer-only principal (the supplier and inventory credentials init prints) can no longer open cases in the console; it still attests through POST /api/cases/{id}/facts given a case id, and still sees the Studio's source read roles. Four tests/test_console.py checks that let the supplier read cases now expect 403, and tests/console_browser.mjs attests as the supplier through the API (expecting quote to be refused and supplier_note and attest_receipt to be recorded) and has the operator inspect the result. That browser script was not run here (no Playwright browser in this container), so CI's browser job is its first run.
  • Behavior change to check: a metric token (SYBERWORK_METRIC_TOKEN, docs/DEPLOY.md) must now be a credential with a role other than observer, for example the operator credential init prints.

5. Backup export follows a symlink [F4]

  • Repro on main: with snap/manifest.json -> victim, export_cell overwrote victim with the manifest.
  • Fix (syberwork/backup.py): every snapshot file is written to a fresh temporary file in the same directory and moved over its name; a link or non-regular file at a name is refused with backup_refused. Snapshot files are now created mode 0600.
  • Tests: BackupDoesNotFollowLinks (POSIX; symlink creation needs a privilege on Windows).

6. A proxy in the environment is baked in at import [F5]

  • Repro on main: syberwork.core.HTTP carried a ProxyHandler built from http_proxy/https_proxy at import.
  • Fix: targets.credentialed_opener builds the opener with an empty ProxyHandler; syberwork.core, syberlabs.publish (also used by settle and outcome) and syberlabs.planner use it. The GitHits client is unchanged (it already bypasses proxies for loopback and talks only to its public API).
  • Tests: NoEnvironmentProxy (no proxy handler on any credentialed opener; a request made with http_proxy set never reaches the proxy).
  • Behavior change to check: a deployment that relied on an egress proxy for HTTPS actions or sources now needs a transparent one.

Traced follow-ups

  • amount_units int4 on PostgreSQL [F9]: migration 0006 alters economic_reservations.amount_units to BIGINT on PostgreSQL; SQLite's INTEGER is already 64-bit. Migrations may now be dialect-keyed. Tested live against PostgreSQL 16 (ReservationAmountsAre64Bit, 2^62+7 stored and summed); main aborted with NumericValueOutOfRange. tests/test_cell.py expects 0006.
  • Publish timeout kills one process [F10]: publish.Command._run now ends the command with checks._stop (the process group on POSIX, taskkill /T on Windows). Test: PublishTimeoutEndsTheTree (a grandchild's heartbeat stops).
  • Compose [F12]: port published as 127.0.0.1:8766:8766; no default database password (SYBERWORK_DB_PASSWORD is required, scripts/compose_cell.sh generates one for the CI boot). SYBERWORK_BIND: 0.0.0.0 stays inside the container so Docker can forward. docs/DEPLOY.md updated, including that an existing syberwork-db volume keeps the password it was created with.
  • Empty SYBERWORK_BIND [F12]: make_server refuses an empty host (main bound 0.0.0.0), and syberwork serve treats an empty variable as unset (127.0.0.1). Test: BindAndUsers.test_an_empty_host_never_binds.
  • users.json read once [F13]: serve passes a UserFile that re-reads the file when its mtime, size or inode changes; a missing or malformed file authenticates no file user (cell principals in the database still do). Test: BindAndUsers.test_users_json_changes_apply_without_a_restart.

The review's remaining items

  • [F6] Special-purpose addresses counted as public: _public_ip now refuses the IANA special-purpose ranges explicitly (192.0.0.0/24 including the PCP and TURN anycast addresses, 2001::/23, fec0::/10, 6to4, documentation and benchmarking ranges, and so on) and checks the IPv4 address inside a NAT64 address, instead of trusting is_global. Reproduced on main: 192.0.0.9, 2001:1::1 and fec0::1 were public. Test: SpecialPurposeAddressesAreNotPublic.
  • [F11] Check, then connect again: credentialed openers now use a pinned HTTPS connection. It resolves the host in connect, refuses the lot if any address is not public, and dials only those addresses; the name still drives SNI, certificate checks and Host. guard_request stays as the early check that gives callers their codes. Test: ConnectionIsPinnedToTheCheckedAddress (the dial goes to the accepted address; a name that rebinds to loopback after the guard is never dialed).
  • [F14] Version copied into If-Match: commit refuses a version_arg value that is not a safe header value (invalid_argument) before the claim, so no effect starts; _execute refuses any header with a line break, control character or edge whitespace (invalid_header) before a request. Test: HeaderValuesAreChecked.
  • [F15] A different result key counted as a change: when the result key differs from the trigger key, a decision completes only if the confirmation re-reads the trigger and finds the decision at the path that was empty when the task was requested (the shipped quote resolution), or if the result's own version moved from one read before the request. Otherwise it stays pending / source_decision_unverified. No schema change. Test: ResolutionNeedsAChangedVersion. Behavior change to check: a contract with a different result key and no such confirmation now needs the result observed before the task is requested.
  • [F16] Second worker labels unknown as settled: lease_obligation compare-and-swaps an expired lease to a new recovering state with its own lease, so one worker recovers it and a worker that dies while recovering hands it on; settle_interrupted returns the stored outcome (unknown stays unknown, the budget stays held). queue_depth counts recovering. Test: InterruptedEffectsKeepTheirOutcome.
  • [F17] Fact acceptance ignored verified and latest: a fact clause now reads the newest observation of its key and honors verified and source when the clause names them. Its key is also protected from manual attestation, like the other keys a contract reads. No shipped contract uses the clause. Test: FactAcceptanceReadsTheNewestObservation.
  • [F18] Console can be framed: the console document sends frame-ancestors 'none' and X-Frame-Options: DENY. Test: ConsoleCannotBeFramed.

Not fixed here, and why

  • GitPush.apply still runs git push under subprocess.run(timeout=...), which ends git but not a child such as ssh. Same class as the publish fix; left for a small follow-up.
  • README.md still describes the facts route as "record a manually asserted fact, tagged as unverified". It is a Class P surface, so it is not edited here; a line saying the route is refused for keys the contract reads from another source would make it exact.
  • Hash chain vs. a database owner who rewrites history: unchanged, as the README already states.

Evidence (claim ceiling: Implemented and Tested)

Run on this branch in a Linux container, CPython 3.13.18, with hypothesis and psycopg[binary] 3.3.7, and a local PostgreSQL 16 (SYBERWORK_POSTGRES_URL set):

  • PYTHONPATH=. python3 scripts/run_shards.py: 1253 tests, 4 failures, 5 expected failures
  • PYTHONPATH=. python3 -m conformance.run: matched 23 golden traces
  • The four failures are the same four that fail on main in this container: two Playwright browser tests (no browser installed) and two hidden-check staging tests. They are environmental and unrelated to this change.
  • Not run: the Compose cell boot (no Docker daemon here; docker compose config resolves with the variable set and refuses without it), Windows, CPython 3.11/3.12. CI covers those.

Coordination

No file overlap with #154, #164 or #163 (they touch syberlabs/cli.py and syberlabs/factory/; none touches jev_api). #170 does not touch these files either. Nothing here is deployed; merging and deploying are Mateo's call.


Generated by Claude Code

- targets: refuse a host that is not an IP literal or ASCII LDH, or that
  urllib would dial differently; refuse a name that does not resolve;
  credentialed openers ignore environment proxies
- core: source URLs keep {key} in the path; action URLs take no query;
  manual attestations of keys the contract reads from another source are
  refused (attestation_denied)
- server: observer-only roles cannot read cases, contracts, certificates
  or metrics; an empty bind host is refused; users.json is re-read on change
- backup: export writes through temp files and refuses links
- storage: migration 0006 widens amount_units to BIGINT on PostgreSQL
- publish: timeouts end the whole process tree
- compose: loopback publish, no default database password

Regression tests in tests/test_security_review.py.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…older

Windows refuses to delete an open SQLite file, and the cleanups ran after
the temporary directory had already been removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…8 edges

- targets: refuse IANA special-purpose ranges explicitly (F6); pin HTTPS
  connections to the addresses the check accepted, name kept for SNI and
  Host (F11); header_value_ok for header values
- core: refuse a version_arg that cannot be a header before the claim, and
  any unsafe header before a request (F14); a different result key is not a
  change unless the confirmation re-reads the trigger or the result's
  version moved (F15); compare-and-swap an expired lease to 'recovering'
  and keep a stored outcome when settling it (F16); acceptance fact keys
  are protected from manual attestation
- evidence: a fact clause reads the newest observation and honors verified
  and source (F17)
- server: frame-ancestors 'none' and X-Frame-Options on the console (F18);
  observer-only credentials read no builder view (F8)
- planner: a planner URL takes no query string (F3)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sykosyber sykosyber changed the title Security review: close six high findings and five follow-ups Security review: close all eighteen findings Nov 3, 2026
@sykosyber
sykosyber marked this pull request as ready for review November 4, 2026 00:21
@sykosyber
sykosyber merged commit 210cc72 into main Nov 4, 2026
25 checks passed
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-04T00:22:34.702744Z 5c287e5 Draft marked ready
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

sykosyber pushed a commit that referenced this pull request Nov 4, 2026
…observer-only credentials off /api/certificates

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sykosyber pushed a commit that referenced this pull request Nov 4, 2026
…e, and the four probes #171 fixed are regression tests now

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

2 participants