Skip to content

fix: bind artifact access to producing lease - #5278

Closed
thymikee wants to merge 35 commits into
fix/daybreak-daemon-boundariesfrom
fix/lease-artifact-owner-admission
Closed

thymikee wants to merge 35 commits into
fix/daybreak-daemon-boundariesfrom
fix/lease-artifact-owner-admission

Conversation

@thymikee

@thymikee thymikee commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

Closed as superseded by #5344 on the 0.22 remediation line. Continue review and implementation there. Historical validation below remains attributed to its original commits; closure does not claim the replacements are merge-ready.

Summary

Bind upload stages, retained downloads, provider artifacts, and materialized paths to the admitted tenant and producing lease. Tenant authentication establishes authority. Stacked on #5243.

Before / after

  • Leased HTTP transfers accept an omitted run for the owning tenant and check any supplied run. Artifact inventory, install-from-source, path release, and recording recovery check producing scope.
  • Explicit historical queries keep their producing scope. With an explicit --session and no lease or run flags, provider-session lookup uses the named cloud connection's lease and run.
  • Recording treats an empty lease as omitted. A nonempty lease requires a tenant owner. Stop active leased recordings before upgrading to protocol 4.

Validation

At c287bab53a, five CLI transport tests passed. The added assertion failed on 8bd855d69b. At 8bd855d69b, both AST parity cases and all 19 hosted checks passed. At a5c5a46b4c, five CLI transport tests passed, including two historical cases that failed at f5ba4128b3. At 5cddfe7e32, 83 CLI transport and HTTP output tests passed.

On combined tip 2c6b09defd with this layer at d7e2b68cab, iOS 26.2 verified package and local ZIP staging, install, and path release through a hookless HTTP proxy with explicit tenant and retained lease. Protocol-4 live evidence is pending for omitted-run staging, URL source install, recording stop or restart recovery, post-close inventory, producing-owner download, typed wrong-lease refusal, and authenticated historical provider lookup. Bearer-only and session-only staging still need an ownership decision.

46a98d5310 extracts the artifact scope block to address Fallow. Merge-tree clean through #5281 and #5282. CI pending.

@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 6.78 MB 6.79 MB +8.9 kB
Package (unpacked) 6.78 MB 6.79 MB +8.9 kB
Package (download) 2.07 MB 2.07 MB +2.4 kB

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 17.3 ms 20.8 ms +3.6 ms
CLI --help 39.2 ms 46.4 ms +7.2 ms

Affected plugins

Plugin Installed (including dependencies) Unpacked Download
@agent-device/revyl 181.2 kB → 181.2 kB (0 B) 180.8 kB → 180.8 kB (0 B) 58.6 kB → 58.6 kB (+1 B)
@agent-device/testmu 26.5 kB → 26.5 kB (0 B) 26.2 kB → 26.2 kB (0 B) 9.6 kB → 9.6 kB (0 B)
@agent-device/tizen 99.5 kB → 99.5 kB (0 B) 99.1 kB → 99.1 kB (0 B) 34.9 kB → 34.9 kB (0 B)
@agent-device/webos 98.5 kB → 98.5 kB (0 B) 98.1 kB → 98.1 kB (0 B) 34.6 kB → 34.6 kB (0 B)

@blacksmith-sh

This comment has been minimized.

@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: 5 new findings on 6c83c5b. The verdict and the full list are in the summary comment.

Comment thread packages/proxy/src/daemon-proxy.ts Resolved
@thymikee

Copy link
Copy Markdown
Member Author

At 6c83c5b, artifact access is not yet reliably bound to the producing lease. Some valid downloads, uploads and lookups now fail, and some callers can reach another lease's artifacts. These changes are needed before merge.

downloadable-artifact-http.ts:216: valid downloads can now return 401. RPC admission accepts leaseId and tenant without runId, and the artifact is bound to that lease. The client then sends the lease header without a run header, and download admission refuses it. Clients built before this head also never send the run header. The run is client-declared, so requiring it adds no isolation. The rule: artifact HTTP authority is the attested tenant plus the lease ID, and the owner's run comes from the registry, never from a header. Please drop DAEMON_HTTP_RUN_HEADER, buildDaemonHttpRunHeaders and the proxy forwarding, and admit {leaseId, tenantId} against the retained owner's tenant, as uploads do.

request-finalization.ts:112: artifacts, uploads and materialized paths bind the declared req.meta.leaseId, not the admitted lease. A request in a session bound to a lease can omit that field and still be admitted. Its artifact is then bound to the tenant only. The rule: every lease-bound store records req.internal.admittedLease, or nothing for unleased requests. This applies to artifact registration, upload consumption and each retain or cleanup of a materialized path.

A second independent pass found that downloadable-artifact-http.ts:219 trusts a caller-declared run and lease. With a tenant-only auth hook, a caller from one run can name another run and lease of the same tenant. It can then list and download that lease's artifacts, even after close while they are retained. The proxy copies both values. Artifact HTTP access should require ownership proven by authentication, such as a run and lease binding or a lease grant that survives close. The proxy should strip incoming identity headers and stamp admitted values, and direct daemon ingress should verify the same proof.

A second independent pass found that RPC artifact inventories also authorize by caller-selected scope (lease.ts:514). The artifacts command skips lease admission. A tenant caller can name another lease in the daemon branch, claim its run and lease in the cloud branch, or select it by provider session ID. All three branches should use the same authenticated artifact scope. A provider session ID should only be a lookup key, and its stored lease must match that scope before the provider is called.

A second independent pass found that upload and install accept a substituted lease (upload-http.ts:152). For a basic lease with no provider, device or client scope, another run of the tenant can use it at legacy upload, preflight, chunk receive and finalize. Install, reinstall and path-based install-from-source also trust the RPC lease identity. Each leased upload phase and install consumption should require proven ownership of an active lease, use its canonical ID, and refuse a lease-bound request without that proof.

A second independent pass found that valid provider-bound installs now fail at the same upload check. Proxy and provider leases require run and any bound provider, device or client fields, and the HTTP caller supplies none to this check. A direct bearer-only daemon also fails now, because the client sends the lease without a tenant header. Uploads should be admitted by the authenticated tenant and run against the active lease, with one upload-specific check carried through every phase. Direct leased connections need credentials that establish this scope.

A second independent pass found that execution can drop the admitted lease (request-finalization.ts:112). A tenant request on a leased session without meta.leaseId can register a recording, trace or perf capture as tenant-only, and an unscoped GET can read it. Tenant-only uploads and retained install paths follow the same split. The dedicated install-from-source RPC drops lease fields but can still pass session-based admission. Remote artifact authority should be resolved from authenticated scope before execution and used for registration, upload consumption and path ownership. A leased artifact operation admitted by session name alone should be refused.

A second independent pass found that recording recovery can hand one lease's recording to another (screen-recording-stop-recovery.ts:102). After lease A closes, the same tenant can use lease B with the same session name and simulator. record stop then replays A's completed recording and registers it under B. The recording manifest should store the producing lease at start. Replay should require a match and keep the original tenant and lease.

A second independent pass found that one lease can get different owner values (upload-http.ts:153). The registry accepts upper-case or space-padded lease IDs, but stores and comparisons keep different spellings. An owner can then fail to install an upload, download an artifact or find a retained provider session. Admission should return the canonical registry ID, and upload, download, inventory, provider lookup and materialization should all use it.

A second independent pass found that materialization release trusts a claimed lease and can lose the real owner (session-app-source-deployment.ts:157). A same-tenant caller who knows the materialization ID can name its lease and release the paths. The dedicated release RPC drops lease fields, so an owner of a leased result gets a mismatch. Both release routes should pass authenticated scope and compare the admitted lease with the stored producer before removing a path.

A second independent pass found that protocol 3 peers now disagree on artifact requests (downloadable-artifact-http.ts:207). Existing clients send the lease without a run header. Head refuses that shape, head proxies now forward the lease header, and the version is still 3. If a stricter scope is required, make it an explicit ADR 0006 change. Update the version, compatibility ledger and peers so incompatible callers fail before dispatch.

A second independent pass found that some artifact lookups that worked before now fail (lease.ts:104). A lookup by live session name without lease metadata returns the unleased inventory. After proxy close, the saved lease ID is cleared, so retained entries are lost to that command. The documented provider session ID lookup also fails without a run. The CLI and SDK should carry the producing lease's authenticated scope, including after close, for both lookup forms. Help and docs examples should show that path.

Would a smaller design work here? Drop the run header, bind each store to req.internal.admittedLease?.leaseId, and keep one retained lease-owner record in LeaseRegistry, pruned with leases. Every lease-named read and upload would then require the lease owner's tenant to equal the attested tenant. Existing clients already send the lease header, and isolation stays at the level of this head because the run is unattested either way. This differs from the asks above for proof of run or lease ownership. Same-tenant run isolation would first need a server-attested run identity. An ADR 0006 decision is also needed on whether requiring the lease header for downloads changes protocol 3.

Not blocking: these can be taken or left: one shared tenant-and-lease owner check with a typed reason instead of copies after requireTenantOwnedEntry, one retained owner record pruned with leases instead of two with separate windows (lease-registry.ts:758), removing the releaseReservation hook that no production caller passes (artifact-tracking.ts:530), and one lease-read admission for both HTTP and RPC inventories (lease.ts:514).

The open thread on the run header still applies, and so do 4 lower-priority open threads.

Repo Guards & Compatibility and Coverage fail, and the PR description places both failures at the wire-compat gate. They are likely caused by this change, which edits the daemon HTTP contract and upload and artifact declarations that the gate checks.

Not verified here: tests were not run, and job logs were not used to confirm the author's test results or the CI cause. No current production caller was confirmed to send a lease and tenant without a run, so the confirmed affected group for the first finding is older clients and callers that pass --lease-id without --run-id. The path that carries the admitted lease into response finalization was not fully traced. A base-version proxy in front of a head daemon was not checked.

Next, remove the client-declared run header from artifact admission and bind stores to the admitted lease. Then settle the ADR 0006 wire-compat decision so that Repo Guards and Coverage pass.

@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: 1 new finding on ef7540c. The verdict and the full list are in the summary comment.

@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: 1 new finding on 6399fb9. The verdict and the full list are in the summary comment.

@thymikee

Copy link
Copy Markdown
Member Author

Leased installs and uploads that worked on base now fail with 401 at 6399fb9, so this needs changes. Since the earlier review, a missing run on provider-session lookup is refused, expired lease owners are pruned, the empty inventory on a leased session is now a typed error, and the stale contracts comment is fixed. The problems below remain or are new.

upload-http.ts:148: the lease header without x-agent-device-run-id is now refused on /upload*, where base ignored it. Released clients send the lease on preflight, chunk, finalize and legacy upload without a run. New clients do the same when --lease-id is accepted without --run-id (lease-registry-scope.ts:245, daemon-artifacts.ts:206). Their leased installs and uploads fail, as reported and confirmed. The run is client-declared, so the refusal adds no isolation. The rule: artifact and upload HTTP authority is the attested tenant plus the lease ID, and the owner's run comes from the registry, never from a header. This covers every admission site, so the clients and proxy no longer need to send the run header. Otherwise, the stricter shape needs an explicit ADR 0006 protocol bump.

request-finalization.ts:112: artifact registration, upload consumption and materialized-path retain and release still bind the declared req.meta?.leaseId (also session-app-deployment.ts:80, install-source-resolution.ts:51, session-app-source-deployment.ts:138). Can a request admitted through its session's lease, without meta.leaseId, then register a tenant-only artifact that any same-tenant unleased read can list and download? That appears likely. Every lease-bound store should bind req.internal.admittedLease?.leaseId, or nothing for unleased requests, through one shared helper that finalization and the deployment handlers call.

screen-recording-stop-recovery.ts:102: this file is unchanged. Can recovery still replay a completed recording from closed lease A and register it under lease B for the same session name and simulator? That appears likely and would hand one lease's recording to another. The recording manifest should store the producing lease at start, and replay should require a match and keep the original tenant and lease.

session-app-source-deployment.ts:160: could you confirm whether materialization release still compares the declared req.meta?.leaseId, and whether the dedicated release RPC still drops lease fields? If so, a same-tenant caller with the materialization ID can release another lease's paths, and the real owner can get a mismatch. Every release route should compare the admitted canonical lease with the stored producer.

ended-lease.ts:36: could you confirm the behavior after proxy close? The session-only lookup now has a typed error and the docs show --lease-id and --run-id, but the saved lease ID still appears to be cleared. The documented agent-device artifacts --json would then send no lease and filter out retained artifacts that base returned. The producing lease and run should stay available to that command after close. Otherwise, device-clouds.md should say that the closed lease's flags are required.

upload-http.ts:163: a second independent pass found that, for a basic active lease, claiming the matching run of another lease in the same tenant is enough to authorize legacy upload, preflight, chunk receipt and finalize. The gate and the resumable store trust the asserted headers. Is there any authenticated tie between the caller and that lease? Every leased upload phase, and RPC upload consumption, should require verified authority (such as a lease grant or a lease binding on the principal) and use that canonical lease.

upload-http.ts:163: a second independent pass found that owners of proxy leases bound to a device or client, or of provider leases, are refused at upload preflight and legacy upload. Read admission requires the bound provider, device and client fields, which these install, reinstall and local-source requests do not satisfy, while base accepted them. Should upload have its own active-lease admission that verifies the principal's grant and returns the canonical lease, leaving those constraints on device RPC admission?

upload-http.ts:154: a second independent pass found that leased installs on a direct daemon without an HTTP auth hook now return 401. Preflight and legacy upload headers omit the tenant (upload-client.ts:262, upload-client.ts:310), so authorization resolves none, while base accepted bearer authentication. Can the direct client's credential establish the owner tenant and producing lease on every leased upload request, with daemon admission using that verified scope?

upload-http.ts:164: a second independent pass found that upload stores the header spelling of the lease ID (also here), while registry admission accepts other casings. An owner who uploads with an upper-case ID and installs with the lower-case one fails the equality check, though base accepted the transfer. Can upload admission return the registry lease, so ticket creation, chunks, finalize, registration and install consumption all use its canonical ID?

upload-http.ts:150: a second independent pass found that the compatibility report holds. A v0.21.45 client passes the check against protocol 3, then gets 401 on leased uploads, and the artifact download incompatibility remains. Should the changed authorization contract be versioned under ADR 0006, with the compatibility ledger and peer metadata updated and a remote-client regression test showing refusal before any transfer or command dispatch?

lease.ts:104: a second independent pass found that a supplied lease ID is enough to pass the new session guard, so artifacts ownership is still caller-selected. Daemon inventory does not validate the run, cloud lease lookup trusts the selected scope, and provider-session lookup can take the lease from the selected session. Can daemon inventory and both cloud lookups require the same authenticated lease-read admission, treating a provider session ID only as a lookup key whose recorded producer is checked before dispatch?

lease.ts:104: a second independent pass found that session-name lookup loses the owner's retained inventory after proxy close. The guard checks only live sessions, the saved lease ID is cleared, and artifacts defers allocation, so the follow-up returns the unleased inventory instead of the retained recording. Can the close result or saved connection carry verified authority for the completed lease during retention, with the explicit lookup documented too?

lease.ts:615: a second independent pass found that the documented SDK example, a provider-session lookup with no configured run, still fails, now with PROVIDER_SESSION_RUN_REQUIRED. Base looked the session up by the admitted tenant. Can the SDK lookup carry the authenticated producing scope, with the example showing how to obtain and supply it?

Not blocking: the guard at lease.ts:104 also appears to refuse the documented past-session lookup (provider session ID and --run-id, no request lease) while a leased session is live, mainly for SDK or local callers, so it could apply only without a provider session ID or let that branch resolve its own lease; take it or leave it.

For a follow-up issue, not for this PR:

  • The proxy forwards client-declared lease and run headers, so a server-attested run identity or lease grant is needed (thread).
  • Artifact listing over HTTP and RPC should share one lease-read admission.
  • Upload admission should return and store the canonical lease ID.
  • The protocol version and ledger do not yet reflect the newly required run header on /artifacts* and /upload*.

Of the open threads, upload compatibility break and proxy forwards headers still apply, as does 1 lower-priority thread. These no longer apply and can be resolved:

Repo Guards & Compatibility and Coverage fail at the wire-compat and closure gates. This PR likely causes it: the description attributes both to the changed upload and artifact wire declarations, and the diff touches that route. Not verified here: tests and CI logs were not run or read; it was not confirmed that remote CLI connections put the saved lease into the artifacts flags (the non-blocking note assumes so); a base-version proxy in front of a new daemon was not checked.

Before merge, leased installs and uploads from base-built clients, and from new clients given --lease-id without --run-id, must succeed again, or be refused through an explicit protocol bump.

@thymikee
thymikee force-pushed the fix/lease-artifact-owner-admission branch from 6399fb9 to 820196a Compare December 1, 2026 09:18
@thymikee
thymikee force-pushed the fix/lease-artifact-owner-admission branch from 820196a to d091508 Compare December 1, 2026 09:45
@thymikee

thymikee commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

At d091508, leased uploads that work on the base branch still fail with 401. The rebase changed no PR code, so none of the blocking items from the earlier review of 6399fb9 is closed.

admitUploadLease returns UNAUTHORIZED for any /upload* request (legacy, preflight, chunk, finalize) with x-agent-device-lease-id and no x-agent-device-run-id. Released clients such as v0.21.45 pass the protocol 3 check and send that shape. New clients do too with --lease-id and no --run-id. Base ac87811 read neither header on upload, so this breaks the production remote install route. The run header is client-declared, so requiring it adds no isolation. The rule to satisfy: HTTP upload and artifact authority is the attested tenant plus the lease ID, and the run comes from the lease registry. Apply it in the admission helper that both admitUploadLease and admitArtifactLease call. Otherwise, refuse old clients before transfer with an explicit ADR 0006 protocol bump and an updated compatibility ledger.

The other earlier items also remain. Finalization, app deployment and install-source stores bind the declared lease, not the admitted one. Recording stop recovery can re-register a closed lease's recording under another lease. Materialization release compares the declared lease. Upload phases trust asserted lease and run headers. Bound proxy and provider lease owners are refused at preflight. Direct leased installs without a tenant get 401. The caller's lease ID casing is stored. The artifact download and run-header contract is not versioned. Artifact lookup after proxy close loses the saved lease. The documented SDK provider-session lookup without a run fails. Most share one root. One admission helper that returns the canonical registry lease for the attested tenant, used by every upload phase, artifact read, finalization store and release route, can close them together.

A second independent pass found that the upload gate likely rejects an active lease owner with a valid tenant credential in all four phases: legacy, preflight, direct PUT and finalize. The fallback from preflight to legacy upload fails too, so local-file install, reinstall and install-from-source stop before dispatch. All four phases must admit the caller through the verified active lease and take the run from it, keeping the current request shape where the credential can establish authority. If existing clients need a new grant, negotiate it before transfer under ADR 0006.

A second independent pass found that a direct daemon without an HTTP auth hook likely returns 401 even with the bearer credential, lease and run. Auth yields no tenant and the client sends no tenant header on preflight or legacy upload. The base route succeeded. Upload admission must resolve the owned lease scope, including the canonical tenant, for the authenticated direct client, and use it through transfer and install.

A second independent pass found that owners of leases bound to a provider, device key or client ID are likely refused at preflight and legacy upload, even with tenant, lease and run. Upload supplies only those three fields, but the registry also requires the device-operation ownership fields. Upload needs its own ownership check on the canonical active lease. The install RPC should keep enforcing the full device scope.

A second independent pass found that an uppercase hex lease ID passes registry lookup but is stored as spelled. A later chunk, finalize or install with the canonical spelling is then likely refused. Admission must return the canonical lease, and preflight, chunks, finalize, registration and RPC consumption must use its ID.

A second independent pass found that upload admission likely lets a caller use another basic lease of the same tenant by declaring its lease and run. The caller can register uploads under it and, with an upload ID, act on its resumable upload. Install paths also trust the request lease field. Every upload phase and RPC consumption must verify a lease-bound grant or authenticated lease principal and compare that lease with the upload's producer.

A second independent pass found that HTTP artifact inventory and download likely return 401 to owners whose client sends a lease without a run, including base-built clients, while protocol 3 is still advertised. Both routes must authorize from the verified producer lease and derive the run from its record where the current credential identifies the lease. Any incompatible credential requirement must be negotiated before dispatch.

A second independent pass found that artifact reads likely trust a caller-selected producer. A same-tenant caller who knows another lease and run can read its inventory, bytes or provider URLs through HTTP or RPC inventory, which is exempt from normal lease admission. HTTP reads and both RPC inventory modes must apply the same verified lease-read authority, resolving a provider session ID to its recorded producer first.

A second independent pass found that a capture on a leased session with no declared lease ID is likely registered without a lease. Another caller with a tenant credential can then list or read it. An install admitted through session scope also cannot consume its lease-bound upload. Output registration, upload consumption, and materialized path retention and cleanup must use the admitted canonical lease. Output recovered from an earlier request must keep its original producer.

A second independent pass found that materialization release likely has no verified owner. A tenant caller with another materialization ID can declare its lease through the generic command and delete its paths. The dedicated RPC drops the lease, so the real owner cannot release them. Both RPC paths must verify the lease owner and pass the admitted lease to the handler, and retention must store that canonical lease.

A second independent pass found that after proxy close clears the stored lease, the documented artifacts --json follow-up likely selects only unleased entries, so the owner loses the retained recording. The new docs note describes an explicit workaround. The artifacts command needs verified access to the completed producing lease for the retention period, separate from the active lease used by the next open.

A second independent pass found that the documented SDK lookup by provider session ID, from a client with no configured run, likely now fails with PROVIDER_SESSION_RUN_REQUIRED, even for the owner. The SDK lookup must carry verified producing-lease authority, and the client API example must show how the caller gets it.

The missing run header thread still applies, as do two lower-priority threads. These no longer apply and can be resolved: this one, because the missing-registry 401 occurs only on embedded test servers; expired owner pruning, the empty leased-session inventory error and the provider-session run refusal, because each requested change is present.

Repo Guards & Compatibility and Coverage fail. The likely cause is this change: it adds a required run header to the upload and artifact wire declarations in packages/contracts/src/daemon-http.ts without a protocol bump, and the PR description gives the same cause. One other check is still queued.

Not verified here: the failing CI logs were not read, no tests were run, and the earlier likely findings on recording stop recovery, materialization release and post-close artifact lookup were not traced again against unchanged code.

Before merge, leased installs and uploads from base-built clients, and from new clients with --lease-id and no --run-id, must stop getting 401. Either admit them by attested tenant plus registry lease, or bump the protocol under ADR 0006.

@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: 4 new findings on d091508. The verdict and the full list are in the summary comment.

@apex-sentinel-staging

This comment has been minimized.

@thymikee
thymikee added this pull request to stack #5309 December 1, 2026 11:48
@blacksmith-sh

This comment has been minimized.

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

@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 44 files

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

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

Comment thread src/daemon-entrypoint.test.ts Resolved
Comment thread website/docs/docs/device-clouds.md Resolved
@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: 1 new finding on 6194cf9. The verdict and the full list are in the summary comment.

@thymikee
thymikee marked this pull request as draft December 1, 2026 12:34
@blacksmith-sh

This comment has been minimized.

@thymikee
thymikee force-pushed the fix/lease-artifact-owner-admission branch from c287bab to 8d5cf14 Compare December 2, 2026 16:54
@apex-sentinel-staging

This comment has been minimized.

Comment on lines +203 to +228
function admitArtifactLease(
req: http.IncomingMessage,
tenantId: string | undefined,
leaseRegistry: LeaseRegistry | undefined,
): string | undefined {
const value = req.headers[DAEMON_HTTP_LEASE_HEADER];
if (value === undefined) return undefined;
const runId = req.headers[DAEMON_HTTP_RUN_HEADER];
if (
typeof value !== 'string' ||
!value.trim() ||
(runId !== undefined && typeof runId !== 'string') ||
!leaseRegistry
) {
throw new AppError(
'UNAUTHORIZED',
'Artifact lease requires an admitted tenant and lease registry',
{
reason: ARTIFACT_DOWNLOAD_REASONS.leaseAdmissionRequired.reason,
},
);
}
const leaseId = normalizeRequiredLeaseId(value);
leaseRegistry.assertArtifactLeaseReadAdmission({ leaseId, tenantId, runId });
return leaseId;
}

@apex-sentinel-staging apex-sentinel-staging Bot Dec 2, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No longer raised on 46a98d5, with the code it pointed at unchanged: withdrawn, not fixed.

Moved from an earlier thread.

🆕 🟡 Minor · GET /artifacts with an absent lease header now hides every leased artifact from its owner

A client that recorded a screenshot under a lease polls GET /artifacts without x-agent-device-lease-id and gets artifacts: []. canReadArtifact's "no scope means unscoped" branch keeps only entries whose entry.leaseId === undefined, so every lease-bound artifact is filtered out. The same omission causes readDownloadableArtifactEntry to throw ARTIFACT_LEASE_MISMATCH; the response's downloadScope is the only place the client learns the id it must send.

Suggested change

Either reject an inventory/download request for a tenant that has lease-bound artifacts and names no lease (typed INVALID_ARGS naming the lease requirement), or fall back to listing the tenant's artifacts for the leases the registry says that tenant holds. Keep the note in the protocol-4 migration docs.

Details

persona: javascript

Useful? Reply @apex-sentinel-staging like, or @apex-sentinel-staging dislike <why> if it is not.

Reply @apex-sentinel-staging note ... to add context, or @apex-sentinel-staging pivot ... if it is wrong — I will re-check the cited code.

@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 8d5cf14. The verdict and the full list are in the summary comment.

Comment on lines +200 to +210
function readDeploymentLeaseScope(params: Record<string, unknown>): DaemonRequest['meta'] {
return {
tenantId: readStringParam(params, 'tenantId'),
runId: readStringParam(params, 'runId'),
leaseId: readStringParam(params, 'leaseId'),
leaseBackend: readStringParam(params, 'leaseBackend') as LeaseBackend | undefined,
leaseProvider: readStringParam(params, 'leaseProvider'),
deviceKey: readStringParam(params, 'deviceKey'),
clientId: readStringParam(params, 'clientId'),
};
}

@apex-sentinel-staging apex-sentinel-staging Bot Dec 2, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No longer raised on 46a98d5.

🆕 🟡 Minor · readDeploymentLeaseScope casts client leaseBackend to LeaseBackend without validating it

A protocol-4 client posting { leaseBackend: "android-instances" } to install-from-source or release-materialized-paths gets that value typed as LeaseBackend via the as LeaseBackend | undefined cast on readStringParam, bypassing the validating readers used by sibling fields. It reaches lease admission and the registry's backend-keyed lookup as a value no schema produces, surfacing as a mismatch or empty lookup instead of INVALID_ARGS.

Suggested change

Read leaseBackend through the same validating param reader the lease RPC params use (or reuse leaseScopeFromRequest's projection), so an unsupported backend is INVALID_ARGS at the boundary.

Details

persona: javascript, maintainability

Useful? Reply @apex-sentinel-staging like, or @apex-sentinel-staging dislike <why> if it is not.

Reply @apex-sentinel-staging note ... to add context, or @apex-sentinel-staging pivot ... if it is wrong — I will re-check the cited code.

Comment on lines +40 to 46
export function resolveInstallSource(
req: DaemonRequest,
owner: Pick<LeaseScope, 'tenantId' | 'leaseId'> = { tenantId: req.meta?.tenantId },
): {
source: DaemonInstallSource;
cleanup: () => void;
} {

@apex-sentinel-staging apex-sentinel-staging Bot Dec 2, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No longer raised on 46a98d5, with the code it pointed at unchanged: withdrawn, not fixed.

🆕 🟡 Minor · resolveInstallSource's default owner drops the lease and rejects leased uploads

resolveInstallSource defaults owner = { tenantId: req.meta?.tenantId } with leaseId undefined, so prepareUploadedArtifact compares undefined against a staged entry's lease and throws ARTIFACT_LEASE_MISMATCH for uploads staged under a lease. The default parameter keeps this reachable at any call site that hasn't resolved the admitted lease.

Suggested change

Make owner a required parameter (no default) so a call site that hasn't resolved the admitted lease fails to typecheck instead of silently resolving an unscoped owner.

Details

Also raised here

Also raised at this location by persona maintainability: resolveInstallSource's default owner omits leaseId, disabling the new lease check — The new second parameter of resolveInstallSource defaults to { tenantId: req.meta?.tenantId }, which carries no leaseId, so a caller that omits it calls prepareUploadedArtifact with undefined for the lease and an upload staged under a lease is refused with ARTIFACT_LEASE_MISMATCH. Every current caller passes the owner explicitly, so nothing is wrong today; the risk is the shape of the default, which silently drops the half of the scope pair this PR just made mandatory. Require the owner argument, or build the default from the same resolveRequestOrSessionLeaseScope(req, ...) the handlers use so both fields come from one source.

persona: javascript, maintainability

Useful? Reply @apex-sentinel-staging like, or @apex-sentinel-staging dislike <why> if it is not.

Reply @apex-sentinel-staging note ... to add context, or @apex-sentinel-staging pivot ... if it is wrong — I will re-check the cited code.

@apex-sentinel-staging

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve · review of 46a98d5

Since the review of 8d5cf14: 0 new · 0 still open · 4 no longer raised (1 marked fixed)

No open findings.

🔧 1 finding marked fixed in their threads
Finding Fixed by Where
http-rpc-methods readDeploymentLeaseScope is a client-declared scope injection surface thymikee ef7540c · reply

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

💬 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.

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