Webfs Harden
Harden WebFS for direct public HTTP serving
Scope and success criteria
Serve the public static blog directly from the ESP32 over HTTP, optimized for browser visits and fair service across visitors. No TLS or reverse proxy is required for this release. HTTP provides no transport integrity; the hardening work targets malicious inputs, resource exhaustion and recovery.
Keep USB-only provisioning and the single 2,176 KiB WebFS partition. Internet publishing remains future work.
Connection handling and performance
-
Replace the current four-worker socket lifecycle with eight fixed socket slots. Budget their buffers, DHCP resources and task memory explicitly; require at least 20% measured memory headroom.
-
Implement explicit listening, receiving, responding, idle and closing states. Validate accepted socket state before handling requests. Retain sockets until bounded FIN/ACK completion; remove the experimental close-wait switch.
-
Support HTTP/1.1 persistent connections with sequential processing: at most eight requests per connection, one second idle between requests, and 30 seconds total connection lifetime. Preserve buffered bytes correctly; never process pipelined requests concurrently.
-
Set a three-second absolute header deadline, two-second write-progress deadline and 15-second response deadline. Give graceful close one second, then allow 250 ms for abort cleanup.
-
Cap established connections at four per source IP using a bounded table. Apply global capacity limits regardless of source address. Do not permanently ban clients or assume one address means one visitor.
- When accepted capacity is exhausted, send a bounded 503 where possible. At TCP capacity, refusal or dropping new connections is acceptable; resource growth and rebooting are not.
-
Keep flash borrows confined to synchronous reads. Yield between response chunks so one large transfer cannot monopolize execution.
-
Retain gzip, ETags and conditional GETs. Cache HTML for 60 seconds and other assets for five minutes; do not mark mutable filenames immutable. Benchmark packet coalescing and buffer sizes before changing their defaults.
Request robustness and observability
-
Separate parsing, representation selection and response transmission so deadlines and error classification apply to the correct phase.
-
Enforce the existing 2 KiB header limit, strict CRLF framing and bounded paths. Reject ambiguous framing, duplicate Host or Content-Length, Transfer-Encoding, invalid control characters and request bodies.
-
Keep GET/HEAD only. Reject write methods with 405, malformed requests with 400 and oversized headers with 431. Do not add administrative or update endpoints.
-
Preserve exact lookup and single decoding of paths; test encoded separators, traversal, malformed escapes, gzip quality values and conditional responses.
-
Add bounded counters for admission rejection, header timeout, write stall, close timeout, parser rejection and TCP errors. Diagnostic events include connection ID, remote tuple and uptime.
-
Make serial logging optional and bounded. Serving must work without a console reader, including after attachment and detachment. Do not expose diagnostics over the network.
-
Keep only TCP port 80 externally reachable. Any eventual router configuration must account for IPv4 and IPv6; development testing does not automatically open Internet access.
Validation and release gates
-
Establish a fresh baseline using the actual 92-file blog. Measure complete page loads, individual asset latency, transferred bytes, failures and memory occupancy.
-
Add host tests for persistent connections, fragmented and pipelined input, cancellation, partial writes and deadlines. Fuzz the parser and image reader, retaining regression cases.
-
Test four simulated visitors with two connections each. Every successful response must match the stored representation exactly. Target p95 page-load time no worse than baseline, with zero unexpected transport failures under this admitted workload on a healthy LAN.
-
Repeat concurrency 1, 2, 4, 8, 16 and 32 three times. Above capacity, require bounded rejection and recovery within five seconds after load stops.
-
Exercise slow headers, slow readers, half-open connections, malformed requests and reconnect storms. Correlate packets with device events and kernel traces; resolve the intermittent read- error mechanism before qualification.
-
Require a 24-minute mixed-traffic soak without unexpected reboot or resource leakage, plus Wi-Fi recovery, DHCP renewal, ten unattended cold boots and 100 console attach/detach cycles.
-
Record measured capacity rather than promising protection against floods that saturate the Wi- Fi link or Internet connection.
Delivery and future publishing
Build and test natively in the existing FreeBSD jail, preserve a private rollback image, flash through USB and commit the qualified changes locally in Fossil. Update webfs-harden.md, webfs- perf.md and the operator instructions with results and remaining limits.
Future Internet publishing must be a separate design. It needs authenticated publication, replay protection, bounded uploads and failure-safe activation. The current single-partition layout cannot provide dual-image rollback; decide its storage strategy before adding any writable network endpoint. No publishing credentials or dormant update handler will be introduced in this release.
Implementation checkpoint — 2026-09-11
Review of the previous uncommitted implementation found worker tasks exiting after
30 seconds, ineffective per-IP admission, discarded pipelined input, shared mutable
ETag storage, and disabled HTTP tests (http.rs.bak). The device at its last known
address, 192.168.3.225, refused HTTP connections during the review; the deployed image
has not yet been identified, so this is not proof of the outage mechanism.
The repair now keeps workers alive across connections, bounds each accepted session separately, and uses an admission guard to increment/decrement the shared IPv4 table. HTTP input persists per connection, response ETags are owned, oversized fields are rejected instead of truncated, Connection: close is honored, and the eighth response closes the connection. Write progress resets its deadline after each successful partial write. HTML uses 60-second caching and other assets use 300 seconds.
Native FreeBSD tests passed: 8 packer, 6 format, and 8 HTTP tests (22 total), including restored allocation checks, all fragmentation sizes for a two-request pipeline, independent response metadata, and partial writes. The host timer thread is initialized before the allocation assertion; request handling is still checked for zero allocations. The initial repaired firmware compiled successfully. Locked dependency builds have been restored; a complete rebuild after diagnostic accounting edits is in progress.
This is implementation progress, not release qualification. Hardware flash/recovery, admission and deadline measurements, parser/image fuzzing, memory headroom, realistic page-load comparison, overload/recovery, packet correlation, and the full 24-minute soak, Wi-Fi/DHCP and console/cold-boot gates remain open. The existing benchmark additions also need replacement with real slow-client and malformed-input tests.
Hardware repair verification — 2026-09-11 01:48–01:52 UTC
The complete locked native build passed all 22 tests and produced a 509,040-byte
application / 574,576-byte merged firmware image. SHA-256 of firmware.bin:
ca14bb3f0a4f52f1fb9247112b30edde6dec9f1ecc8a4fa294a842af39c3cf8f.
Artifact directory on the host:
/usr/local/bastille/jails/esp32c3/root/build/artifacts.
Identified /dev/cuaU1 as Espressif USB Serial/JTAG, ESP32-C3 QFN32 revision 0.4,
4 MiB XMC flash, MAC 90:70:69:ad:77:f4. Saved a private full-flash backup at
/usr/local/bastille/jails/esp32c3/root/build/artifacts/pre-harden-v5-20260911T0148.bin.
Its firmware prefix matches the previous 22:17 build exactly, and its WebFS bytes
match the supplied 92-file blog. This identifies the old deployed binary, but does
not by itself prove how the outage occurred.
Firmware-only commands used (the merged image includes its bootloader and partition table):
doas esptool --chip esp32c3 -p /dev/cuaU1 -b 460800 write-flash 0 \
/usr/local/bastille/jails/esp32c3/root/build/artifacts/firmware.bin
doas esptool --chip esp32c3 -p /dev/cuaU1 -b 460800 verify-flash 0 \
/usr/local/bastille/jails/esp32c3/root/build/artifacts/firmware.bin
Both automatic write verification and explicit verification passed. The existing
WebFS partition was preserved. HTTP resumed at 192.168.3.225.
- All 92 stored assets matched exactly: 3.894 seconds total with two test workers; slowest asset 0.903 seconds. This is functional validation, not a p95 benchmark.
- POST/PUT/DELETE/PATCH on removed publishing paths returned 405; GET returned 404; HEAD returned 200 without a body.
- Eight requests sent in one pipeline returned identical expected representations; responses 1–7 advertised keep-alive and response 8 advertised close, followed by EOF.
- Nine probes over 45.2 seconds all succeeded, crossing the old worker-exit threshold.
- Four confirmed admitted same-IP connections held partial next headers; a fifth connection received 503. Recovery after closing the held connections took 1.129 seconds. The test first confirms a HEAD response on each held connection to avoid mistaking a TCP handshake for application admission.
These are initial repair checks only. Diagnostic completeness and serial boot capture remain open, as do the performance, fuzzing, memory and endurance gates.
Qualification work in progress — 2026-09-11
Added and passed native tests for cancellation with partial header retention, an actual stalled-write deadline, and 100,000 deterministic parser mutations (25 host tests total). Mutation testing is bounded and reproducible; coverage-guided fuzzing and format mutation campaigns are not yet complete.
Replaced the old benchmark's nonfunctional slow-client stubs with a bounded wrk
matrix runner (scripts/diagnostics/benchmark.py) and a separate real socket test
(scripts/diagnostics/adversarial-device.py). The matrix records each raw wrk result,
process deadline and recovery measurement. It runs inside the jail; Python is
python3.12, not python3 on this installation. Concurrency above four from one
source intentionally exceeds its quota and is an overload test.
The v5 matrix exposed non-success responses even at concurrency four (26 in its first trial). Closing connections retained their admission quota while waiting for FIN completion. Source now releases that quota when close starts, allowing a browser replacement connection. This change is not yet hardware verified. v6 also adds remote tuples and sampled heap minima to diagnostics, limits emission to eight events plus worker summaries per ten seconds, and enables diagnostics by default. A locked build is in progress; the device is still running v5 while its matrix finishes.
The v5 matrix completed all 18 trials. Raw logs and summary are archived at
webfs-perf-results/2026-09-11/harden-v5/matrix/. Worst recovery was 0.817 seconds.
| v5 concurrency (one source) | Requests/sec, three runs | Non-2xx/3xx, three runs |
|---|---|---|
| 1 | 15.46 / 14.64 / 14.77 | 0 / 0 / 0 |
| 2 | 30.51 / 26.97 / 28.23 | 0 / 0 / 0 |
| 4 | 51.81 / 49.05 / 52.26 | 26 / 28 / 66 |
| 8 | 64.87 / 61.38 / 75.07 | 352 / 375 / 512 |
| 16 | 54.51 / 67.63 / 63.95 | 409 / 509 / 494 |
| 32 | 45.70 / 42.97 / 61.01 | 351 / 272 / 358 |
Rates include rejected responses and must not be interpreted as successful blog throughput. No socket errors occurred at c1/c2/c4. Higher concurrency produced read and write errors; c32 run 2 also reported one timeout. Packet/kernel correlation is still required. The c4 response failures prevent admitted-workload qualification.
Real socket checks passed for duplicate Host, duplicate Content-Length, bodies, Transfer-Encoding, encoded traversal and bare LF (400), oversized headers (431), and removed update POST (405). A header dripped continuously closed after 3.019 seconds; the subsequent health check succeeded.
v6 locked build passed all 25 tests. Application size 511,536 bytes, firmware SHA-256
a1504a50edde8d3491b5e71ca6dd03973795b53d13e63e817cc939c2e02df10d.
Flashing and hardware regression of v6 are underway. The private v5 rollback image
is retained under jail /build/harden-v5-qualified-repair/; despite that directory
name, v5 has not passed Internet release qualification.
v6 first hardware regression
Flashed and explicitly verified the 577,072-byte merged v6 image. The first c4/15s trial returned 621 responses (41.16 requests/sec), with no wrk socket errors or non-2xx/3xx responses. A subsequent HTTP probe returned 200. This is one trial; it does not establish a performance improvement or satisfy the full matrix gate.
Serial diagnostics are active and include worker/connection/remote tuple/error counts. Observed sampled minimum heap free: 48,952 bytes of the configured 98,304-byte heap. This does not account for full static/task/stack headroom or allocations between samples. Full memory qualification remains open. Early boot output was incomplete because the collector attached after reset; a complete boot capture remains required.
Build, flash and c4 evidence is archived in
webfs-perf-results/2026-09-11/harden-v6/. Next work: repeat admitted workloads,
correlate overload socket failures, complete memory accounting and fuzzing, then run
endurance/recovery/console/cold-boot gates. The source is still uncommitted pending
review; no claim of full Internet qualification is made.