5.1 KiB
5.1 KiB
S023 — The port and its protection: test file
Written by the worker that built it, run by the test phase. Nothing here has been tested until its Result says so.
Built
crates/core/src/connector/mod.rs·Connector::start(on, port) -> (Connector, Receiver<Arrival>),set(on, port)live,status(),log(),on_change;guard(Host, Origin, preflight, type),Gate(16 connections, bucket 30 + 5/s).connector/wire.rs· strict HTTP/1.1 read (head 16 KiB, body 1 MiB, Content-Length only),answer(no CORS).connector/link.rs·Body(object or list),Raw::check->Incoming,Incoming::task(&Secrets, common).connector/peer.rs· sender / listener program name from/proc/net/tcpand/proc/*/fd.crates/core/tests/connector_nacre.json· Nacre'scustom_bodyoutput, as a fixture.docs/CONNECTOR.md· format. Nothing is wired into the app yet (S024). Reach it from a test:Connector::start(true, 0), read the port fromstatus().
Checks
| # | Risk | Do this | Expect | How | Result |
|---|---|---|---|---|---|
| 1 | HIGH | Start on port 0; ss -ltn / status() |
On(p), bound on 127.0.0.1 only, nothing on 0.0.0.0 or :: |
integration | — |
| 2 | HIGH | curl POST the fixture with Content-Type: application/json |
200 {"accepted":1,"refused":[]}; one Arrival: url, name a.zip, page https://example.com/, user agent UA, secret cookies k=v, task_headers() has User-Agent and Referer, no Cookie |
integration | — |
| 3 | HIGH | Host: evil.example:p, Host: 127.0.0.1:1, two Host headers, no Host |
403 host, no Arrival, log entry Refused(Host) |
integration | — |
| 4 | HIGH | Add Origin: https://evil.example, Origin: null, Sec-Fetch-Site: cross-site, Sec-Fetch-Mode: cors (each alone) |
403 origin |
integration | — |
| 5 | HIGH | POST with application/x-www-form-urlencoded, multipart/form-data, text/plain, application/json; charset=latin1 |
415 content-type |
integration | — |
| 6 | HIGH | OPTIONS / with Access-Control-Request-Method: POST; also POST with that header |
405 preflight; no Access-Control-* header in any answer of checks 2–9 |
integration | — |
| 7 | HIGH | Link headers {"X-A":"1\r\nX-B: 2","Connection":"close","Range":"bytes=5-","Accept-Encoding":"gzip","If-None-Match":"x","Authorization":"Bearer t"} |
X-A, Connection, Range, Accept-Encoding, If-None-Match dropped (in dropped); Authorization only in secret.headers; user agent with \n dropped |
unit | — |
| 8 | HIGH | Links javascript:alert(1), file:///etc/passwd, data:,x, http://, a 9 KiB URL, https://u:p@h/f |
first five refused (scheme/invalid), last accepted as https://h/f with the login in secret |
unit | — |
| 9 | HIGH | Filename ../../.bashrc, a\u0000b, 400 chars |
made safe by http::name::safe (no slashes, no leading dot, capped) |
unit | — |
| 10 | HIGH | Incoming::task with Secrets::new(Bus::Off) |
task.secret is a task: name; secrets.load gives the cookies; task headers carry no secret (store accepts it) |
unit | — |
| 11 | HIGH | Log after checks 2–8 | entries with time, what, outcome; no cookie value, login or query string appears in any what |
integration | — |
| 12 | MED | GET / |
200 {"name":"Medlar","version":...}, not logged |
integration | — |
| 13 | MED | List of 3 links, one bad; then a list of 1001; then {}; then []; then not json |
200 accepted 2 refused index 1; 413 too-many; 422 no-links; 422; 400 body |
integration | — |
| 14 | MED | Body 1 MiB + 1; Transfer-Encoding: chunked; head of 20 KiB; open and send nothing for 6 s |
413; 411; 413; 408 or closed | integration | — |
| 15 | MED | 40 requests at once from one loop | the first ≈30 answered normally, later ones 429 busy |
integration | — |
| 16 | MED | Hold the port with another listener, start on it | Taken { by: Some(test binary name) }, words() names the port and the fix; free it: On within ~5 s |
integration | — |
| 17 | MED | set(false, p), then set(true, q) |
port closed (connect refused), then open on q; status follows | integration | — |
| 18 | LOW | Sender of check 2 | from.process is curl (a process of this user) |
integration | — |
Needs
Loopback only, ports chosen free (port 0) — never 15151 or 38151 or 17616 while the user's Medlar runs. curl for check 2. No network.
Doubts
- Never compiled beyond
cargo check; never run. The hand-written HTTP reader is the main risk: partial reads, a request split over several packets, HTTP/1.0 clients. - Nacre's request (ureq): check it sends
Host: 127.0.0.1:<port>, noOrigin, no chunked body — else check 2 passes with curl but Nacre fails. Sec-Fetch-Site: noneis let through (typed in the address bar: GET only, harmless).- Rate limit is per listener and global, so a flood also delays the real browser for a few seconds.
peer::processscans every/proc/*/fd: may be slow with many processes; it runs beside the read.Bodyis untagged: a known field of the wrong JSON type (for example"headers": []) refuses the whole body withbody.- The UI is not wired: S024 must call
Connector::start/setfrom settings and showstatus().words().