Repository navigation
Accept only ASCII digits in PINs and compare them as bytes - #49
Conversation
str.isdigit() accepts Unicode digits (e.g. Arabic-Indic), which passed PIN validation and then made hmac.compare_digest raise TypeError: a 500 that skipped the failure counters. A non-ASCII PIN in config.ini would likewise break every login. PINs are now validated as ASCII digits in one shared helper and compared as bytes. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PemRAtiBKjoZV6HkBCGDBC
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (3)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review. 📝 WalkthroughWalkthroughPIN handling now uses shared helpers to accept only 4–8 ASCII digits and to compare encoded PIN values. Storage, authentication, and migration paths use these helpers. Tests cover Unicode PIN rejection and valid ASCII PIN handling. ChangesASCII PIN handling
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Merge Risk: ⚪ Minimal · up to No actionable merge-blocking risk remains in the reviewed changes; the test fixture isolates the mutated application state. Security Architecture ReviewSecurity architecture risk: 🟡 Moderate · up to ASCII-only validation improves authentication failure handling. However, an existing Unicode PIN override can now be ignored in favor of an older config PIN, allowing someone who knows that older credential to open the configured door. This depends on legacy overlapping records; their presence in deployed installations is unknown. Retained concerns
Security review detailsSecurity Blast Radius
Security Findings and Attack Paths
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Comment |
Problem
str.isdigit()is True for Unicode digits such as"٣٣٣٣"or"²²²²". Those passedvalidate_pin_input, thenhmac.compare_digest(str, str)raisedTypeError("comparing strings with non-ASCII characters is not supported"). Result: a 500 logged asEXCEPTION, and the attempt skipped the failure counters. A non-ASCII PIN inconfig.ini [pins]would make the same call raise for every login attempt, since the loop compares against every user.Changes
is_valid_pin()(4–8 ASCII digits) andpins_equal()(bytescompare_digest) inusers_store.py, used by the keypad, the store, and the migrate endpoints in place of five inlineisdigit()checks.400 Invalid PIN formatand are counted.(The matching non-ASCII admin-password fix is part of the secrets PR #45.)
Tests
tests/test_ascii_pins.py: validator accept/reject matrix,pins_equalwith non-ASCII, store rejects Unicode PINs, Unicode PIN → counted 400, and a non-ASCII config PIN doesn't break other users' logins. Full suite passes (121),ruffclean.🤖 Generated with Claude Code
https://claude.ai/code/session_01PemRAtiBKjoZV6HkBCGDBC
Generated by Claude Code
Summary by CodeRabbit