Repository navigation
fix(viewer): request head checks, no body before the login, agent hardening - #196
Conversation
… token dir, stderr) - mcp --task-token-file: an empty file, or one given with --url (also from IPHONE_CONTROL_URL), stops the server instead of running it outside the task; the viewer no longer passes IPHONE_CONTROL_URL/CA to its agents - request heads: the target is visible ASCII only; header names are tokens (`Content-Length : 1` and a name with blanks are 400); a line without a colon (folded or garbage) is 400 instead of skipped - token files live in the private directory's `tokens/`, beside the agent's `work/`, named with a counter, and removed if writing fails - the agent's stderr is read by bytes like its stdout - the login form is read within the head timeout (10 s), not the body's 60 s Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Review fixes (2e6152c):
Workspace: 560 tests passed, clippy, fmt. Device (iPhone 15 Pro Max iOS 27.2.1; viewer on the LAN, plain HTTP): tab target, non-ASCII target, |
…dening From a full review of main after #195: - Request heads: the target must be a path (`GET @evil.example/` made the HTTPS redirect `https://host:port@evil.example/`), no control characters or lone CR/LF (a header line in `Location`), HTTP/1.0 or 1.1 only, one Host, one Content-Length of digits only, never a length and Transfer-Encoding together. Anything else gets 400. A chunked body outside /mcp gets 411 instead of being read as empty. - Nothing of a body is read before the login, and the connection counts against its machine's limit until then: a keep-alive request read its whole body first, so 64 bodies that never came, from one machine without a token, held every place. - Video acks past what was sent are taken as all of it (u64 underflow: a panic in debug, a frozen picture in release). - Origin without a port: the scheme's default (443/80). - AI task agents: the prompt goes last after `--` (claude's -p is a flag, so a prompt starting with `--permission-mode=...` was an option); the task's token reaches the MCP server through a 0600 file (`mcp --task-token-file`, hidden) instead of the command line every user can read; notification keys and the viewer login aren't passed to the agent; output lines that aren't UTF-8 are skipped instead of ending the run, and a run that ends early stops the agent's group. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
… token dir, stderr) - mcp --task-token-file: an empty file, or one given with --url (also from IPHONE_CONTROL_URL), stops the server instead of running it outside the task; the viewer no longer passes IPHONE_CONTROL_URL/CA to its agents - request heads: the target is visible ASCII only; header names are tokens (`Content-Length : 1` and a name with blanks are 400); a line without a colon (folded or garbage) is 400 instead of skipped - token files live in the private directory's `tokens/`, beside the agent's `work/`, named with a counter, and removed if writing fails - the agent's stderr is read by bytes like its stdout - the login form is read within the head timeout (10 s), not the body's 60 s Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2e6152c to
3e5011b
Compare
What and why
P0, first batch, from a full review of
mainafter #195 (viewer and AI-task agents):Head::parse): the target must be a path.GET @evil.example/ HTTP/1.1over plain HTTP from the LAN was redirected tohttps://host:port@evil.example/, which a browser follows toevil.example; a target with a bare LF could add a line toLocation. Now: target starting with/(not//), only printable text, tabs and CRLF in the head, HTTP/1.0 or 1.1, oneHost, oneContent-Lengthof digits, never a length together withTransfer-Encoding; otherwise 400. A chunked body outside/mcpgets 411 instead of being read as empty.sent - ackedunderflowed: a panic in debug builds, a frozen picture in release; a read-only token could send it).Originwithout a port is the scheme's default (443/80).agent.rs):--; claude's-pis a flag, so a prompt starting with--permission-mode=bypassPermissionswas taken as an option;mcp --task-token-file, hidden), not the command line, which any local user can read; removed when the run ends;TG_BOT_TOKEN,BARK_KEYandIPHONE_CONTROL_VIEWER_TOKENaren't passed to the agent (the MCP server reads the settings file itself). Defense in depth only: Codex's read-only sandbox can still read the settings file, which is the user's own;Tests
1. Unit tests
cargo test --workspace --all-features --locked: 558 passed; clippy-D warnings;cargo fmt --checkfor all 11 packages;node --test tests/viewer/*.test.mjs: 36 passed;tests/check_regression_cases.py: 0 missingonly_a_plain_request_head_is_taken,a_body_is_not_waited_for_before_the_login,a_report_beyond_what_was_sent_is_taken_as_all_of_it,a_prompt_is_never_an_option_and_the_token_never_on_the_command_line; default ports inon_the_lan_its_own_names_but_no_others2. Real-device regression
--lantests/device/run.py: 16 calls, 0 failed3. Regression cases
4. Real-device proof
GET /stream?x=1→ 307 tohttps://<lan>:8202/stream?x=1as before;GET @evil.example/→ 400; a target with a bare LF → 400; twoContent-Length→ 400Content-Length: 4000with 1 byte sent: 401 at once (before: the read timeout)--permission-mode=bypassPermissions 请只调用一次 iphone_status…: run as the task's text, oneiphone_statusstep recorded for the task (so the MCP server joined it through the token file), completedBARK_KEY(the viewer's has one); the token file was gone afterwardsChecklist
mcp --task-token-fileis hidden and only the viewer uses it🤖 Generated with Claude Code