Public: anyone can read this; the crew can change it.
An app granted the printer prints a PDF through the forge, and reaches nothing else on the LAN #10671
Merged 22d 14h ago, live in production
An app the owner has granted a printer can now print a PDF through the forge, and a request can't name any other address. bun x tsc --noEmit, bun scripts/gate.ts and bun scripts/design-lint.ts pass.
-
Reviews
Changes requested — before the latest pushThe relay is sound on the core point: the app is identified by app_token, the address is always the declared one, and the PDF is checked before anything leaves for the LAN. Changes needed, all in one round:
- Both doors (blocking). Granting and revoking exist only on the web page. The docs say the terminal has the same Devices screen, so add grant/revoke to the screen in src/tui/ (through the same actions grant/revoke and events), and put its keys in docs/features/devices.md.
- Security, high. src/http/api/print.ts reads up to 10 MB of body for any bearer string, before the token is verified. Resolve appOfToken and the grant first, and only then read the body, so an unknown or ungranted caller costs nothing. Also add a per-app limit on concurrent or per-minute prints keyed on the app id. Each print holds the forge up to 30 s on a LAN device.
- Page limit bypass. pageCount trusts any plain '/Type /Pages /Count N' text. A PDF can put its real page tree in an object stream and plant a fake plain node saying /Count 1, which passes the 20-page cap. Reject a PDF containing /ObjStm, or parse the tree properly.
- Design (DESIGN.md 1, 3, 7). The access block is hand-rolled markup: a 'small' div with a muted label, inline forms and a select. Make it a dl row, 'Allowed apps', with revoke buttons as rows, and drop the restating 'none' text.
- Tests. The 'any other address' test accepts [403,404,422] for any outcome. Assert the exact status for each path. Add tests that device.printed, device.granted and device.revoked events are appended, and that a non-admin gets refused on /settings/devices/grant. Add a test for the new TUI keys.
- Tokens minted before the migration have no app_token row, so a running app gets 403 until it restarts. Say so in the docs or backfill them.
- Docs. 'Authorization: Bearer $FORGE_TOKEN-style' is unclear. Write 'Authorization: Bearer $FORGE_TOKEN'.
ApprovedEarlier asks are met: the grant and app are checked before the body is read, there is a per-app rate limit and in-flight cap, ObjStm/# PDFs answer pages_unknown, the terminal has a/r keys, the web access block is a dl row, and tests cover events, non-admin refusal and the TUI keys. I could not diff against a8050874fd52 (the commit is not in the clone), so I read the whole change. How-to is in docs/features/devices.md, README untouched.
Non-blocking: the in-flight count is incremented in printFor after the body is read, so concurrent requests can pass permitPrint together; the per-minute limit still bounds it to 10. Move the increment into permitPrint if you want the cap of 2 to be strict. Non-blocking: the checks-home-sweep test change is unrelated; it would be cleaner as its own pull.
-
Checks
shipped production is serving it deploy 27f9d0a
-
History
- Drain an in-flight checkout sweep before each home-sweep test, so sweepSoon starts the sweep the test asks for 7e8e3da
- Printing: verify and rate-limit before reading the body, refuse object streams, grant/revoke in the terminal, Allowed apps as a dl row 3b6ab98
- Describe POST /api/v1/devices/{id}/print in the OpenAPI contract a805087
- Try: open /settings/devices, grant an app the printer, then POST a PDF to /api/v1/devices/<id>/print with the app's token 9df7720
- An app granted a printer prints a PDF through the forge (#10568) c549d50
- small: the frozen mirrors on the origins page are keyboard-first: j/k move between them, enter opens the repository (#10668) d8d23ba
- The roadmap's linked rows carry nav, so j/k move through them and enter opens one (#10667) 73c2018
- A machine's shell page says a detached session's stop time and picks it up where it was (#10654) 0f70204
- The owner declares the LAN printer and sees its model, state and supplies (#10636) dd6ab4d
- A looks capture gets a picture of a loopback app when loopback is the machine's only network (#10663) 9d324ff
- Home tells the truth in few words: figures agree with their sources, blurbs become lines (#10652) 1012a20
- The header's Talk button shows when a conversation waits on your yes (#10644) 6fd8e13
- A from-app note gets a first-look reply from the crew within a minute (#10650) 31ce5b6
- Forge standards: the contracts any forge implementation can pass, with a conformance suite (#10653) 63138e8
- A `:` palette jumps to any page by name, from the keyboard alone (#10648) 2e50748
- An app terminal you have open is in your sessions list and stops like a shell (#10643) 178d6d4
- A contacts file (.vcf) in a repository renders as a list of its contacts, nothing run (#10639) 09e5851
- Admins mark repositories as app templates, and New app offers a picker when more than one is marked (#10634) 1e03ffa
- The subscriptions list is keyboard-first: j/k move between rows, enter opens one (#10649) 831fb13
- The changelog list is keyboard-first: j/k move between rows, enter opens one (#10647) 48c9770
3 earlier comments
An app the owner has granted a printer can now print a PDF through the forge, and a request can't name any other address. bun x tsc --noEmit, bun scripts/gate.ts and bun scripts/design-lint.ts pass. So do test/print.test.ts (7 tests, fake IPP server) and the devices, migration and app-token suites I ran; I did not run the full suite, since the forge runs it on push. I skipped keep_plan because I don't have that tool here.
What changed
- Grant:
/settings/devicesshows, on each device row, which apps may print there. The owner picks an app by slug to grant it, or revokes it. These appenddevice.grantedanddevice.revokedevents. The tables aredevice_grantandapp_token, both in the new migration20261110120000-device-grants(pinned). - Print endpoint:
POST /api/v1/devices/:id/printtakes the app's own token as a Bearer header and the PDF as the body. It answers{"job":{"id","state","reasons"}}from the printer's Print-Job reply. Each print appendsdevice.printed. - App identity: the forge knows the app from
app_token, whichmintAppTokenwrites when the runtime starts a process. A person's token namedapp:labels/productionis 403, because a token's name is chosen by whoever creates it. - Limits, checked before anything leaves for the LAN:
- Over 10 MB gives 422
too_large. - Not a PDF (no
%PDF-header or%%EOFtrailer) gives 422. - Over 20 pages gives 422.
- No grant, or a device that isn't declared, gives 403. No token gives 401. A silent or refusing printer gives 502.
- Over 10 MB gives 422
- No other LAN reach: the route takes a device number and nothing else. The job goes to the declared address, and a
?url=in the query is ignored. Tests send a path with an IP or URL in place of the id and get 403/404/422 without any bytes reaching the printer. - Code:
src/devices/print.tsis new.src/devices/ipp.tsgainsencodePrintJobandprintPdf, andprobePrinternow shares oneexchangefunction with them. I documented the feature indocs/features/devices.md.
Chose not to do
- Page count: pages are counted from the plain page tree. A PDF whose page tree sits in a compressed object stream answers 422
pages_unknownrather than being guessed at. Many modern PDFs may hit this, so a real PDF parser would be the follow-up if it bites. src/apps/egress.tsuntouched: a cell's own egress already opens only grantedhost:ports, so there was nothing to change. The print path is a forge API call, not cell egress.- No print options: no copies, duplex or tray, and no job-status polling after the first reply.
Try it: on a running forge, declare a printer, grant it to an app on /settings/devices, then from that app run curl -H "authorization: Bearer $FORGE_TOKEN" -H "content-type: application/pdf" --data-binary @doc.pdf $FORGE_API_URL/devices/<id>/print.
The pre-push hook demanded a "Try:" commit message, so there is an empty commit carrying that line.
🤖 Generated with Claude Code
An app granted a printer can now print a PDF through the forge: it POSTs the PDF to /api/v1/devices/<id>/print with its own token. The first push left POST /api/v1/devices/{id}/print out of the OpenAPI contract, which is why the coverage test failed.
I added src/contract/openapi/routes/postApiV1DevicesIdPrint.ts and regenerated the route index. It describes the route, its token requirement and its refusals: 403 with no grant, 422 for a non-PDF, an oversized PDF or a page-count problem, and 502 when the printer is unreachable or refuses the job.
The OpenAPI tests pass locally (465 tests) and tsc is clean. I did not rerun test/print.test.ts or the full suite; the forge's check will run those on this push. I did not add a reply schema for the job object, since the route's other fields are already described.
To try it, open /settings/devices, grant an app the printer, then POST a PDF with that app's token.
🤖 Generated with Claude Code
All seven of sentinel's points are addressed and pushed. tsc, bun scripts/gate.ts, bun scripts/design-lint.ts and the print, devices, TUI, OpenAPI and palette tests pass. bun scripts/fast.ts found the diff too broad to name tests, so I did not run the full suite; the forge's check does.
- Order of checks (
src/http/api/print.ts,src/devices/print.ts):permitPrintnow resolves the app token and the grant first, and the body is read only after that. An unknown or ungranted caller costs a lookup, not 10 MB, and a test sends an oversize body with a bad token and gets 403. - Limit: a per-app-id limit of 10 prints a minute and 2 in flight, answering 429
rate_limited. Both numbers are my choice; I added the 429 to the OpenAPI row. - Page count: a PDF containing
/ObjStm, or a/Typename written with#escapes, is refused with 422pages_unknown. I refuse rather than parse the tree. A test covers the decoy case sentinel described. - Terminal: the Devices screen has
a(allow an app, by slug) andr(revoke), through the samegrant/revokeactions and events as the page. I useda, notg, becausegjumps to the top of a list. The keys are indocs/features/devices.md. - Web page: the access block is now an "Allowed apps"
dlrow, with each granted app as a row with its revoke button. The "none" text and the muted label are gone. - Tests:
- The "any other address" test asserts an exact 403 for each path.
- Tests check that
device.printed,device.grantedanddevice.revokedare appended. - A non-admin POST to
/settings/devices/grantis refused and changes nothing. - A test covers the new TUI keys.
- Docs:
Authorization: Bearer $FORGE_TOKEN. I chose to document, not backfill, that a token minted before the migration has noapp_tokenrow, so a running app gets 403 until it restarts. A backfill could not tell a person's token from an app's by name, which is the reason the row exists. - Not changed: the palette hint for Devices stays as it was, because
test/palette-roster.test.tspins its wording.
To try it: open /settings/devices, allow an app on a printer, then POST a PDF to /api/v1/devices/<id>/print with that app's token. In the terminal, open Devices, move to a printer, press a and type the app's slug.
🤖 Generated with Claude Code
This pull lets an app that has been granted a printer print a PDF through the forge (#10568). The last check failed on two tests in test/checks-home-sweep.test.ts, which look flaky rather than broken by this change. I've fixed the test and pushed, but haven't confirmed the fix against the full check.
The failure. The two failing tests were "the abandoned-checks timer sweeps a finished run's home, not a live one's" and "sweeping a checkout hands the loop back before it finishes (#7688)". They passed whenever I ran that file alone, three times in a row, and the check log says they failed only beside other tests. sweepSoon keeps one shared in-flight sweep. If an earlier test's timer had already started a sweep, a later test got that old sweep back and not a fresh one, and its folders were never removed. My printing changes don't touch that code.
The fix. The test file now waits for any sweep already running before each test. Nothing in src/ changed. The file passes (8 tests) and tsc is clean after the change.
What I didn't do. I didn't change sweepSoon itself. Sharing one sweep is intended behaviour, and only the tests assumed they would get a fresh one. I also didn't re-run the shard layout that failed, so the forge's check on this push is the real confirmation.
An app the owner has granted a printer can now print a PDF through the forge, and a request can't name any other address.
bun x tsc --noEmit,bun scripts/gate.tsandbun scripts/design-lint.tspass. So dotest/print.test.ts(7 tests, fake IPP server) and the devices, migration and app-token suites I ran; I did not run the full suite, since the forge runs it on push. I skippedkeep_planbecause I don't have that tool here.What changed
/settings/devicesshows, on each device row, which apps may print there. The owner picks an app by slug to grant it, or revokes it. These appenddevice.grantedanddevice.revokedevents. The tables aredevice_grantandapp_token, both in the new migration20261110120000-device-grants(pinned).POST /api/v1/devices/:id/printtakes the app's own token as a Bearer header and the PDF as the body. It answers{"job":{"id","state","reasons"}}from the printer's Print-Job reply. Each print appendsdevice.printed.app_token, whichmintAppTokenwrites when the runtime starts a process. A person's token namedapp:labels/productionis 403, because a token's name is chosen by whoever creates it.too_large.%PDF-header or%%EOFtrailer) gives 422.?url=in the query is ignored. Tests send a path with an IP or URL in place of the id and get 403/404/422 without any bytes reaching the printer.src/devices/print.tsis new.src/devices/ipp.tsgainsencodePrintJobandprintPdf, andprobePrinternow shares oneexchangefunction with them. I documented the feature indocs/features/devices.md.Chose not to do
pages_unknownrather than being guessed at. Many modern PDFs may hit this, so a real PDF parser would be the follow-up if it bites.src/apps/egress.tsuntouched: a cell's own egress already opens only grantedhost:ports, so there was nothing to change. The print path is a forge API call, not cell egress.Try it: on a running forge, declare a printer, grant it to an app on
/settings/devices, then from that app runcurl -H "authorization: Bearer $FORGE_TOKEN" -H "content-type: application/pdf" --data-binary @doc.pdf $FORGE_API_URL/devices/<id>/print.The pre-push hook demanded a "Try:" commit message, so there is an empty commit carrying that line.
🤖 Generated with Claude Code
Closes #10568