Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/readings-window/blob/main/AUDIT_SCOPE.md # readings-window aien-dev/readings-window Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `readings-window / AUDIT_SCOPE.md` 120 lines ยท 6494 bytes Raw Blame History Rendered 1 # Audit scope 2 3 Written for an outside, independent security audit. Revision described: 4 ``c6e2ab34598303f2d9f72bf1194e19074bdf51a6`` on `main`, 2026-10-26. Everything below is taken from the repository's own files at 5 that revision; items marked NOT_RUN were not executed while writing this document. 6 7 ## What this repository is 8 9 A small Rust service, plus a shell exposure watch, that runs on the project's house server. 10 `readings-window collect` fetches one JSON line of GPU and CPU readings from the development 11 machine over ssh and keeps 30 days of history. `readings-window serve` listens on `0.0.0.0:9443` 12 with TLS and serves `/health` without a token and every `/v1/*` route to holders of a bearer 13 token. Code: `src/main.rs` (561 lines) and `src/tls.rs` (380 lines, the TLS listener and a 14 hand-written HTTP/1.1 head reader that replaced `tiny_http`). `scripts/exposure-watch.sh` (98 15 lines) with a systemd `.service` and `.timer`. `spark.conf.example` documents the ssh target file. 16 Licence AGPL-3.0-or-later. 17 18 ## What to review, in priority order 19 20 1. Authentication (`auth_ok`, `ct_eq`, `handle` in `src/main.rs`). `Authorization: Bearer ` 21 is trimmed and compared with a fold over XOR after a length check. `serve` refuses to start with 22 a token shorter than 32 characters. Check every `/v1/*` route sits behind the check and that 23 `/health` reveals nothing sensitive (it returns `status`, `last_reading_age_s`, `exposure`). 24 2. Remote command construction (`chat_route`, `chat_command`, `clamp_lines`, `fetch`, 25 `spark_ssh`). The remote command string is built from constant paths in the `AGENTS` table and 26 a clamped integer; `?all=1` switches to `cat` of a constant path or glob. ssh runs with 27 `BatchMode=yes`, `ConnectTimeout=5`, optional `-i `, then the target, then the 28 command. Targets and identity come from the root-owned `/etc/readings-window/spark.conf`, read 29 on each fetch, with no shell expansion. Check that no request byte reaches the remote command, 30 and the effect of a config value beginning with `-`. 31 3. HTTP and TLS (`src/tls.rs`): `parse_head`, the head deadline reader, `MAX_HEAD` 16 KiB, 32 `MAX_CONNS` 64, one thread per connection, read and write timeouts. NOTES.md records that the 33 handshake and header deadlines do not bound ssh execution or total response time, and that 34 `?all=1` on a large file is a big response (UNVERIFIED under load). 35 4. Response validation of fetched data (`validate`, `validate_status`, `validate_results`, 36 `validate_exposure`) before it is cached and served. 37 5. History handling (`collect`, `ts_of`, `clamp_hours`: default 24, max 720 hours; `KEEP_SECS` 38 30 days) and file writes under `/var/lib/readings-window/`. 39 6. `scripts/exposure-watch.sh`: gets the public IP from an external echo service (with a DNS 40 fallback), runs `nmap` TCP and UDP scans against that IP only, lists UPnP mappings with `upnpc`, 41 checks that named DNS records resolve to the public IP (`EXPOSURE_DNS_HOSTS` overrides the 42 list), and builds the JSON result with `printf`. Check quoting of values interpolated into that 43 JSON and that the scan target cannot be redirected. 44 45 ## Trust boundaries 46 47 - Untrusted: every HTTPS client and request byte; unauthenticated callers reach `/health` and the 48 401, 404 and 405 paths. 49 - Trusted: the token, key and certificate files under `/etc/readings-window/`, the ssh target file 50 and identity, and the remote machine's output after validation. 51 - The service runs as root on the server (README); the remote ssh account runs the fixed read 52 commands. 53 - The exposure watch trusts the external IP echo service and DNS for the IP it scans. 54 55 ## Threat model summary 56 57 - Assets: the bearer token; confidentiality of the chat feeds and readings; the remote machine 58 (only read commands reach it). 59 - Attackers considered: unauthenticated network clients; slow or malformed TLS and HTTP clients 60 (tests cover fragmented handshakes and incomplete records against the head deadline); a token 61 holder trying to inject into the remote command. 62 - Defended: token check on `/v1/*`, allow-listed agent names, clamped integers, head size and 63 connection caps, deadlines, rustls only. 64 - Not defended / explicitly out of scope: a token holder can request full chat histories (by 65 design); concurrent chat requests can start concurrent ssh processes (NOTES.md); the exposure 66 watch sees the LAN hairpin view, not the internet view (README). No rate limiting per client is 67 described in the repository. 68 69 ## Build from source at a pin 70 71 Needs a stable Rust toolchain (version not pinned). `Cargo.lock` committed (68 packages). 72 73 ```sh 74 cargo build --release 75 ``` 76 77 Dependencies: `rustls` 0.23.46 (no default features; `ring`, `std`, `tls12`), `serde_json` 1; 78 dev-dependency `rcgen` 0.14 for the TLS tests. 79 80 ## Run every test 81 82 NOT_RUN while writing this document. From AGENTS.md: 83 84 ```sh 85 cargo test # unit tests in src/main.rs and src/tls.rs 86 cargo clippy --all-targets # lint 87 bash -n scripts/exposure-watch.sh 88 ``` 89 90 AGENTS.md says 20 tests; the tree at this revision has 26 `#[test]` attributes (18 in 91 `src/main.rs`, 8 in `src/tls.rs`), so expect `test result: ok` with the count cargo prints. 92 `cargo fmt --check` does not pass on the current tree (AGENTS.md). 93 94 Do not run `collect`, `serve` or `scripts/exposure-watch.sh` on a development machine: `collect` 95 needs root, the server's ssh key and the remote machine; `serve` needs the token, key and 96 certificate and binds port 9443; the exposure watch scans a public IP and writes under `/etc` and 97 `/var/lib`. NOT_RUN. 98 99 ## Known limitations and NOT_RUN 100 101 - No CI. 102 - Behaviour under load UNVERIFIED (NOTES.md). 103 - Exposure watch findings marked UNVERIFIED in NOTES.md (hairpin vantage; one UDP port reported 104 `open|filtered`). 105 - `/health` does not prove the remote fetch works (README). 106 - Deployed binary, units, token and baseline are outside the repository and not checkable here. 107 108 ## Dependencies and provenance 109 110 - `Cargo.lock` present; crates fetched from crates.io. 111 - AGENTS.md: advisory-driven dependency updates are separate commits naming the advisory (for 112 example `RUSTSEC-2026-0382`); `tiny_http` was removed because it pinned a rustls with an 113 advisory. 114 - Run-time host tools: `ssh`; for the exposure watch `curl`, `dig`, `nmap`, `upnpc`, `timeout`. 115 - No GitHub Actions. 116 117 ## Evidence 118 119 No receipts are stored in this repository. `NOTES.md` records deployment layout, feed history and 120 unverified points.