feat(hash): pwned-password check (Have I Been Pwned, k-anonymity)#83
Merged
Conversation
Add a "Pwned password check" to the Hash tool — tells the user whether the text they typed has appeared in known breach corpora, so they can avoid easily cracked passwords. - src/lib/hibp.ts: pwnedPasswordCount() — SHA-1 the input locally, send only the first 5 hex chars to the HIBP range API (k-anonymity; a plain GET with no custom headers → a CORS "simple request", no preflight), and match the returned suffixes in-page. The password never leaves the browser — only a hash prefix shared by thousands of hashes does. - Explicit-trigger only (a "Check" button) per the no-silent-network rule; the result resets when the input is edited. Strips the textarea's trailing newline before checking (internal/leading spaces are preserved — passwords can contain them). - Meaning-correct wording: "found in N known breaches" vs "not found in any known breach (not a strength guarantee)" — never "safe"/"strong". 5 unit tests with an injected fetch, including the FOUND case asserted on the REAL SHA-1 of "password" so the silent-failure bugs (lowercase hex / wrong slice / prefix left in the suffix) can't pass as "not found". typecheck / lint / build clean, 208 tests green. Verified the real call end-to-end in the COEP-isolated app via headless Chrome (crossOriginIsolated=true, HTTP 200, "password" → 52,256,179, random → 0; the UI renders the breach count). EN + zh-CN strings. Co-Authored-By: Claude Opus 4.8 (1M context) <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 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.
What
A Pwned password check in the Hash tool: enter a password (text mode) and click Check to see whether it's appeared in known breach corpora — so you can avoid easily-cracked passwords. This is the rainbow-table-style "is this crackable?" check requested.
How — privacy-preserving by design
Uses the Have I Been Pwned: Pwned Passwords API with k-anonymity (
src/lib/hibp.ts):…/range/{prefix}(a plain GET, no custom headers → a CORS simple request, no preflight).The password itself never leaves the browser — the server only sees a 5-char prefix shared by thousands of hashes.
Verification
pnpm typecheck·pnpm lint·pnpm build— clean; 208 tests green.password(5BAA6/…68FD8), so the silent-failure bugs (lowercase hex, wrong slice, prefix-in-suffix — all of which look like "not found") can't pass.crossOriginIsolated=true, HTTP 200,password→ 52,256,179, a random string → 0; the UI transitions Checking… → the breach count.EN + zh-CN strings.
🤖 Generated with Claude Code