Skip to content

fix(client): refuse unsafe credential and replay inputs - #5246

Closed
thymikee wants to merge 55 commits into
fix/daybreak-android-helper-boundariesfrom
fix/daybreak-client-replay-boundaries
Closed

thymikee wants to merge 55 commits into
fix/daybreak-android-helper-boundariesfrom
fix/daybreak-client-replay-boundaries

Conversation

@thymikee

@thymikee thymikee commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

Summary

Reject credentials before non-loopback cleartext HTTP requests. Keep remote artifacts in client-owned destinations. Bound Maestro selectors while preserving literal, multiline, and long exact matches. Bind trace and performance destinations to client-minted capture IDs. Prove bundled dependencies in the packed artifact.

This PR is stacked on #5245, which must merge first.

Before / after

  • Non-loopback HTTP requests could carry a bearer token; they now fail before transport.
  • A pathless capture stop could reuse a stale destination. Live capture IDs authorize saved paths. Typed refusals, mismatches, later starts, and delayed close replies now settle the correct client record.
  • Unsafe selector regexes could exhaust CPU. Nested quantified alternatives are refused before execution; bounded multiline matching preserves short-value behavior. Long regex-shaped selectors use exact normalized equality across all candidates. Ordered interactions remain fail-closed when a match is uncertain. Failure suggestions omit unsafe or indeterminate selectors so the original step failure remains reportable.
  • A malicious authenticated daemon could replay a client-minted ID to select a previously caller-authorized path under the documented trust assumption. An old daemon without the ID echo gets a unique client destination.

Validation

At 7f9c92c2e8, the Maestro failure-suggestion test file passed 18/18; capture tests passed 33/33 at the preceding source commit. Independent review found no issues. Earlier closure 28/28, proxy 3/3, selector 33/33 passed. Current-head code checks passed; Runner Build fails before compilation in concurrent actions/cache/restore setup. The capture certainty Fallow finding is fixed. No live remote trace or perf run was performed.

@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 6.74 MB 6.81 MB +71.6 kB
Package (unpacked) 6.74 MB 6.81 MB +71.6 kB
Package (download) 2.06 MB 2.08 MB +18.6 kB

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 27.6 ms 24.0 ms -3.7 ms
CLI --help 52.5 ms 53.1 ms +0.6 ms

Affected plugins

Plugin Installed (including dependencies) Unpacked Download
@agent-device/revyl 180.5 kB → 180.5 kB (0 B) 180.2 kB → 180.2 kB (0 B) 58.5 kB → 58.5 kB (+1 B)
@agent-device/testmu 27.4 kB → 27.4 kB (0 B) 27.1 kB → 27.1 kB (0 B) 10.0 kB → 10.0 kB (+1 B)
@agent-device/tizen 97.5 kB → 97.5 kB (0 B) 97.2 kB → 97.2 kB (0 B) 34.4 kB → 34.4 kB (-1 B)
@agent-device/webos 96.5 kB → 96.5 kB (0 B) 96.1 kB → 96.1 kB (0 B) 34.1 kB → 34.1 kB (-1 B)

@thymikee
thymikee force-pushed the fix/daybreak-client-replay-boundaries branch from c69488e to 6bf3ff2 Compare November 30, 2026 13:17
@blacksmith-sh

This comment has been minimized.

@thymikee
thymikee force-pushed the fix/daybreak-client-replay-boundaries branch from d55bd5a to 9ed0566 Compare November 30, 2026 13:28
@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex Sentinel: 2 new findings on 9ed0566. The verdict and the full list are in the summary comment.

@blacksmith-sh

This comment has been minimized.

@thymikee
thymikee force-pushed the fix/daybreak-client-replay-boundaries branch from 4169368 to 2b4c512 Compare November 30, 2026 14:28
@thymikee
thymikee force-pushed the fix/daybreak-client-replay-boundaries branch from 2b4c512 to 6b7f79e Compare November 30, 2026 14:57
@thymikee
thymikee force-pushed the fix/daybreak-client-replay-boundaries branch from 6b7f79e to 156eab1 Compare November 30, 2026 15:01
@thymikee
thymikee force-pushed the fix/daybreak-client-replay-boundaries branch 2 times, most recently from 2827834 to 4908c28 Compare November 30, 2026 15:17
@thymikee
thymikee force-pushed the fix/daybreak-client-replay-boundaries branch 4 times, most recently from b44de1a to f9d127a Compare November 30, 2026 15:55
@thymikee

Copy link
Copy Markdown
Member Author

The code at f9d127a needs changes before merge. The Maestro selector guard refuses common safe selectors, some transport docs are now false, and the points below on release behavior and remote capture paths need attention.

selector-regex.ts:41 still refuses every unescaped ( ) [ ] { } | and more than one unescaped * + ?. So .*Sign in.*, candidate-(low|high), item \d{2} and [0-9]+ now throw maestro_selector_regex_unsafe. All of them work on base e11d593. The selector step fails on the first node that is not an exact match, so the whole flow fails. The updated tests remove these base patterns. Please refuse a pattern only when its matching work can be exponential: a quantifier ({n,m}, *, +, ?) on a group whose body has a quantifier or an alternation, and any backreference. Keep the 256-character pattern cap and the 8192-character value cap in matchesMaestroRegex, and drop the other two rules. Tests should show that .*X.*, (low|high), \d{2} and [0-9]+ match, and that (a+)+, (a|aa)+, (a+){2} and (a+)\1 are refused. run-maestro-flows.md:33 should state the narrower rule.

selector-regex.ts:17 now runs the guard before the normalized equality check. An exact visible label such as Sign in (beta), Terms | Privacy, Item 22 [ready or Why? Who? now throws. These labels matched on base, so copying a label into a text selector breaks for ordinary punctuation. The invalid-regex literal fallback also cannot run for them. A literal match never reaches the backtracking engine, so it should not need the guard. Please run the equality check and the literal fallback for invalid regexes first, and check only the pattern that is actually passed to new RegExp. Keep the 256-character cap on that pattern, and restore the base Item 22 [ready literal test.

security-trust.md:46 still says 0.21.x warns on stderr and 0.22 refuses. Line 48 says the override silences the warning, and remote-proxy.md:32 repeats the warning phase. At this head, 0.21.45-dev refuses and the warning code is gone, so an operator with a LAN http:// daemon URL gets insecure_credential_transport. Every transport sentence in website/ and skills/ should match the shipped behavior of the release line. If refusal stays on this line, these sentences should say that the connection is refused unless AGENT_DEVICE_ALLOW_INSECURE_TRANSPORT=1 is set. Searching for 0.21.x warns, warns on stderr and silences the warning finds the sites.

A second independent pass found that credential-admission.ts:11 likely removes the agreed warning period on 0.21. On e11d593, an authenticated LAN HTTP endpoint connects after one warning. Now the CLI or SDK refuses before it sends the daemon token. The same change affects cloud device auth, stored-issuer exchange, the Metro bearer and the proxy's default upstream token. The command help and the proxy README already advertise immediate refusal. Please keep the warn-once helper, with matching help and proxy README, on the 0.21 line, and land the refusal and its docs on 0.22. Unsafe upload tickets should keep the existing legacy fallback on both lines. If a maintainer confirms refusal on 0.21 instead, only the docs fix above is needed.

A second independent pass found that peer metadata likely still shapes the client path for unnamed trace and perf output. At daemon-artifacts.ts:752, the remote daemon can pick the stem and extension through fileName, or the stem through artifact.field. On Windows, report.txt:trace.log passes the drive-prefix check and can select a stream on report.txt. A response can also claim artifactType: test-artifacts and switch to directory extraction. For trace and perf, the destination and regular-file mode should come from the client request. The client should build the full name with a UUID and its own extension when the format is known. Response filename, field, type and paths should not affect the destination.

A second independent pass found that a path named at capture start is likely lost at stop. After trace start ./captures/run.log, a pathless trace stop now saves a UUID-suffixed file in cwd (daemon-artifacts.ts:738). Base downloads to the named path. perf cpu profile and perf trace are affected too, and the Android help examples give a path only at start. The client should keep the start destination in its own capture state and use it at stop. An explicit stop path should still win, the unnamed fallback should be generated locally, and the daemon echo should not be used to recover the path.

A second independent pass found that selector-regex.ts:41 likely classifies by punctuation instead of regex structure. item \d{2} \[ready, Item [0-9], Save|Done, (?:Save) and literal text such as Item [ready or Tax (USD) throw. Line 33 also treats Item \8 as a backreference, although it matches Item 8 when the pattern has no capturing group. The check should classify parsed regex constructs, keep the literal path when no regex runs, admit safe classes, bounded counts, groups and alternatives, and separate real backreferences from literal escapes.

A second independent pass found that selector-regex.ts:43 likely refuses safe patterns by counting quantifier characters. Item \d+\s+ready has two disjoint runs, Item \d+? ready has one lazy repetition, and C++ is a literal label. All throw now. The check should tell quantifier modifiers apart from separate repetitions, judge real ambiguity or nesting, and keep literal matching for input that never runs as a regex.

A second independent pass found that selector-regex.ts:16 likely rejects long exact selectors. An id of 257 ASCII letters matches the same identifier on base but now throws, and a new test asserts this. Exact literal comparison should stay available for long safe selectors, with any budget applied only to regex work.

A second independent pass found that selector-regex.ts:18 likely reports long matching values as absent. With a label of Details: , 8,300 x characters and End, the selector Details: x+ End matches on base. Now assertVisible misses it and assertNotVisible can pass while it is on screen. Admitted patterns should match long values with bounded, linear work on the value. If a match cannot be evaluated within the budget, the result should be an explicit indeterminate one, not a non-match.

Not blocking: these can be taken or left: run-maestro-flows.md:33 says values over 8192 characters fail with maestro_selector_regex_unsafe while selector-regex.ts:18 returns no match, so either the doc or a typed refusal for non-literal patterns should align them; a maintainer should confirm refusal on 0.21.x (the linked requirement asks for it and ADR 0041 calls a temporary warning a release choice, but the agreed split is warn on 0.21 and refuse on 0.22) or this layer should move to 0.22; as a follow-up, a start path for trace or perf trace could be kept in client state keyed by connection and session (or the help could repeat --out on stop) and the unread daemon echo removed, although remote-proxy.md:102 documents the current behavior; also as a follow-up, although the daemon can no longer select an existing client path, daemon-artifacts.ts:611 could use a request-derived extension for trace and perf, refuse : in Windows names and allow directory mode only for client-approved test-artifact requests; and once the guard is narrower, the AST repo guard and its gate-only rewrite could go, since matchesMaestroRegex has one production caller.

Could matchesMaestroRegex be just the 8192 value cap, normalized equality, the literal fallback for invalid regexes, one check for exponential groups and backreferences (with the 256 pattern cap), and then new RegExp, with no other rules and probably no AST repo guard? The credential and artifact parts already look minimal. Would a maintainer decision to refuse rather than warn on 0.21.x need to come first for the credential part?

Two earlier threads no longer apply and can be resolved: this one because a label over 8192 characters now returns no match instead of failing every selector, and this one because escaped characters are now skipped and tests show that a\(b and price \{2\} match.

The non-passing checks look unrelated to this diff: Body rules was cancelled by a newer push, and one other check is still queued. An earlier failure in packages/platform-android text-input-fill.test.ts comes from the base Android layer (#5245), which this diff does not touch.

Not verified here: tests were not run; the cost of .*X.* on 8192-character labels was reasoned from backtracking behavior and not measured; the full traversal of the AST repo guard and archive-entry safety in artifact-download.ts for directory mode were not read; and no transport sentences were found by a search of skills/, so its coverage of the 0.21 warning phase was not confirmed further.

Before merge, the Maestro guard should be narrowed to exponential shapes and backreferences with the literal fallback ahead of it, and the transport sentences in security-trust.md and remote-proxy.md should match the release behavior.

@apex-sentinel-staging

This comment has been minimized.

@thymikee

thymikee commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

No code problems remain at ae98615. The multiline selector problem from the earlier review is fixed: selector-regex.ts now checks the whole value once before it applies the restart budget, so the 1,209-character start.*end label matches again. The new test covers that input.

This long-selector thread no longer applies and can stay resolved: long selectors are decided by exact equality across all candidates, and the per-node match defers the refusal.

Not verified here: tests were not run locally, and the reported 33/33 pass comes from the author. The regression test was judged by tracing the 9a37623 code by hand. The cost of the single whole-value check on a 16,384-character multiline value was not timed; it was judged equivalent to the existing single-line path, which has no length cap.

The only check that did not pass is a cancelled Body rules job. It is likely unrelated to the code, because that job validates the PR description.

Before merge, merge the base PR #5245 first, take this PR out of draft, and get Body rules to pass.

@thymikee
thymikee marked this pull request as ready for review December 1, 2026 03:25

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 58 files

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread website/docs/docs/security-trust.md Resolved
Comment thread docs/agents/security.md Resolved
Comment thread scripts/check-package.ts Resolved
Comment thread website/docs/docs/run-maestro-flows.md Resolved
Comment thread scripts/check-package.ts Resolved
Comment thread website/docs/docs/error-reasons.md Resolved
@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Dec 1, 2026
@blacksmith-sh

This comment has been minimized.

@apex-sentinel-staging

This comment has been minimized.

@thymikee thymikee removed the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Dec 1, 2026
@thymikee

thymikee commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

At dfd7fc9, the points raised in the inline threads are fixed, but the new foreign-capture guard can stop a caller from ending a capture. This is a follow-up to the earlier review, and three problems with that guard remain.

capture-destination-record.ts:213 marks the record foreign when a capture-already-active refusal names any ID other than current.active.generation, even if this client minted that ID. One route: trace start /a.trace is dispatched and the daemon stores the ID, the client send throws (timeout or dropped connection), and the retried start is refused with that same ID. Another route: the client process dies after dispatch, so the ID is still in current.pending at the next start. The mark then stays, and every stop is refused before dispatch, including a stop with an explicit path, until a successful close, which loses the capture. This is a regression: on the base branch, the pathless stop after a retried start returns the artifact. The security doc and the error reasons doc describe only a refused pathless stop. The rule: foreign means an ID this client provably did not mint, decided once in certaintyAfterStart. An ID that matches a pending generation, or a refusal while the client's own history is already unknown, must stay unknown; only a settled record can become foreign. Either limit the refusal to pathless stops, as the docs say, or update both docs to say every stop is refused. Please add a test to capture-destination-record.test.ts where start throws after dispatch, the next start is refused with that generation, and the pathless stop still dispatches.

A second independent pass found that the foreign guard also blocks a stop with a caller-chosen destination. Client A starts a remote trace or native perf capture. Client B, with a separate state directory but the same remote session and lease, tries a start, receives A's live ID, and then runs trace stop ./capture.log or perf ... stop --out ./capture.trace. The guard throws before the explicit-path check, although that stop dispatched on the base branch and the daemon still accepts it without a capture ID. The foreign refusal must apply only to a stop with no explicit client destination. A successful explicit stop should save to the chosen path and clear the foreign mark if it is still the one seen before dispatch.

A second independent pass found that a client can also mark its own unnamed capture as foreign. Run remote trace start without a path, run it again on the same session, then run trace stop. The first start succeeds and echoes the client's ID, but the client drops that identity because there is no destination. The refused repeat start names the same ID, so the stop is rejected, although it dispatches on the base branch. Native perf starts without --out follow the same path. A confirmed start must keep its generation and order even without a destination, so a repeat-start refusal with that generation still allows the stop, with the unique client filename when no path was saved.

Not blocking: a malformed or unreadable record now also makes a remote close of that session fail with an error that names no file, so close could skip or remove that record, or the refusal details could name its path, here or in a follow-up issue, as you prefer.

No inline thread still applies, so these can be resolved: the upload-ticket sentence now names the client override; the approval rule and its scope are restored; the package check now reads bundled dev dependencies; pathless-stop tests now assert there is no capture ID; both trace result variants now include the client capture ID; three certainty states now exist (the first problem above is a new effect); only a missing file now counts as no record; lone CR and LF cases are tested; the saved-path rules are reworded; the proxy test now asserts the error code; the Maestro doc now names lookarounds; the package check header is updated; trace and native perf share one refusal builder; the docs now say when the live ID is named.

The only check that did not pass is Body rules, which was cancelled. It validates the PR description, so it looks unrelated to this code. The other 40 checks pass.

Not verified here: tests were not run locally. The first problem was traced by hand through the client record and daemon trace code, not reproduced. The exact error returned on a remote request timeout was not confirmed; the route only needs it to differ from a capture-already-active refusal.

Before merge, the guard needs these fixes and the timeout-then-retry regression test. Then the base branch fix/daybreak-android-helper-boundaries needs to land first, and Body rules needs to pass.

@thymikee

thymikee commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

Fixed the three foreign-capture regressions at efaf61b3e7. A retry that names this client's pending ID, or follows an uncertain start, stays uncertain and allows a pathless stop with the unique-file fallback. A confirmed unnamed start retains its capture ID, so a repeat-start refusal preserves that identity. Only a settled record with a different live ID becomes foreign. That state refuses a pathless stop, while an explicit caller path still dispatches; success clears only the unchanged foreign record, and failure or a concurrent replacement retains it. Trace and native perf are covered by the focused capture test (33/33). An independent focused review found no actionable issue.

Current-head CI is pending. The 14 earlier inline threads remain resolved; #5245 must merge before this PR.

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex Sentinel: 2 new findings on efaf61b. The verdict and the full list are in the summary comment.

Comment thread packages/kernel/src/errors.ts Resolved
@thymikee

thymikee commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

At 7f9c92c2e8, failure suggestions catch only the two typed unsafe/indeterminate selector errors across ranking and basis calculation, returning no suggestions so report construction retains the original step failure. The focused Maestro test file passed 18/18. The capture-certainty logic was also extracted without changing its branches to address the Fallow complexity failure. Independent review found no actionable regression. I replied with call-path evidence to the other two inline findings and resolved them. Current-head CI and Apex review are pending.

@apex-sentinel-staging

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve · review of 7f9c92c

Since the review of efaf61b: 0 new · 0 still open · 2 no longer raised

No open findings.

Not in the reviewers' scope (1 file)
  • pnpm-lock.yaml: generated or a lockfile, so its lines were left out

Reviewed with this repository's own Sentinel configuration (cddba76858da).

💬 Talking to Sentinel

In a finding's thread, reply with:

Command What it does
@apex-sentinel-staging note <context> Adds context; Sentinel re-checks the cited code
@apex-sentinel-staging pivot <why> Says the finding is wrong; Sentinel re-checks the cited code
@apex-sentinel-staging like Marks the finding as useful
@apex-sentinel-staging dislike <why> Marks it as not useful, so it is not raised again

On this conversation, comment @apex-sentinel-staging review to run a full review once again.

@thymikee
thymikee added this pull request to stack #5297 December 1, 2026 06:43
@thymikee

thymikee commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

Please ship the shared credential refusal at the five ADR 0041 points. Preserve the process override, the proxy’s custom-transport exemption and the unsent-ticket fallback to the admitted daemon. Target the announced 0.22 enforcement release unless the rollout is explicitly changed. Move Maestro matching and its packaging work to a replay PR. Move artifact destinations and capture identity to a client-artifact PR, with their regression tests. The transport tests can observe zero sends and ticket fallback directly. No remote trace, perf or device replay run is needed for the credential change.

@thymikee

thymikee commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

At 7f9c92c, the three problems from the earlier review are fixed, and no new code problems were found in the changes since then. A timed-out or pending own start now stays unknown, so a pathless stop still dispatches. The foreign refusal now allows a stop with an explicit path, and a successful one clears the unchanged foreign mark. A confirmed unnamed start now keeps its capture ID.

Both open threads can be resolved. Stop hand-off keying does not apply, because the same request object reaches artifact materialization without a clone. Mismatch meaning wording does not apply, because both the error definition and the error reasons doc now start with the daemon refusal.

Runner Build (tvOS + visionOS + watchOS) failed and looks unrelated, because this PR changes no Swift, Xcode, runner or workflow file. The PR description reports a failure in a setup step before compilation. Body rules was cancelled, and it checks the PR description, not the code.

Not verified here: tests were not run locally, and each new regression test was judged by reading it against the dfd7fc9 code. The Runner Build failure log was not captured. The credential refusal code was not reviewed again, because these changes do not touch it and earlier reviews covered it.

This commit was pushed before the re-scope request, so the Maestro and capture work is still here. Before merge, please keep only the shared credential refusal at the five ADR 0041 points in this PR, including the process override, the proxy custom-transport exemption and the unsent-ticket fallback. Move Maestro matching and its packaging to a replay PR, and capture destinations and identity to a client-artifact PR, each with its regression tests. Then update the title and description, get Body rules passing, and land the base branch fix/daybreak-android-helper-boundaries first.

@thymikee

thymikee commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

Superseded by three scoped PRs, all based on #5245:

The three slices were independently reviewed. This mixed-scope PR can close while the successor branches receive their own CI and review.

@thymikee thymikee closed this Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant