Skip to content

fix: review hardening for re-signing, buffers and small leaks - #187

Merged
Derrors merged 1 commit into
mainfrom
fix/review-p0-hardening
Nov 25, 2026
Merged

Derrors merged 1 commit into
mainfrom
fix/review-p0-hardening

Conversation

@Derrors

@Derrors Derrors commented Nov 25, 2026

Copy link
Copy Markdown
Owner

What and why

Phase 0 code fixes from the architecture review of 0.2.14 (high and medium findings):

  • WDA upkeep only for WDA devices. Automatic re-signing checked only device.is_some() && wda_bundle.is_some(), and the daily Apple ID session check nothing at all. wda_bundle is global, so a phone driven natively (iOS 27+) went on checking its provisioning profile, re-signing, and checking the Apple ID session (with a "session expired" warning) once another device had used WDA. Now both are skipped while the device in use is driven natively, and the round doesn't count, so after switching to a WDA device the check runs at the next tick (wda_upkeep). With no phone connected the session check still runs if WDA was ever installed.
  • After re-signing, the background WDA recorded for the device is forgotten and the supervisor is woken: the new WDA starts at once instead of up to 10 s later.
  • Size limits: WDA responses 64 MB (the Content-Length is checked before reserving; the read loop is now read_response), DTX messages 64 MB over all fragments, read as they come instead of allocating what the header claims, HEVC frames 8 MB (dropped whole, a keyframe asked for).
  • No frame assembly without subscribers: with nobody watching, the media stream only keeps the parameter sets (a new subscriber's first keyframe stays decodable); frames are still acknowledged.
  • HidSession::held_drag records the contact, so closing the session lifts the finger if the drag fails or times out.
  • Small ones: install_app clears the app cache once; LogFilter lowercases grep once instead of per entry; native screenshots say "via CoreDevice" (WDA-down fallback still "via HID"); native_terminate drops the killed pids from the frontmost-app cache; serve_mjpeg keeps the Arc it sends; viewer auth: failed() checks and counts under one lock, tokens are written through a temporary file of their own.

Not changed from the review, on purpose: TerminateApp stays outside a task's app scope (quitting an app is how an agent gets back after the user says no, tasks.rs), and ring::constant_time::verify_slices_are_equal is deprecated in ring 0.17.14 ("no promises regarding side channels"), so the hand-written comparison stays.

Tests

1. Unit tests

  • fmt (per package), cargo clippy --workspace --all-targets --all-features --locked -- -D warnings, cargo test --workspace --all-features --locked: 539 passed
  • New: wda_upkeep_is_only_for_devices_that_use_wda, oversized_responses_are_refused, the_whole_message_is_limited_not_each_fragment, unwatched_frames_keep_only_the_parameter_sets, oversized_frames_are_dropped
  • No existing test removed, ignored or loosened
  • #[ignore] tests of the changed area: none apply

2. Real-device regression

  • Devices, host: iPhone 15 Pro Max (iPhone16,2), iOS 27.2.1, native control; iPad mini 5 (iPad11,1), iPadOS 26.7.3, WDA; Debian 12
  • The device runs were made on a local branch combining this PR with the other pull requests from the same review (and a WDA keep-alive change that was then dropped); the lock scenario was also run on this branch alone (see below)
  • tests/device/run.py: iPhone 3 rounds, 48 calls, 0 failed; iPad 15 rounds, 240 calls, 0 failed
  • tests/device/scenarios.py: iPhone tools typing delivery collect editing fresh batch menu idle url 64/64 and lock 13/13; iPad tools typing delivery collect editing fresh batch menu url 60/60
  • Compared with main (run.py --repeat, compare.py): iPad 23.71 s → 24.01 s total, no step clearly slower; iPhone 17.09 s → 18.21 s, iphone_status and iphone_wait_for flagged slower on medians of 3, but main's own rounds range over the same values (status 0.02–0.29 s, wait_for 0.23–0.57 s)
  • This branch alone, iPad scenarios.py --lock lock: 3 runs, 39/39
  • Longer run: about 1.5 h of the runs above, WDA recovery after a hang, automatic unlocking on both devices

On the iPad, scenarios.py --lock lock now and then fails one lock: the IOHID power press takes 5.4 s instead of 0.4 s (XCTest waiting for the app to go idle) and the screen stays on. It happens in stretches and on main too: in the same hour main passed 7 runs and failed 1 the same way. Not caused by this change; noted in the regression notes for later.

run.py output
this branch (combined):
### iPhone16,2, iOS 27.2.1, 430x932 pt, native
--- 48 calls, 0 failed, 64.4s in all        (3 rounds; the first step includes a 10 s automatic unlock)
### iPad11,1, iOS 26.7.3, 1024x768 pt, WDA
--- 80 calls, 0 failed, 120.6s in all       (5 rounds)
--- 80 calls, 0 failed, 120.7s in all       (5 rounds)
--- 80 calls, 0 failed, 118.5s in all       (5 rounds)

main (25a0333):
### iPhone16,2, iOS 27.2.1, 430x932 pt, native
--- 48 calls, 0 failed, 52.0s in all        (3 rounds)
### iPad11,1, iOS 26.7.3, 1024x768 pt, WDA
--- 80 calls, 0 failed, 122.3s in all       (5 rounds)

3. Regression cases (docs/dev/regression-cases.md)

4. Real-device proof of the fix or feature

  • Native screenshots say "via CoreDevice" (iPhone run.py); WDA screenshots unchanged
  • Not reproducible on a device here: the size limits (no broken stream to provoke), held_drag failing halfway, the native-phone upkeep (would take a day of waiting for the session check); covered by unit tests and code review
  • Untested: a re-sign on this branch (none was due during the runs)

Checklist

  • MCP tool names, parameters and default outputs stay compatible (D10); only the "via" word of a native screenshot caption changes
  • No new dependencies
  • CHANGELOG.md and CHANGELOG.zh-CN.md (Unreleased)
  • No private data in the outputs above

🤖 Generated with Claude Code

- WDA upkeep (automatic re-signing, the Apple ID session check) only for
  devices that use WDA: skipped while the device in use is driven natively,
  and the round doesn't count, so switching to a WDA device checks at once
- after re-signing, forget the background WDA and wake the supervisor
- size limits: WDA responses 64 MB (Content-Length checked before
  reserving), DTX messages 64 MB over all fragments and read as they come,
  HEVC frames 8 MB (dropped whole, a keyframe asked for)
- media: frames nobody subscribes to only update the parameter sets, no
  copy or allocation; they are still acknowledged
- held_drag records the contact so closing the session lifts the finger
- install_app clears the app cache once; LogFilter lowercases grep once
- native screenshots say "via CoreDevice"; native_terminate drops the
  killed pids from the frontmost-app cache
- serve_mjpeg keeps the Arc it sends instead of copying each frame
- viewer auth: failed() checks and counts under one lock; tokens are
  written through a temporary file of their own

Not changed from the review: TerminateApp stays outside the task scope
(it is how an agent gets back after the user says no), and ring's
verify_slices_are_equal is deprecated in 0.17, so `same` stays.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@Derrors
Derrors merged commit 7afda12 into main Nov 25, 2026
7 checks passed
@Derrors
Derrors deleted the fix/review-p0-hardening branch November 25, 2026 02:36
Derrors added a commit that referenced this pull request Nov 25, 2026
- /mcp chunked bodies: the raw body is bounded too (the decoded 1 MB plus
  64 KB of framing; endless trailer lines or long chunk extensions got
  413 instead of growing for a minute), read in 64 KB pieces (about 16
  decoding passes for 1 MB instead of 256), and a broken chunk gets 400
  instead of a closed connection
- /mcp answers: 1xx, 204 and 304 are never sent chunked (they have no
  body, RFC 9112 6.3)
- MjpegStream errors are in the page's language (the stream ran outside
  the request's language scope)
- the scoped-task foreground check matches `Route` like the other
  dispatch sites
- a page's native video connection that closes while it waits for the
  next media stream (an unlock holds the device for seconds) no longer
  opens the stream again for nobody
- the viewer lets its port go before stopping the agents
- media.rs's comment and the changelog no longer say unwatched frames
  aren't assembled: they are depacketized and scanned, only not copied
  or queued
- CONTRIBUTING's per-package fmt list includes ictl-ax, as CI does
- the Unreleased changelog: PR numbers on every line, the iOS 17-18 disk
  image fix (#186), sections and wording per CONTRIBUTING

Not changed: a TTL in front of the token file's stat (microseconds per
request; a revoked token would keep working for the TTL).

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant