Program thread for the 2026-11-16 external security review. Findings, Fable 5.2 cross-check and the plan below. Paul's rulings 2026-11-16: carlos-app@ unit backing is operator-trusted only; CSRF keeps accepting the old raw token for one release; audits next (gVisor root unit, managed enrolment, /auth/cli device login, mailer).
Branches: sec-edge-redirect-linklocal, sec-console-csrf-derive, sec-gate-shadow-guard, sec-unit-app-demobuild.
October hunt re-baseline (2026-11-16)
The 2026-10-25 hunt's verifier tests (TestHunt_*), copied onto main @ 3793aa49 and run: most still FAIL, i.e. the findings are still open on main. Only the account-root batch (5698a8f) landed; fix/hunt-release-chain-integrity is held. Still failing: H3-M1/H6-M2 (critical/high), H3-M2, H3-M5, H3-M8, H3-M6, H3-M7, H3-M9, H4-M1..M12 (H4-M1..M4 high), H5-M1, H5-M7, H5-M12 (high), H6-M3, H6-M4, H6-M11, H6-M12, H2-M1, H2-M5, H2-M6. Compile drift (not run): H3-M3 (appconfig), H2-M4 (edge). Raw output: ~/.cache/sec-review-20261116/hunt-rebaseline.txt on docs-t1. Awaiting Paul's priority call.
Security review 2026-11-16 fixes: implementation plan
> For agentic workers: REQUIRED SUB-SKILL: superpowers:subagent-driven-development. Steps use - [ ].
Goal: close the actionable findings of the 2026-11-16 external review of carlos/platform @ 3793aa49, as amended by the Fable 5.2 cross-check and Paul's rulings.
Architecture: four independent branches off origin/main, each landed through amadan branch merge -squash. No new storage, no new keys, no new config switches.
Tech stack: Go 1.26.10 (source .amadan/go-toolchain.sh), systemd unit files, golang.org/x/tools/go/packages (already in go.mod) for one guard test.
Spec: ~/.cache/sec-review-20261116/carlos-platform-security-review.md (findings), carlos-security-fixes-for-agents.md (the reviewer's brief; this plan amends it), fable-report.md (cross-check; the amendments come from it).
Global constraints
- Every change lands via a described amadan branch, squash-merged with
-expect <full sha> -message (subject < 80 chars). - Local verification is targeted tests only (
go test ./internal/<pkg> -run '<names>' -count=1); never make test, make ci or go test ./... on docs-t1. Hosted CI runs the rest. Socket-binding packages (edge, host, activator, console) run with TMPDIR=/tmp/g and the sandbox off. - Leave GOCACHE at its default. Never
git worktree prune; never create or remove worktrees (the controller owns them). - Branches touching the root binary (edge, demobuild, host units) need a census card (
make census-card, CLAIMS file, make census-propose NAME=<branch> CLAIMS=<file>) and an Astra census verdict recorded on #280. - Do not move the Go toolchain off 1.26.10.
- No user-visible copy changes beyond the existing "Cross-site request blocked." refusal; if one becomes necessary, stop and report (copy review).
- Every behaviour fix gets a regression test that fails on origin/main and passes after.
Paul's rulings (2026-11-16)
carlos-app@ (Backing=unit) is operator-trusted only. Document it; add only controls that cannot break a tenant.- CSRF: accept the old raw-session token for one release beside the derived one, then remove it in a follow-up.
- Audit next (separate work): gVisor root unit, managed enrolment,
/auth/cli/* device login, mailer. Release-chain verification was hunted on 2026-10-25 (H3/H6) and its fix branch is held; see the program discussion.
Review focus
- A rootless or absolute-form request-target on edge
:80 (x:@evil/p, http://other/p, *): Location must be https://<host>/ or https://<host><path>, never another authority. - A name or literal resolving to link-local or AWS IMDS (
169.254.169.254, ::ffff:169.254.169.254, fe80::1, fd00:ec2::254) as an edge upstream: never connected, on every edge upstream dialer including the prober. - A form rendered before the deploy (raw token) and after (derived): both accepted during the transition release; any other value refused 403.
- A step-up re-auth that replays a held POST: must carry the derived token and succeed.
- A future console JSON view embedding
provision.Record / registry.Route: must fail the guard test unless gate is shadowed.
---
Branch A: sec-edge-redirect-linklocal (census)
Task A1: edge :80 redirect keeps its own authority
Files: Modify internal/edge/edge.go (httpFallbackHandler, the http.Redirect(... "https://"+host+r.URL.RequestURI() ...) line). Test: internal/edge/http_fallback_redirect_test.go (new).
- [ ] Step 1: write
TestHTTPFallbackRedirectRootlessTarget: build the request with http.ReadRequest(bufio.NewReader(strings.NewReader("GET x:@evil.example/p HTTP/1.1\r\nHost: <a routable test host>\r\n\r\n"))), serve it through (*Edge).httpFallbackHandler() built the way the existing fallback tests build it (find them with grep -rn httpFallbackHandler internal/edge/*_test.go), assert status 302 and Location == "https://<host>/". Same test, subcases: absolute-form GET http://evil.example/p → Location host is <host>; ordinary GET /a/b?c=1 → https://<host>/a/b?c=1 (unchanged). - [ ] Step 2: run, expect the rootless subcase to FAIL with
https://<host>@evil.example/p. - [ ] Step 3: inline the console's rule (
internal/console/server.go redirectTarget): uri := r.URL.RequestURI(); if !strings.HasPrefix(uri, "/") { uri = "/" }. The console imports the edge, so do not import console; add a one-line comment naming console.redirectTarget as the twin. - [ ] Step 4: run, PASS. Step 5: commit
edge: keep the :80 redirect on its own host for a rootless target.
Task A2: edge never dials link-local or IMDS upstreams
Files: Create internal/edge/upstreamdial.go; modify internal/edge/edge.go (tcpProxy, the multi-upstream DialContext near the "dialer works in passes (D10b)" comment) and internal/edge/prober.go (the probe http.Transport). Test: internal/edge/upstreamdial_test.go.
Interfaces — produces:
func refuseLinkLocalUpstream(network, address string, _ syscall.RawConn) error — a net.Dialer.Control hook: parses the host of address (already resolved by the dialer), unmaps IPv4-in-IPv6, and returns errLinkLocalUpstream for 169.254.0.0/16, fe80::/10 and fd00:ec2::254/128; nil otherwise.var errLinkLocalUpstream = errors.New("edge: refusing a link-local upstream address")func upstreamDialer() *net.Dialer — &net.Dialer{Control: refuseLinkLocalUpstream}; used wherever these three sites fall back to the default dialer today (hold.dialer == nil, i.e. production).
- [ ] Step 1: tests:
TestRefuseLinkLocalUpstream table over 169.254.169.254:80, [::ffff:169.254.169.254]:80, [fe80::1]:80, [fd00:ec2::254]:80 (refused) and 127.0.0.1:80, 10.0.0.5:80, [::1]:80 (allowed). TestTCPProxyRefusesNameResolvingToIMDS: a tcpProxy for imds.test:80 whose resolution yields 169.254.169.254 (use a net.Resolver with a fake Dial serving a canned DNS answer, or upstreamDialer() with Resolver overridden — pick whichever the package's tests already use; there must be no real connect attempt) returns 502 and the error wraps errLinkLocalUpstream. - [ ] Step 2: run, expect FAIL (undefined, then connection attempted).
- [ ] Step 3: implement; at each of the three sites replace the nil/default dialer with
upstreamDialer().DialContext. Leave test-injected hold.dialer untouched. Do not touch unix-socket dials, mesh hops or tunnels. - [ ] Step 4: run
go test ./internal/edge -run 'TestRefuseLinkLocalUpstream|TestTCPProxy|TestHTTPFallback|Prober|Hold' -count=1 with TMPDIR=/tmp/g; PASS. - [ ] Step 5: commit
edge: refuse link-local and IMDS addresses at upstream dial time.
Task A3: census card for branch A
- [ ]
make census-card; CLAIMS lines for httpFallbackHandler, tcpProxy, the multi-upstream proxy builder, the prober transport builder and the new file's functions ("redirect target confined to a rooted path; no read added" / "upstream dialer gains a Control hook refusing link-local destinations; no read added"); make census-propose NAME=sec-edge-redirect-linklocal CLAIMS=<file>; commit the overlay + card. Astra census review per AGENTS.md; record on #280.
Branch B: sec-console-csrf-derive (console only, no census)
Task B1: derived CSRF token, every emitter and every checker
Files: Create internal/console/csrf.go, internal/console/csrf_test.go, internal/console/csrf_scan_test.go. Modify every emitter and checker listed below.
Interfaces — produces:
func csrfToken(rawSession string) string = hashToken("carlos-console-csrf-v1:" + rawSession). Must never equal hashToken(rawSession) (the DB key).func csrfOK(got, rawSession string) bool — constant-time compare of got against csrfToken(rawSession); ALSO accepts got == rawSession (constant-time) during the transition release. Mark the raw branch with // TRANSITION(csrf-v1): remove one release after <tag> so the follow-up is a grep.func csrfFormOK(r *http.Request, rawSession string) bool — exactly one csrf value in r.PostForm (after ParseForm) and csrfOK on it. Handlers that today use r.FormValue("csrf") switch to this.
Emitters (put csrfToken(raw) where raw is emitted today): page.CSRF in basePage (server.go ~2966) and every other CSRF: raw / CSRF: session fill (server.go ~3295, ~4239; authcli.go ~1117, ~1234, ~1379; accountindex.go ~22; opshell.go ~86; demo_claim_page.go ~166); every {"csrf", raw} confirm field (confirm.go ~118, ~180, ~201, ~232; appsettings.go ~1012, ~1793; accountlinks.go ~366; server.go ~3630; billingchange.go ~206; browserretry.go ~94; browserrestart.go ~105); the step-up replay form.Set("csrf", raw) (stepup.go ~484). Line numbers are from 3793aa49; find them by grep. Checkers: every ConstantTimeCompare([]byte(r.FormValue("csrf")), []byte(raw)) (~66 sites), envform.go (r.PostForm["csrf"]), storepage.go (storeFormCSRF), billingchange.go (billingCSRFRefused, two sites), demo_claim_page.go ~333 and demo_claim_kept.go ~50 (the session compare only; leave demoClaimNonce alone), pipelinepage.go (compares against p.CSRF and then uses p.CSRF as raw at ~280: after the change p.CSRF is the derived token, so take raw from s.session(r) instead — check what raw is used for below that line and keep that behaviour). Leave alone: LinkNonce (email-link login CSRF), demoClaimNonce, validDemoReportToken, API bearer routes.
- [ ] Step 1:
csrf_test.go: TestCSRFTokenIsNotTheSession (derived != raw, != hashToken(raw), stable, 64 hex); TestCSRFOKAcceptsDerivedAndTransitionRaw; TestCSRFOKRefusesOther (empty, other session's derived, truncated). - [ ] Step 2: an end-to-end test in the style of the existing signed-in page tests (find a helper that signs in and fetches
/ or /accounts): TestSignedInPageDoesNotContainSessionToken — body must not contain the raw cookie value; must contain csrfToken(raw). Plus TestStepUpReplayCarriesDerivedCSRF driving one step-up-protected POST through re-auth (find the existing step-up test and extend it). - [ ] Step 3:
csrf_scan_test.go TestNoRawSessionAsCSRF: AST over non-test internal/console/*.go; fail on (a) ConstantTimeCompare whose either argument mentions FormValue("csrf"), PostForm["csrf"], PostForm.Get("csrf") or PostFormValue("csrf") outside csrf.go; (b) a composite literal {"csrf", X} or form.Set("csrf", X) where X is not a call to csrfToken; (c) a CSRF: keyed field whose value is not a csrfToken(...) call. Negative control: a small in-test source string with each bad shape must be flagged. - [ ] Step 4: run the three new tests: FAIL. Implement. Then update test fixtures that post
csrf=<raw>: they still pass during transition; do NOT bulk-rewrite the ~1,200 fixture lines now. - [ ] Step 5:
go test ./internal/console -run 'CSRF|Csrf|StepUp|SignedIn|EnvForm|Store|Billing|Pipeline|DemoClaim|Confirm' -count=1 with TMPDIR=/tmp/g; PASS. Commit console: derive the CSRF token instead of echoing the session token. - [ ] Step 6: open a follow-up discussion "Remove the raw-session CSRF transition" naming the release, and link it in the branch description.
Branch C: sec-gate-shadow-guard (console test + CI script comment, no census)
Task C1: guard that no console JSON view leaks the gate hash
Files: Create internal/console/gate_shadow_guard_test.go.
- [ ] Step 1:
TestConsoleJSONNeverCarriesGateHash: load carlos.dev/...internal/console (use the module path from go.mod) with golang.org/x/tools/go/packages (NeedTypes|NeedSyntax|NeedTypesInfo, Tests:false). For every call to writeJSON, json.Marshal, json.MarshalIndent and (*json.Encoder).Encode in the package, take the static type of the body argument (for a map[string]any composite literal, each value's type). Walk the type as encoding/json would (exported fields, embedded structs promoted unless a shallower field of the same JSON name exists, pointers, slices, arrays, map values). Fail if the walk reaches provision.Record.Gate or registry.Route.Gate under JSON name gate without a shallower gate-named field shadowing it. Report the call site file:line. - [ ] Step 2: negative control in the same test: a type-check of a small in-memory package containing
type v struct{ provision.Record } passed to json.Marshal must be flagged, and type w struct{ provision.Record; HiddenGate string \json:"gate,omitempty"\ } must not. - [ ] Step 3: run; it must PASS on main (the review found no leak). If it FAILS, that is a real leak: stop and report the site to the controller before fixing.
- [ ] Step 4: commit
console: guard test that no JSON view carries a gate hash.
Task C2: toolchain note
Files: Modify .amadan/go-toolchain.sh (the "it also carries GO-2026-6859" line).
- [ ] Replace with two sentences: GO-2026-6859 is present in 1.26.10 but needs a body read on another goroutine than the handler's while it writes headers, with net/http's own response writer passed to MaxBytesReader; #904 checked every production MaxBytesReader site and found none. Its fix in 1.26.11 is the same change that brings the deadlock, so moving the pin waits for both. Commit
ci: say why GO-2026-6859 does not move the 1.26.10 pin.
Branch D: sec-unit-app-demobuild (census)
Task D1: carlos-app@ operator-trusted stance plus non-breaking controls
Files: Modify internal/host/units/carlos-app@.service, internal/registry/registry.go (Backing field comment and SetBacking doc comment), README.md (the unit-backing / app-capabilities section near "hostrole"), `internal/host/unitsisolation_test.go`.
- [ ] Step 1: test
TestAppUnitHardeningFloor in units_isolation_test.go: carlos-app@.service carries SystemCallArchitectures=native, SystemCallFilter=@system-service, SystemCallFilter=~@keyring io_uring_setup io_uring_enter io_uring_register userfaultfd, SystemCallErrorNumber=ENOSYS, ProtectControlGroups=yes, PrivateIPC=yes, TemporaryFileSystem=/dev/mqueue:ro; and does NOT carry PrivatePIDs= (#528) or a loopback/RFC1918 IPAddressDeny (would cut the edge's loopback dial to Addr tenants and DNS). Keep IPAddressDeny=169.254.169.254/32 fd00:ec2::254/128 exactly; do not widen to 169.254.0.0/16 (the VPC resolver 169.254.169.253 may be the box's DNS). - [ ] Step 2: FAIL. Step 3: add the lines (copy each from
carlos-instance@.service with its comment shortened), and add to the unit header: "Trust: unit backing is for operator-trusted tenants only (Paul, 2026-11-16). It is set only by box root through carlos route --backing unit / carlos add --backing unit, never by the console. It does not carry the instance sandbox's network fence or abstract-socket scoping: a unit tenant can reach loopback, the VPC and abstract unix sockets. Never set it for a tenant you would not give a shell on the box." Mirror one sentence in the Backing and SetBacking comments and in README. - [ ] Step 4:
go test ./internal/host -run 'Unit|Isolation' -count=1 and go test ./internal/edgefence -count=1; PASS. Run systemd-analyze verify on the unit if available (sandbox off). Commit host: carlos-app@ is operator-trusted; add the syscall and IPC floor.
Task D2: demobuild chmod through an fd
Files: Modify internal/demobuild/unit.go (the systemd-family filepath.WalkDir(l.cache, ...) that calls os.Chmod(p, 0777)). Test: internal/demobuild/unit_cache_chmod_test.go (new; Linux build tag if instancefs needs it).
Interfaces — consumes: instancefs.OpenDirBeneath(dir, name string) (*os.File, error) (Linux; ErrUnsupported elsewhere), the pattern in gvisor.go ownBuildDirectories.
- [ ] Step 1: test
TestCacheDirsChmodThroughFD: a cache tree whose subdirectory is swapped for a symlink to an outside dir between walk and chmod is not chmodded through the link (drive it with a hook or by asserting the helper refuses a symlink component via OpenDirBeneath); ordinary dirs end 0777. - [ ] Step 2: FAIL. Step 3: extract
chmodCacheDirs(cache string, mode os.FileMode) error that walks as today but chmods each dir via instancefs.OpenDirBeneath(cache, rel) + f.Chmod(mode). Non-Linux keeps compiling (cross-compile gate: darwin/windows/arm64). - [ ] Step 4:
go test ./internal/demobuild -run 'Cache|Chmod' -count=1; GOOS=darwin go build ./...; PASS. Commit demobuild: chmod the build cache through an fd, not by path.
Task D3: census card for branch D
- [ ] As A3, NAME=sec-unit-app-demobuild, claims for the unit file,
registry.go comment-only change, unit.go walk. Astra census review; record on #280.
Branch reviews
Each branch: Astra review of the whole branch (per-task review only where AGENTS.md stopping rule 3 requires: A1 redirect, A2 dial gate, B1 CSRF gate). Fable second reviewer on B and A. Max three rounds; stop at the first round with no P1.