fix(card): mastercard() no longer accepts non-Mastercard 2-series BINs#467
Open
Jordan-Bourillot wants to merge 1 commit into
Open
fix(card): mastercard() no longer accepts non-Mastercard 2-series BINs#467Jordan-Bourillot wants to merge 1 commit into
Jordan-Bourillot wants to merge 1 commit into
Conversation
The Mastercard 2-series range is 2221-2720, but the prefix pattern matched 22-27 (i.e. 2200-2799). Numbers in 2200-2220 and 2721-2799 were wrongly accepted as Mastercard, including Mir cards (2200-2204): the same number passed both mir() and mastercard(). Use the precise 2-series sub-ranges. The Mir test cards are now included in the mastercard negative fixtures, which they failed before this change.
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.
Summary
mastercard()accepts numbers that are not Mastercard. The Mastercard 2-series IIN range is 2221–2720, but the prefix pattern matches22|23|24|25|26|27— i.e. anything from 2200 to 2799. So2200–2220and2721–2799pass as Mastercard.This also collides with
mir(): Mir cards begin with2200–2204, so the same number is reported as both Mir and Mastercard.Reproduction
Root cause
22–27is much wider than the real 2-series range (2221–2720).Fix
Match the precise 2-series sub-ranges:
Valid Mastercard numbers (51–55 and 2221–2720) keep validating; 2200–2220 and 2721–2799 are now rejected.
Tests
test_returns_failed_on_valid_mastercardalready checks that every other network's cards are rejected bymastercard()— every list exceptmir_cards, the only omission, because those cards currently passmastercard(). This PR addsmir_cardsto that fixture: they fail onmasterand pass with the fix. The full test suite stays green andruffis clean.