Skip to content

--ports: the only ports a run may touch - #2

Merged
daniel-frenkel merged 2 commits into
mainfrom
feat/port-allowlist
Sep 25, 2026
Merged

daniel-frenkel merged 2 commits into
mainfrom
feat/port-allowlist

Conversation

@daniel-frenkel

@daniel-frenkel daniel-frenkel commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

Base: origin/main at 638a1fba596ee8944254a7ec62c9512e0d5295de, fetched and branched immediately before the commit.

Found while preparing Step 4. This machine has COM6 (Daniel's configured unit), COM15 and COM18 attached, all Espressif 303A. Bench mode as merged takes every ESP port, so a run meant for COM18 would have flashed and provisioned all three.

--ports COM18 restricts every path. It's applied inside list_ports(), the one function the GUI, console and bench mode all get their ports from, so no path can skip it.

Tests (22):

  • only the named port is listed;
  • a bench run touches only COM18, asserted on the fake esptool's log;
  • control: without --ports, all three are listed.

Sabotage: with the filter removed, exactly those 2 tests go red. After restore, 22/22 pass.

Added before merge (c36de61): the real guards

  • A local protected-MAC list at ~/.config/valar-flasher/protected-macs.json. It is never in the repo, because it names this bench's hardware. It is seeded with COM6 (Blipscope bench unit) and COM15 (Missileer test board); COM5 is added when it next appears.
    • What it does: a protected board is refused on any port, in every write path (bench, variant flash, and both chip-flash paths), all through one function.
    • How it checks: first by the USB serial number the OS already has, so a protected board is not even reset. Then again by the MAC esptool reads, before any write. Its tile goes red.
    • Fails closed: a list that exists but can't be read refuses bench mode.
  • Bench mode without --ports lists every board (port, MAC, EXCLUDED: PROTECTED) and waits for yes. It then flashes only those MACs; a board attached later is refused. The GUI does the same with a confirm dialog.
  • Two smaller fixes:
    • bench mode refuses a configured provisioner path that doesn't exist;
    • the golden-plan test now normalises line endings, so it passes on a Windows checkout.

Tests: 38. Sabotage runs:

sabotage result
protected and confirmed checks removed from bench_board 7 red, as predicted
confirmation accepts any answer 1 red, as predicted

After restore, all green.

Live read-only check on the bench machine (no port opened):

COM6     90:70:69:32:6e:64  -- EXCLUDED: PROTECTED (COM6 -- Blipscope bench unit (configured))
COM15    90:70:69:31:e9:d8  -- EXCLUDED: PROTECTED (COM15 -- Missileer test board (another product))
COM18    90:70:69:31:e2:08  -- WILL BE FLASHED AND PROVISIONED

Note that COM15 (TinyUSB) reports its serial as 90706931E9D8, with no colons. The matcher normalises both forms, and a test covers it.

🤖 Generated with Claude Code

daniel-frenkel and others added 2 commits September 24, 2026 20:22
Every Valar board is 303A, so bench mode's default of 'every ESP port' would
flash a configured unit or another project's board attached to the same
machine. The allowlist is applied inside list_ports, the one function every
flash and bench path gets its ports from. Tests: only the named port is seen;
a bench run touches only it (asserted on the fake esptool's log); control:
without --ports all three are seen. Sabotage (filter removed): 2 red.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
- A local protected-MAC list (~/.config/valar-flasher/protected-macs.json, never
  in the repo). A protected board is refused on any port and in every write path
  (bench, variant flash, both chip-flash paths): first by USB serial, so it is not
  even reset, then by the MAC esptool reads, before any write. Unreadable list =
  bench refused.
- Bench mode without --ports lists every board (port, MAC, EXCLUDED/PROTECTED)
  and waits for 'yes'; it then flashes only those MACs, and a board attached later
  is refused. GUI does the same with a confirm dialog.
- Bench refuses a configured provisioner path that does not exist.
- Golden-plan test LF-normalises, so it passes on a Windows checkout too.

Tests 38. Sabotage: checks removed from bench_board -> 7 red; confirmation that
accepts anything -> 1 red. Live read-only run of the list on the bench machine:
COM6 and COM15 EXCLUDED: PROTECTED, COM18 WILL BE FLASHED.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@daniel-frenkel
daniel-frenkel merged commit 8c547e3 into main Sep 25, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant