Repository navigation
Conversation
13 tasks done
- pages carry a Content-Security-Policy naming their own inline scripts by hash; every answer sends Referrer-Policy: no-referrer; answers and event stream writes time out (30 s) - Origin is checked against the scheme served (HTTPS on: http only from this machine; off: no https) - the viewer's certificate, key and names.json are written atomically, names last, so a stop halfway makes a new pair instead of a mismatched one - the tokens file is watched by (time, length, inode); token commands hold a flock while they read, change and write - the env file: a key's last value wins; saves use a temporary file of their own; `mcp --task-token-file` skips IPHONE_CONTROL_URL/CA from it - services: paths with spaces are quoted, `$`, backquotes and `%` refused; a paused viewer service is started again without enabling it; a failed update job setup removes what it wrote - stale task token files are cleared when the viewer starts - a read-only page sends no touches from the picture Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ask-token-file, /mcp writes) - Turning the update job off unloads it as far as it can: when systemctl or launchctl fails (often why setting it up just failed) the unit, timer, plist and launcher written here still go, and the error comes after. - `clear_stale_tokens` only removes token files of this process or of one that is gone: the directory is shared by every viewer of the user. - `mcp --task-token-file` (or `=FILE`) is found after the root options, for `mcp` only, from the raw arguments (non-UTF-8 ones don't panic). - `/mcp` writes its answer and each event within the write limit, and sends Referrer-Policy like every other answer; so do the redirect and the MJPEG stream; `linger` bounds its shutdown (TLS close_notify) by its second. - `write_atomic` makes a new temporary file each time and sets its mode; the token lock retries on EINTR; the page is built once; `https` reused. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Derrors
force-pushed
the
fix/p1-viewer-host
branch
from
November 25, 2026 16:34
e389e96 to
4c34761
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
P1, third batch, from the full review of
mainafter #195: the viewer and the host's configuration.Content-Security-Policy: default-src 'none'; script-src 'sha256-…'(each of their own inline scripts by hash, worked out from the page as served, so each language gets its own),style-src 'unsafe-inline'(the page setsstyleattributes), andimg-src 'self' data: blob:; connect-src 'self'; media-src 'self' blob:; base-uri 'none'; form-action 'self'; frame-ancestors 'none'. Every answer, stream and redirect sendsReferrer-Policy: no-referrer./api/agent/tasks/{id}/eventsor/open, is limited to 30 s (write_timed). A client that read nothing held its connection's place for good.origin_allowedtakestls. With HTTPS on,https://origins are accepted, andhttp://only for the loopback names (the network is redirected to HTTPS). With it off, onlyhttp://, since this server serves no HTTPS page.names.json, which makes the pair reused, is removed first and written last: a stop halfway used to leave a new key beside the old certificate, reused, and "the certificate and key don't match" on every start after.(modified, len, ino): on file systems with whole seconds, a token removed within the same second as another change stayed valid (each save is a new file renamed into place, so the inode always changes);add,renewandremove(and the firstload) hold aflockonviewer-tokens.lockacross read, change and write.load_into_processtakes a key's last value (an empty last one leaves it unset), as systemd and the shell read the file; it used to take the first;savewrites a temporary file of its own (create_new, pid and counter) instead ofenv.tmp.--task-token-fileon the command line,IPHONE_CONTROL_URL/CAfrom the settings file are skipped. They made the viewer's agent MCP fail onconflicts_with = "url"(review of fix(viewer): request head checks, no body before the login, agent hardening #196). Stale token files are cleared when the viewer starts (review of fix(viewer): request head checks, no body before the login, agent hardening #196: PID reuse).ExecStart="…", whichmanagedalready recognises), and$, backquotes,%, quotes, backslashes and control characters are refused (check_exe);resume_viewer(andpause_viewer's fallback) usesstart_managed, notenable --now, which turned the viewer's start at login back on;Tests
1. Unit tests
cargo test --workspace --all-features --locked: 587 passed; clippy-D warnings;cargo fmt --checkfor all 11 packages;node --test tests/viewer/*.test.mjs: 37 passed;tests/check_regression_cases.py: 0 missingpages_allow_only_their_own_scripts,a_client_that_reads_nothing_is_let_go,a_pair_written_halfway_is_made_again,a_removed_token_is_noticed_within_the_same_second,tokens_added_at_once_are_all_kept,the_last_value_of_a_key_wins,service_program_paths; scheme cases inon_the_lan_its_own_names_but_no_others; stale token clearing ina_prompt_is_never_an_option_and_the_token_never_on_the_command_line;a read-only page sends no finger and says so once in a whileorigin_allowedandaction_allowedcalls gained thetlsargument)2. Real-device regression
--lan(HTTPS)tests/device/run.py: 16 calls, 0 failed3. Regression cases
4. Real-device proof
Headless Chromium (zenika/alpine-chrome, against the deployed viewer):
/api/info, rendered 5 times, and the picture status changed from the static "正在连接…" to the script's "正在连接画面…";data-scheme.A control page with a script the policy doesn't name showed "Refused to execute inline script" and kept its static text, so a violation would have shown.
With HTTPS on,
POST /api/button:Origin: http://192.168.10.100:8202→ 403;https://192.168.10.100:8202andhttp://127.0.0.1:8202→ 200A settings file (temporary
HOME) withIPHONE_CONTROL_URL:mcp --task-token-filestarted (it then ended on its closed stdin), where it used to stop on the conflict;mcpwith the same file used that URL;--urlgiven with the token file is still refused.Six
viewer token addat once (temporary data directory): all six keptNot tried:
Checklist
🤖 Generated with Claude Code