Skip to content

fix(providers): admit credential endpoints and bound responses - #5336

Merged
thymikee merged 4 commits into
0.22from
t3/provider-endpoint-remediation
Dec 3, 2026
Merged

thymikee merged 4 commits into
0.22from
t3/provider-endpoint-remediation

Conversation

@thymikee

@thymikee thymikee commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

Summary

provider A/provider B requests that carry credentials go only to HTTPS or loopback-HTTP endpoints and never follow redirects. Every provider response body (WebDriver hub, Revyl, provider C) is read through one bounded reader. The endpoint URL comes from user config or profile; the response bytes come from the provider.

Before / after

  • Before: credentials could be sent over cleartext public HTTP, a redirect could carry them to another host, and response.text() / arrayBuffer() / json() read unbounded provider bodies.
  • After: the credentialTransportRefusal rule (through admitCredentialDestination, including the AGENT_DEVICE_ALLOW_INSECURE_TRANSPORT override) is checked with the host env before each credentialed request. Credentialed requests use redirect: 'manual', and any 3xx gives provider_redirect_refused. Requests without credentials keep following redirects.
  • @agent-device/host-kit/response-body reads bodies with a 1 MiB budget. Successful screenshot and source answers, Revyl artifact answers, and provider catalog or app-list replies get 32 MiB. Overflow gives provider_response_too_large with the HTTP status. An oversized Revyl error body is dropped, so the status classifier still runs.
  • provider C's file download keeps createByteLimitStream (2 GiB cap). Info.plist and release manifest reads pass a 256 KiB budget.
  • The host-kit readers load on demand, so the eager module closures stay within budget.

Out of scope: long-lived streaming bodies, such as the provider C /xctest/run success stream.

Size

About 260 production lines versus 0.22.

Validation

Ran the provider package suites, packages/host-kit/src/response-body.test.ts, and scripts/__tests__/eager-closure-budgets.test.ts with vitest. All passed.

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

@blacksmith-sh

This comment has been minimized.

@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 5.29 MB 5.29 MB 0 B
Package (unpacked) 5.28 MB 5.28 MB 0 B
Package (download) 1.62 MB 1.62 MB +12 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 20.0 ms 15.2 ms -4.8 ms
CLI --help 29.9 ms 26.3 ms -3.5 ms

Affected plugins

Plugin Installed (including dependencies) Unpacked Download
@agent-device/aws-device-farm 133.2 kB → 135.3 kB (+2.0 kB) 132.8 kB → 134.8 kB (+2.0 kB) 40.6 kB → 41.4 kB (+813 B)
@agent-device/browserstack 139.7 kB → 143.0 kB (+3.4 kB) 139.2 kB → 142.6 kB (+3.4 kB) 42.3 kB → 43.6 kB (+1.3 kB)
@agent-device/harmonyos 370.0 kB → 370.0 kB (0 B) 369.6 kB → 369.6 kB (0 B) 106.2 kB → 106.2 kB (+1 B)
@agent-device/limrun 3.08 MB → 3.08 MB (+2.0 kB) 430.6 kB → 432.5 kB (+2.0 kB) 128.2 kB → 129.0 kB (+810 B)
@agent-device/linux 298.9 kB → 298.9 kB (0 B) 298.5 kB → 298.5 kB (0 B) 84.7 kB → 84.7 kB (0 B)
@agent-device/macos 226.1 kB → 226.1 kB (0 B) 225.7 kB → 225.7 kB (0 B) 64.4 kB → 64.4 kB (0 B)
@agent-device/maestro 896.5 kB → 896.5 kB (0 B) 896.0 kB → 896.0 kB (0 B) 278.2 kB → 278.2 kB (0 B)
@agent-device/replay 72.6 kB → 72.6 kB (0 B) 72.1 kB → 72.1 kB (0 B) 23.8 kB → 23.8 kB (0 B)
@agent-device/revyl 187.1 kB → 187.7 kB (+657 B) 186.7 kB → 187.3 kB (+657 B) 60.5 kB → 60.7 kB (+221 B)
@agent-device/testmu 139.2 kB → 142.6 kB (+3.4 kB) 138.8 kB → 142.2 kB (+3.4 kB) 42.8 kB → 44.2 kB (+1.4 kB)
@agent-device/tizen 100.8 kB → 100.8 kB (0 B) 100.4 kB → 100.4 kB (0 B) 35.3 kB → 35.3 kB (0 B)
@agent-device/vega 262.9 kB → 262.9 kB (0 B) 262.5 kB → 262.5 kB (0 B) 73.8 kB → 73.8 kB (0 B)
@agent-device/web 94.0 kB → 94.0 kB (0 B) 93.6 kB → 93.6 kB (0 B) 30.8 kB → 30.8 kB (0 B)
@agent-device/webos 99.6 kB → 99.6 kB (0 B) 99.2 kB → 99.2 kB (0 B) 35.0 kB → 35.0 kB (0 B)

@apex-sentinel-staging

This comment has been minimized.

@thymikee

thymikee commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

The bounded readers still let several large provider responses through at 9732d00, and credential endpoint refusals do not always carry the typed reason. All 23 checks pass at this commit, including the Coverage and closure guards that failed on the earlier head. There are no conflicts. Before merge, the findings below need fixes.

A second independent pass found that webdriver-transport.ts:296 gives every status and route the binary limit. A BrowserStack or TestMu hub can return a 2 MiB JSON reply to POST /session, or a 2 MiB error page to a session command, and the transport buffers and parses it. Ordinary WebDriver text then uses the 32 MiB budget, not the promised 1 MiB. Default to the 1 MiB text reader, let the client select the 32 MiB budget only for successful screenshot and hierarchy responses, and keep unsuccessful responses on the text budget.

A second independent pass found the same shape in revyl-client.ts:447. A screenshot or hierarchy GET that returns a 2 MiB JSON 403 or gateway 502 is read under the 32 MiB budget chosen at lines 267-274, and assertSuccess can then decode and parse it (lines 517-520 and 646-660). Apply the larger limit only to successful screenshot and hierarchy responses, and use the 1 MiB budget for every unsuccessful status.

A second independent pass found that ios-files.ts:29 still calls response.json() for GET /files/list and for the PUT used by stageFile, both through readFileReply (lines 121-125 and 164-172). A configured Limrun instance can return a multi-megabyte JSON payload there, and the 15-second deadline only stops a stalled peer. Read both replies through the shared 1 MiB body reader, keep the current signal, and let provider_response_too_large pass through the invalid-JSON handler.

A second independent pass found that ios-runner-products.ts:313 reads the whole /sync reply with response.json() before it checks needFull. A configured instance can return an array larger than 1 MiB while runner products are staged. Use the shared 1 MiB body reader for this reply and keep the typed overflow through the JSON parse handler.

A second independent pass found that ios-runner.ts:188 buffers a finite 409 or 500 body from POST /xctest/run through result.text() before it scrubs the diagnostic. The deadline bounds the wait but not the byte count. Cancel the body when only the status is needed, or read it with the shared 1 MiB cap. Keep the status-based 409 retry decision, and make the launch deadline reach the error-body read.

A second independent pass found that ios-files.ts:226 reads an Info.plist that was downloaded under the 2 GiB artifact budget (line 219), and readFile allocates the whole file before the plist parser runs. An XML plist over 1 MiB or a binary plist over 32 MiB can reach the in-memory parser. Set a metadata-specific limit before the download, and keep the abort signal and temporary-directory cleanup.

A second independent pass found that ios-runner-products.ts:163 downloads the release manifest under the 2 GiB disk budget (lines 157-162), then reads all of the JSON into memory with no signal, even if input.signal aborts after the transfer. Give the manifest download the 1 MiB text budget and pass input.signal to the manifest read. Keep the 2 GiB budget for the runner archive, and hash that archive incrementally so the disk budget stays a disk budget.

A second independent pass found that webdriver-utils.ts:64 builds the URL before admission. A malformed BROWSERSTACK_SESSION_DETAILS_ENDPOINT or TESTMU_API_ENDPOINT reaches appendUrlPath from browserstack.ts:184 or testmu.ts:229, and new URL throws before fetchProviderSessionDetails can issue provider_credential_endpoint_blocked. The TestMu app-list override reaches new URL at testmu-connection-verification.ts:109 before the same policy. No credentials leave on these paths, but callers lose the expected reason. Admit each credentialed base before appending a path or query, and keep the unauthenticated catalog URL construction independent.

A second independent pass found that webdriver-utils.ts:325 loses the redirect refusal reason. When an admitted endpoint returns a redirect during credential verification or session-details lookup, fetch correctly refuses to follow it. The handlers at lines 325-331 and 362-367 then return COMMAND_FAILED with only a network hint, so a caller cannot tell the policy refusal from a connection failure. Keep redirect targets unfetched, classify redirect responses before reading them, cancel their bodies, and pass a shared typed refusal reason through the wrappers.

A second independent pass found that webdriver-utils.ts:296 also stops redirects on the public TestMu catalog. A staging deployment configured with TESTMU_API_ENDPOINT redirects /capability/generator to its canonical path, which answers with the expected catalog. This head fails connect before the app-list request, although testmu-connection-verification.ts:53-57 sends the catalog request without credentials on purpose. Apply redirect refusal only to the credential-bearing verification call, and keep the previous fetch behavior for the public catalog request.

Not blocking, and these can be taken or left: other provider readers still buffer with response.json() (Limrun readFileReply, the runner upload reply, and the ADC client json() at provider-adc/src/client.ts:122), and a follow-up issue could enumerate them by grepping .json()/.text()/.arrayBuffer() under packages/provider-*; readResponseText in src/cli/cloud-response.ts and fetchReleaseFile in packages/apple-runner/src/runner-release-artifact.ts could delegate to readBoundedResponseBody in a second follow-up; the './response-body' export in packages/host-kit/package.json:103 is the only one that points into src/internal/, so a top-level module would match the other subpaths; PROVIDER_RESPONSE_REASONS in packages/contracts/src/facades/remote.ts:29 is the only constant defined in a file of re-exports; the transport and Revyl client import host-kit/response-body twice only to resolve one constant, so readProviderTextBody and readRevylResponseBody could take a 'text' | 'binary' kind; the redirect test at webdriver-transport.test.ts:629 could assert details.reason === 'webdriver_request_interrupted' with dispatched 'unknown'; and the PR body links two private finding URLs with no public issue, still says validation is pending although CI is green, calls Limrun's 2 GiB budget 'existing' although base had no cap, and the PR is still a draft.

The three earlier inline threads no longer apply at this head, so they can be resolved: the budgets now have one owner in host-kit (#5336 (comment)), Limrun now uses createByteLimitStream from host-kit/archive (#5336 (comment)), and Revyl delegates to readBoundedResponseBody as WebDriver does (#5336 (comment)).

Not verified here: live BrowserStack, TestMu, Revyl and Limrun runs, real response sizes against the new budgets (mainly the TestMu capability/generator catalog and BrowserStack device and app lists against 1 MiB, and the largest WebDriver page source or screenshot against 32 MiB), the test counts in the PR body, and the two private finding URLs. Live evidence is not required for this change. Base had no ceiling, so an answer above these ceilings would be a regression that no fixture can show.

@thymikee
thymikee force-pushed the t3/provider-endpoint-remediation branch from 9732d00 to e7b78bb Compare December 3, 2026 07:36
@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 e7b78bb. The verdict and the full list are in the summary comment.

@thymikee

thymikee commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

The code in e7b78bb is ready. The earlier findings from 9732d00 (#5336 (comment)) are mostly fixed: the response budgets now live in one place and the providers share them.

Not blocking: a malformed BROWSERSTACK_SESSION_DETAILS_ENDPOINT, TESTMU_API_ENDPOINT or TestMu apps endpoint still throws a bare TypeError from new URL (webdriver-utils.ts#L65) before admitCredentialedEndpoint can return insecure_credential_transport, so every credentialed base string should be admitted before any URL is built from it; and webdriver-utils.ts#L81 reads process.env directly, so the owning host env should be passed in instead, as the other provider packages do. Both can be taken or left.

CI is likely related to the second note: the layering gate rejects a process.env read in non-entry production files, and all 23 checks passed at 9732d00, before this read existed. Not verified here: the failing step, because no job log excerpt was read, and whether the changed-line coverage gate also fails, since the delta removed a test file and some new changed lines have no direct test. No conflicts are known. Before merge, CI must be green, so the env read needs to be fixed and the failing Coverage step identified.

On the open threads: the redirect thread on webdriver-transport.ts (#5336 (comment)) is lower priority and still applies, so one lower-priority thread remains. These no longer apply and can be resolved: all budgets now live in host-kit/src/response-body.ts and every provider imports them (#5336 (comment)); download-file.ts now uses createByteLimitStream (#5336 (comment)); revyl-client.ts now reads through readBoundedResponse (#5336 (comment)).

Not verified here: real response sizes against the new budgets (device and app lists and the TestMu catalog against 1 MiB, the largest page source or screenshot against 32 MiB, Info.plist against 256 KiB), and the PR body test counts.

@thymikee
thymikee marked this pull request as ready for review December 3, 2026 08:21

@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 46 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/testmu.md Resolved
Comment thread packages/host-kit/src/response-body.ts 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: 2 new findings and 1 moved to a new line on 09ad38d. The verdict and the full list are in the summary comment.

Comment thread packages/host-kit/src/response-body.ts Resolved
@thymikee
thymikee force-pushed the t3/provider-endpoint-remediation branch from 09ad38d to 8fcdee4 Compare December 3, 2026 09:11
@apex-sentinel-staging

This comment has been minimized.

…review findings

Load host-kit admission and response readers on demand, follow redirects for uncredentialed WebDriver requests, keep the response status on an oversized body, and give provider inventories the large budget.
@apex-sentinel-staging

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve · review of 18d1335

Since the review of 8fcdee4: 0 new · 0 still open · 3 no longer raised (3 marked fixed)

No open findings.

🔧 3 findings marked fixed in their threads
Finding Fixed by Where
Connect-time device catalogs get the 1 MiB budget and fail provider_response_too_large thymikee d8dec8b · reply
New shared reader in host-kit has no unit tests thymikee d8dec8b · reply
redirect:'manual' + refuseRedirect fire on uncredentialed WebDriver requests too thymikee d8dec8b · reply
Not in the reviewers' scope (1 file)
  • pnpm-lock.yaml: generated or a lockfile, so its lines were left out

1 finding below minor hidden (user_settings.min_severity).

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

💬 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 commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

The change at 18d1335 looks good, and the earlier notes from the e7b78bb review (#5336 (comment)) are now fixed or benign. The oversized non-2xx body, the credentialed-only redirect refusal, the status on too-large errors, the 32 MiB budget for verification reads, the download clamp and the new response-body tests all match what the code now does.

All 12 earlier inline threads, plus the three newer ones, are fixed at this head except one that is benign: response-body.ts:15-18 is unchanged, and every caller passes a module constant or undefined, so no input reaches an invalid maxBytes (#5336 (comment)). These can be resolved: #5336 (comment), #5336 (comment), #5336 (comment), #5336 (comment), #5336 (comment), #5336 (comment), #5336 (comment), #5336 (comment), #5336 (comment), #5336 (comment), #5336 (comment), #5336 (comment), #5336 (comment) and #5336 (comment) (this one also closes the earlier low-priority redirect thread r4781477086).

CI is green at 18d1335: 24 checks, none failing. The earlier R86 process-globals failure is gone, since no process.env read remains in provider-webdriver production code. No conflicts.

Not verified here: real provider response sizes against the 1 MiB, 32 MiB and 256 KiB budgets. The PR body's local validation and the eager-closure budget result rely on green CI and were not re-run. The review covered the changes from aa0b515 to 18d1335; the 0.22 rebase commits were treated as upstream. Nothing else must change before merge.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Dec 3, 2026
@thymikee
thymikee merged commit c88f6d4 into 0.22 Dec 3, 2026
24 checks passed
@thymikee
thymikee deleted the t3/provider-endpoint-remediation branch December 3, 2026 11:21
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