Replace @randyd45/curp-validation with validate-curp - #296
Draft
ricardobcl wants to merge 1 commit into
Draft
Conversation
The curp lib validated the CURP check digit, but its replacement @randyd45/curp-validation only checks the format regex, so 9 out of 10 possible check digits on any structurally-valid CURP were accepted. validate-curp (MIT, same author as validate-rfc) restores check-digit validation and additionally validates the state code and RENAPO's forbidden-word list, matching the original curp lib's behavior.
ricardobcl
force-pushed
the
bugfix/restore-curp-check-digit-validation
branch
from
August 31, 2026 15:32
e27838d to
c83f085
Compare
Prado
approved these changes
Sep 2, 2026
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.
Description
v11.0.0 replaced the GPL-licensed
curplib with@randyd45/curp-validation(#287), but the two are not equivalent:curp.validar()validated the CURP check digit, while@randyd45/curp-validation'sisFormatValid()only tests the format regex — the 18th character is matched by(\d)but never verified. Both libraries use the same regex, so the swap silently made the assert strictly more permissive.Verified empirically — same 17-character prefix, all ten possible check digits:
curp@1.2.3@randyd45/curp-validation@1.0.4SABC560626MDFLRN01(correct digit)SABC560626MDFLRN00,02…099 of 10 previously-rejected values pass v11. The check digit is a weighted mod-10 sum over the 17 preceding characters — it is what catches single-character typos and transpositions anywhere in the CURP.
This PR replaces
@randyd45/curp-validationwithvalidate-curp(MIT, same author as thevalidate-rfclib already backing theRfcNumberassert), mirroring theRfcNumberassert one-to-one.validate-curprestores check-digit validation — its algorithm is identical to the originalcurplib's (same 37-character dictionary, weights18 - i, mod 10) — and additionally validates the state code (includingNE) and RENAPO's forbidden-word list (identical tocurp's 81-wordmalasPalabraslist).Behavioral notes:
validate-rfc,validate-curpnormalizes input before validating (trim, uppercase, strip non-alphanumerics), so e.g. lowercase CURPs are now accepted — consistent with howRfcNumberbehaves today.curp.validar(), which never checked it (onlygenerar()substituted forbidden words). Genuine RENAPO-issued CURPs never carry those prefixes.Also adds a check-digit negative test — the test that would have caught this in #287.
Related issues
Follow-up to #287. Affects uphold/backend#18451.
Impacted areas
CurpNumberassert.Steps to reproduce or test
Development
yarn test523/523 passing, including the new check-digit case.
QA
N/A
Checklist
Breaking Changeif it applies.package.json.Deploy notes
Peer dependency change (
@randyd45/curp-validation→validate-curp), so the next release should be a major (v12.0.0). Consumers must swap the optional peer dependency when upgrading.