Batch A2: #13 salted secret hashing + #19 subject allowlist validation #49

Merged
amiryahaya merged 3 commits from fix/a2-credentials-and-subjects into main 2026-11-15 06:48:04 +01:00
Owner

Two authentication/issuance hardening fixes.

  • #13 (M-1): pbkdf2-sha256 (100k iter, per-hash salt) + Plug.Crypto.secure_compare; legacy sha256 hashes still verify for migration; malformed stored hashes rejected without raising
  • #19 (M-7): MyKad 12-digit serialNumber enforcement, commonName charset allowlist (Malaysian name forms), control/zero-width/bidi rejection, 64-char cap, charlist value handling

196 tests green locally (11 new).

Fixes #13
Fixes #19

Two authentication/issuance hardening fixes. - **#13 (M-1)**: pbkdf2-sha256 (100k iter, per-hash salt) + Plug.Crypto.secure_compare; legacy sha256 hashes still verify for migration; malformed stored hashes rejected without raising - **#19 (M-7)**: MyKad 12-digit serialNumber enforcement, commonName charset allowlist (Malaysian name forms), control/zero-width/bidi rejection, 64-char cap, charlist value handling 196 tests green locally (11 new). Fixes #13 Fixes #19
fix(security): salted client-secret hashing + per-attribute subject validation
All checks were successful
Lint / lint (pull_request) Successful in 2m33s
Security / Dependency advisories (mix hex.audit) (pull_request) Successful in 23s
Security / Secret scan (gitleaks) (pull_request) Successful in 11s
Unit tests / test (pull_request) Successful in 3m19s
32aa6ac628
#13 (M-1): client secrets are hashed with salted pbkdf2-sha256
(100k iterations) and compared constant-time; legacy unsalted
SHA-256 stores still verify (migration path) but the format is
never written again.

#19 (M-7): SubjectValidator moves from a weak character blacklist to
per-attribute rules — serialNumber must be a 12-digit MyKad number,
commonName restricted to a name charset (covering Malaysian a/l, a/p,
bin, binti forms), control/zero-width/bidi-override characters rejected
(U+202E name spoofing), values capped at 64 chars. New 400 mappings in
enroll/renew for the new error reasons; xmerl charlist values handled.

Fixes #13, Fixes #19
fix(security): address code-review findings on #13/#19
All checks were successful
Lint / lint (pull_request) Successful in 2m59s
Security / Dependency advisories (mix hex.audit) (pull_request) Successful in 25s
Security / Secret scan (gitleaks) (pull_request) Successful in 12s
Unit tests / test (pull_request) Successful in 3m46s
4fa64f3d2e
Review findings (two-axis + ponytail), fixed:

- BMPString/UniversalString values previously skipped ALL validation
  (empirically reproducible bypass) — now converted and validated;
  unknown ASN.1 string types and unrecognized subject shapes fail
  closed instead of passing silently
- invalid UTF-8 / T.61 teletexString bytes crashed to 500 — now
  rejected as {:invalid_subject_encoding, _} 400s
- token.ex still wrote unsalted SHA-256 via its duplicated hash_secret
  (auto-created clients) — removed, now delegates to
  ClientCredentials.hash_secret/1
- stored iteration counts honored without an upper bound — capped at
  1M (crafted stored hash = CPU hang per auth attempt)
- omitting serialNumber bypassed the MyKad rule entirely — the
  attribute is now REQUIRED
- legacy-format clients never upgraded — successful verification of a
  legacy hash now re-saves with salted pbkdf2 (measured +7ms only)
- dashed MyKad form (README-documented) now normalized and accepted;
  README error strings aligned
- six copy-pasted controller clauses collapsed into one shared
  render_subject_validation_error/2; empty commonName rejected;
  byte/character message mismatch fixed
- new failing-when-broken tests: encoding bypass, invalid UTF-8,
  iteration cap, hash upgrade, missing serial, dashed form, empty CN

MyKad checksum from the issue text: documented deviation — the format
has no checksum digit (trailing digits encode gender/place-of-birth).

Fixes #13, Fixes #19
Merge remote-tracking branch 'origin/main' into fix/a2-credentials-and-subjects
All checks were successful
Lint / lint (pull_request) Successful in 2m54s
Security / Dependency advisories (mix hex.audit) (pull_request) Successful in 23s
Security / Secret scan (gitleaks) (pull_request) Successful in 11s
Unit tests / test (pull_request) Successful in 3m41s
2f41ca60a9
Sign in to join this conversation.
No description provided.