zat.dev/zds
atproto pds · mirror of https://tangled.org/zat.dev/zds
zds 0.25.1 Latest 2 packages, all images
0
0
# shared percent decoder review — 2026-11-16
ZDS adopts `zat.percent.decodeAlloc` and `zat.percent.decodedEql` for permission-set
audiences, RPC audience comparison, and percent-encoded icon data URLs. Scope
authorization remains in ZDS. The shared decoder preserves literal `+` and decodes
once; it rejects anything other than two ASCII hex digits after `%`.
## ownership and credit
Zat already decoded `did:web` authorities and provided OAuth percent encoding.
Its authority decoder had the same malformed-escape problem as ZDS. That existing
consumer, together with ZDS's scope values, justifies the shared primitive. zttp
owns HTTP transport, not identifier or scope policy. Zig 0.17's `std.Uri` decoder
preserves malformed escapes, which is unsuitable for this rejecting boundary.
The initial design included caller-buffer decoding and form modes. Neither was
needed by these consumers; the final public surface has only the two functions
above. `zig zen` was run before implementation and during final review.
Brooke's [PR #33](https://tangled.org/zat.dev/zds/pulls/33/latest), commit
`40a58b7209fa0eba47e0906e101a31620dc9f548`, fixed encoded RPC audiences and double
encoding during permission-set expansion. Her original commit remains in history,
and its regression tests remain in ZDS. The Zat extraction credits Brooke as a
co-author. This change tightens escape validation while preserving her fix.
`std.fmt.parseInt(u8, two_bytes, 16)` accepts signs: `%+A` became newline and `%-0`
became NUL. Those are invalid escapes under
[RFC 3986 section 2.1](https://www.rfc-editor.org/rfc/rfc3986#section-2.1).
The shared iterator uses `std.fmt.charToDigit` on each digit separately. No
authorization bypass using a valid service DID was demonstrated.
## validation
- Zat's 713 tests pass, including all 65,536 possible byte pairs after `%`, exact
comparison lengths, single decoding, literal plus, binary bytes, malformed
suffixes, allocation failures, and the `did:web` consumer regression.
- The optional Hegel campaign uses a separately structured split-on-percent
oracle, valid encodings, arbitrary bytes, and eleven inserted probes per case.
Seeds 101, 202 and 303 each ran 1,000 cases: 39,000 input checks total.
Every case exercised valid, arbitrary and targeted inputs. Inputs with at least
128 decoded bytes occurred in 51.1–56.7% of cases; NUL bytes in 25.7–31.3%, and
raw plus in 23.4–28.7%. The initial generator favored short inputs; these counts
describe the revised `zat.percent.v2` generator.
- Six planted mutations were each caught on seeds 101, 202 and 303 with 100 cases:
signed hex, form-style plus conversion, accepting longer comparisons, swapped
nibbles, rejecting lowercase hex, and accepting truncated escapes. All 18 were
behavioral failures, not compilation errors. The clean baseline passed all
three seeds. Calibration used disposable source copies.
- The signed-hex mutant minimized to `%+A`. Its v2 replay blob is
`AXicY2EAAi5GEMnMAGczQYUAAsAAKw==`; replay passes against the fixed decoder.
- `just test`, `just smoke-all`, formatting, and diff checks pass in ZDS. A local
DPoP-bound proxy smoke used a mock upstream: encoded and fragment-encoded grants
forwarded; wrong services/methods/fragments, malformed and double-encoded grants
did not. Revoked tokens were refused. Include-audience and icon regressions also
reject signed escapes.
Run the shared campaign in Zat:
```sh
HEGEL_SEED=101 HEGEL_TEST_CASES=1000 zig build fuzz-percent -Dhegel --summary all
HEGEL_ZIG_REPLAY=AXicY2EAAi5GEMnMAGczQYUAAsAAKw== zig build fuzz-percent -Dhegel
```
The compiler was Zig 0.17.0 on arm64 macOS. Hegel was pinned to
`4b2bc83a5750bb872524bb97ccb0f6c45a1c3d24`; ordinary builds do not enable it.
This is bounded parser evidence, not a concurrency or whole-service fuzz campaign.
The released Zat revision is `00ad9bbc0f49f060abbe34ce0081aadf8d41bcfe`
(`v0.7.0-alpha.10`). Its main CI passed on Linux, including the ARMv6 compile.
Local `zig fetch` initially cached the archive with an extra directory level;
repacking the verified downloaded source through `zig fetch <directory>` restored
the expected package layout and the same declared hash. The dependency remains
the published release URL; no source override or alternate hash was retained.
## performance
The baseline functions came from ZDS `8494a25`. Baseline and candidate were
compiled together in ReleaseFast and alternated order across 100 paired samples.
Each comparison sample checked 600,000 operations across matching, mismatching,
plain, truncated and double-encoded audiences and asserted 200,000 matches.
Each allocating sample decoded 100,000 alternating plain/encoded audiences using
a reset fixed-buffer allocator and asserted 3,100,000 output bytes.
| operation | baseline median | candidate median | median paired ratio |
| --- | ---: | ---: | ---: |
| decoded comparison | 37 ns | 37 ns | 1.00 |
| allocated decode | 22 ns | 22 ns | 1.00 |
The laptop had unrelated concurrent workloads. Ranges were noisy, so these are
not absolute capacity claims or a claimed speedup. An initial caller-buffer API
added a small allocation-path cost; removing that unused API eliminated it in
the paired measurement. The allocator probe isolates decoding and allocation
bookkeeping, not system allocator or HTTP latency.
The required `atproto-bench` firehose workload ran twice interleaved against
`v0.7.0-alpha.9` and the candidate, using the existing 3,160-frame corpus in
disposable checkouts. All runs decoded 163,180 blocks with zero errors; throughput
varied with host load and showed no consistent candidate regression. No corpus
was captured and no production load test was run. The ZDS RPC benchmark is now
reproducible through `zig build bench-rpc-scopes -Doptimize=ReleaseFast`.
## other consumers
Stream has two form/query decoders in `src/internal/serve/filter.zig` and
`src/internal/serve/status_page.zig` with the same signed-hex issue. They should
adopt strict shared decoding with explicit raw-plus handling; URI decoding alone
is not a drop-in form decoder. ZDS's HTTP form decoder has the same follow-up.
The tolerant scope-display decoder and Stream's observability URI decoder need
their malformed-input behavior reviewed before replacement. Jetstream and Zlay
had no matching handwritten decoder in the searched sources. Their older Zat
pins do not require an unrelated upgrade for this patch.
Raw local logs and calibration/benchmark drivers are under the ignored
`bench/results/percent-review/` directory. The shared campaign and deterministic
regressions are committed with the implementation.