Fix hashIdentifier normalization bug - #43
Conversation
…-normalization modified: package.json :wq#
…ternally inconsistent(missing terser, and yocto-queue/resolve-cwd were listed but notactually being installed), which broke npm ci and eslint/jest on aclean install. Regenerating from package.json fixes it.Also removed spurious os restrictions (aix/linux-only) that had beenadded to pretty-format, resolve.exports, and semver in the previouslockfile - those are pure-JS packages with no such restriction on thereal npm registry, and the restriction was blocking installs onWindows/macOS.
|
While working on #22 (fix/hash-identifier-normalization), I found that
I verified the actual package content (integrity hashes) matches the
Separately, the workflow itself Since the comment above this step says the comparison is meant to be Suggest: regenerate |
|
@Just-Bamford |
|
@pgreat123 Thanks for identifying this. I’ve created an issue to track the lockfile and benchmark workflow fixes. Feel free to apply for it and take it up. |
|
@pgreat123 Just leave a comment on here |
Summary
Fixes #22 —
hashIdentifierdid not normalize input before hashing, soidentifiers differing only in whitespace, case, Unicode representation,
or incidental punctuation produced different hashes, causing token
validation to fail for otherwise-identical voter identifiers.
Changes
normalizeIdentifierhelper insrc/crypto.tsthat:of the same character collapse to one)
-, or_hashIdentifiernow runs input throughnormalizeIdentifierbeforehashing. Algorithm (SHA-256) and output format (hex string) are
unchanged.
tests/crypto.test.tsfor: Unicode NFC/NFDequivalence, stripping of stray punctuation/symbols, and preservation
of hyphens/underscores — on top of the existing whitespace/case tests.
This changes hash output for any identifier that wasn't already clean
lowercase alphanumeric, not just whitespace/case variants called out
in the issue. In particular,
@and.are stripped, so anemail-shaped identifier like
alice@example.comnow hashes identicallyto
aliceexamplecom— the@and.no longer contribute to the hashat all.
If eligibility data was seeded/hashed using the old (unnormalized or
trim+lowercase-only) version, those hashes will no longer match after
this change. Per the issue's acceptance criteria, this needs to be
verified against the backend — and if identifiers are email addresses,
we may want to confirm this stripping behavior is actually desired
before merging, or existing eligibility data will need to be
regenerated.
Testing