Skip to content

fix(server): check printer, key and quota before fetching a payload; version 3.4.0 - #12

Merged
LukiPrince merged 3 commits into
mainfrom
fix/check-before-fetch
Nov 13, 2026
Merged

LukiPrince merged 3 commits into
mainfrom
fix/check-before-fetch

Conversation

@LukiPrince

Copy link
Copy Markdown
Owner

Follow-up to #11, found by its security review. Before this change, a *_uri job made the server fetch its URL before it checked the printer and the quota. An org with quota 0 and no printer could make the server send unlimited outbound requests, none of which counted against the quota, and could hold all 256 outbound slots with a slow URL. The label path checked first, but only for jobs without an idempotency_key.

What changes

For every job type the server fetches (raw_uri, pdf_uri, raw_uri_post, pdf_uri_post, label_uri), four checks now run before the fetch, in this order:

  1. Printer in the caller's org. If it is unknown, the 400 has the same text as before.
  2. Existing idempotency_key. A resubmit returns the original job without fetching again. While a request with a key is still in flight, a concurrent one with the same key gets 409, so a *_uri_post never hits its downstream service twice.
  3. Quota, for keyed jobs as well as unkeyed ones. Key lookup and quota check run in one DB call.
  4. Per-org download cap, set with the new PRINTAPI_FETCHES_PER_ORG. It defaults to 4 with PRINTAPI_SIGNUP=open and to no cap otherwise, so a single-org self-hosted box keeps today's behaviour. Over the cap the answer is 503.

Smaller fixes:

  • label_uri answers 503 before fetching when no render slot is free.
  • label_base64 and label_text take no download slot.
  • Job types without a fetch (*_base64) keep their order of checks exactly.

enqueue_job keeps its own checks inside the write transaction. The new checks only stop the expensive work earlier.

Docs: docs/api.md, docs/labels.md (order of checks and errors), docs/printnode-compat.md, docs/server.md (env row).

This PR also sets the version to 3.4.0 for the release that follows, which covers #11 and this PR.

Review

An adversarial review plus a Codex adversarial review (read-only) checked the change, and an independent verifier checked every finding. Six were confirmed and fixed in ab1d678. The most important: a hardcoded per-org cap would have let four hung upstream fetches block every label of a single-org production box. Three Codex findings were refuted as not caused by this change (the global pool shared by many orgs, the private-URL default, failed fetches not counting as quota).

Checks (local, at 3c22f74)

  • cargo test --workspace: 910 passed. crates/setup: 106 passed. Clippy -D warnings and fmt --check are clean.
  • Parity against v2.5.1: 785 steps, 0 unexpected diffs (26 known dashboard asset names). --db-compat: 23/23.
  • pytest tools/docs, check_docs.py, pytest agent/tests, and web lint, test and check:bundles pass.

🤖 Generated with Claude Code

https://claude.ai/code/session_01TEvvb3zrZ3bLSGJbCBaEYX

LukiPrince and others added 3 commits November 13, 2026 23:38
…ing a payload

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TEvvb3zrZ3bLSGJbCBaEYX
…guard, gate fixes

- PRINTAPI_FETCHES_PER_ORG (0 = no cap); unset: 4 with open signup, else no cap
- label_base64 takes no download slot
- key lookup and quota check in one DB closure
- an idempotency key being fetched answers 409 to a second request
- label_uri answers 503 before the fetch when no render slot is free
- docs and comments follow

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TEvvb3zrZ3bLSGJbCBaEYX
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TEvvb3zrZ3bLSGJbCBaEYX
@LukiPrince
LukiPrince merged commit 0f50982 into main Nov 13, 2026
28 checks passed
@LukiPrince
LukiPrince deleted the fix/check-before-fetch branch November 13, 2026 23:42
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