feat(core): per-dimension identity normalization#13
Merged
Conversation
A case-insensitive login keyed on an un-normalized dimension is a lockout BYPASS: `Alice`, `alice`, and `alice ` hash to three different counters, so an attacker exceeds the limit by varying case or whitespace. The docs already warned about this; now the library provides the fix. - interfaces.ts: `Normalize` type + optional `normalize?` on LockoutPolicy — a per-dimension `Record<dimension, (value) => string>` (mirrors django-axes's per-field username callable; you normalize `username`, not `ip`). - key.ts: apply the normalizer inside deriveKeys, before hashing — so it covers check / record / reset uniformly (all route through deriveKeys). - manager.ts: thread it through; validate at construction (each entry must be a function — fail loud, not on the hot auth path). - Tests: key.spec (case/whitespace variants collapse to one key; only listed dimensions normalized; combination-key per-dimension) + manager.spec (end-to-end counter collapse; reset by any spelling; non-function rejected) + adapter (normalize threads through forRoot). 100% core coverage; the normalizer-application mutant is test-killed (hand-verified). - Docs: upgraded the existing "normalize it yourself" security note to the configurable option + the api-reference policy table. Backward compatible.
📊
|
| Metric | PR | Base | Diff | |
|---|---|---|---|---|
| Statements | ████████████████████ |
927/927 (100%) |
897/897 (100%) |
⚪ 0% |
| Branches | ████████████████████ |
159/159 (100%) |
151/151 (100%) |
⚪ 0% |
| Functions | ████████████████████ |
51/51 (100%) |
50/50 (100%) |
⚪ 0% |
| Lines | ████████████████████ |
927/927 (100%) |
897/897 (100%) |
⚪ 0% |
🧾 Changed files
| File | Statements | Branches | Diff | |
|---|---|---|---|---|
core/key.ts |
████████████████████ |
57/57 (100%) |
10/10 (100%) |
⚪ 0% |
core/manager.ts |
████████████████████ |
356/356 (100%) |
92/92 (100%) |
⚪ 0% |
Updated for ec7f238 | Compared against base branch
⏱️ Performance Report
🐢 Slowest test suites
🐌 Slowest individual tests
Updated for |
🧠 Cognitive Complexity Report
🧩 Most complex functions
🧾 Changed files
Updated for |
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 & why
Closes a real lockout bypass: with a case-insensitive login keyed on
username/email,Alice,alice, andalicehash to three different counters — so an attacker stays under the limit by varying case or whitespace. django-axes centralizes this (AXES_USERNAME_CALLABLE); authlock's docs only warned about it. Now it's a configurable control.How
Normalizetype + optionalnormalize?onLockoutPolicy— a per-dimension map.deriveKeys(before the SHA-256), so it covers check / record / reset uniformly — a lockedAliceis seen as locked underalice, andreset({ username: 'BOB' })unlocksbob.LockoutModuleOptions extends LockoutManagerOptions); added a test proving the option threads throughforRoot.Tests / gates
normalizeand behaviour is identical.Part of a 0.4.0 line (normalization +
resetAll+ audit-trail docs); no version bump in this PR — the CHANGELOGUnreleasedsection accumulates until the release.