fix(channels): reject malformed Buzz key padding - #4688
Draft
RerankerGuo wants to merge 1 commit into
Draft
Conversation
Validate discarded bech32 payload bits so non-canonical npub and nsec strings cannot alias valid keys. Add fixed checksum-valid regression vectors for both key types. Signed-off-by: RerankerGuo <121015044+RerankerGuo@users.noreply.github.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 free
to 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.
Why
NIP-19 encodes a 32-byte key as 52 five-bit bech32 words. The last word has
four padding bits that must be zero, but the Buzz decoder discarded those bits
without validating them. A checksum-valid
npubornsecwith nonzero paddingwas therefore accepted as an alias of a canonical key.
For example, the malformed but checksum-valid
npub1lycg5qvjtrp3qjf5f7zl382j9x6nrjz9sdhenvyxq8c3808qxmu3875l8gwas accepted as
f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9.What changed
npubandnsec.Canonical hex,
npub, andnsecinputs are unchanged.Surface area
frontend/backend/appdocker/or sandboxed executionskills/Screenshots / Recording
Not applicable.
Bug fix verification
main: both checksum-valid malformed vectors were accepted(
34 passed, 2 failed).141 passed).Validation
cd backend && PYTHONPATH=. uv run --extra buzz pytest tests/test_buzz_nostr.py tests/test_buzz_channel.py -q- 141 passedcd backend && make testwith the Buzz extra installed -11204 passed, 72 skipped
git diff --checkpassedDuplicate check
Searched all open PR titles and bodies for
bech32,padding,npub,nsec,Buzz, andNostr; no active implementation was found.AI assistance
Tool(s) used: TRAE
How you used it: Audited the newly merged Buzz parser, generated fixed
checksum-valid malformed vectors, wrote the failing regression first, applied
the minimal decoder check, and ran focused plus full validation. I reviewed the
final diff and can explain each changed line.