Uh oh!
There was an error while loading. Please reload this page.
fix(dig-node): add bounded non-injectable shape hint for rejected peer ids (#107) - #176
Merged
Merged
Conversation
Co-Authored-By: Claude <noreply@anthropic.com>
…r ids (#107) A peer-supplied id that fails is_canonical_hex_id logs the fixed NON_CANONICAL sentinel (correct: an attacker-writable log is not evidence, #1603) but that erased the difference between a nearly-right id (a 63-hex typo, a 0x-prefixed key) and pure garbage. Emit a bounded, non-injectable shape hint alongside the sentinel: len=<N> plus charset=<hex|hex+prefix|non-hex>, derived from the raw value but echoing none of its bytes. A closed Charset enum + an integer length keep the amplification/forgery guarantees of the bare sentinel. The classify logic is one pure helper (IdShapeHint) reused by both serve-log reject paths (dig.fetchRange via ServeTarget's SafeId fields, dig.getAvailability via SafeId::new), so both gain the hint DRY. Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes dig-node#107. A peer-supplied identifier that fails
is_canonical_hex_idcurrently logs only the bare<non-canonical>sentinel — correct for security (an attacker-writable log is not evidence, #1603) but it loses debug signal for a nearly-right id (63 hex chars, an0xprefix, a typo). This adds a bounded, non-injectable shape hint alongside the sentinel, computed from the raw value but echoing none of its bytes.The change (single DRY helper, both paths)
Charsetclosed enum —Hex/HexPrefix/NonHex— withof(raw)classifying by alphabet andtag()→ fixed source-literal strings.IdShapeHint { len, charset }whoseDisplayrenders exactlylen=<N> charset=<tag>and nothing else can appear in its output.SafeId::Display's non-canonical arm now renders<non-canonical> len=<N> charset=<tag>. Because both serve-log reject paths render ids throughSafeId—dig.fetchRangeviaServeTarget'sSafeIdfields anddig.getAvailabilityviaSafeId::new(...)— this one edit covers both (and every otherSafeIdlog site). TheABSENTand canonical-64-hex arms are unchanged.Vocabulary:
len=<integer char count>+charset ∈ {hex, hex+prefix, non-hex}. A rejected id now renders e.g.<non-canonical> len=63 charset=hex.Security property (the point of the ticket)
The hint is fixed-vocabulary — only a decimal length + one of three enum tags. No byte, substring, or transformed form of the input can appear, preserving the forgery/amplification properties (#1603) the sentinel was chosen for.
How verified (TDD)
shape_hint_echoes_no_byte_of_a_hostile_id— feeds a hostile id (control chars, apeer_id=…newline-forgery payload, an RTL override, a path, a NUL) and asserts the emitted hint equals exactlylen=<count> charset=non-hex— pinning the whole output, so any regression folding a raw substring in fails. Non-vacuous.shape_hint_reports_length_and_charset_from_the_alphabet—63-hex → len=63 charset=hex,0xABCDEF → hex+prefix,not-a-root → non-hex, bare0x → non-hex.both_serve_log_reject_paths_emit_the_shape_hint— asserts the hint on the fetchRangeServeTargetfields AND the getAvailabilitySafeIdrender.cargo test -p dig-node-core --lib→ 667 passed, 0 failed (664 baseline + 3). fmt +clippy -D warningsclean; build OK.Blast radius
SafeId::Displayis consumed only at logging call sites; the change is additive log-output on the already-rejected branch — no control-flow, signature, or caller-logic impact (risk LOW). Note: the DRY win means the hint also enriches themodule_serve/module_reshare/module_anchor/module_transportSafeIdlog sites — a strict improvement, but any log-scraper keying on a bare<non-canonical>should switch to a prefix match. NoSPEC.md/SYSTEM.md/docs change (internal diagnostic log format, not a wire/contract).Version
root
[workspace.package].version0.93.7 → 0.93.8 (patch,fix:);Cargo.lockregenerated.Generated by Claude Code