Skip to content

Commit d734e61

Browse files
authored
fix: reject non-digit characters in valid_cc_number() (#10580)
1 parent 3bb0f3b commit d734e61

3 files changed

Lines changed: 12 additions & 2 deletions

File tree

‎system/Validation/CreditCardRules.php‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,7 @@ public function valid_cc_number(?string $ccNumber, string $type): bool
199199
// Remove any spaces and dashes
200200
$ccNumber = str_replace([' ', '-'], '', $ccNumber);
201201

202-
// Non-numeric values cannot be a number...duh
203-
if (! is_numeric($ccNumber)) {
202+
if (! ctype_digit($ccNumber)) {
204203
return false;
205204
}
206205

‎tests/system/Validation/StrictRules/CreditCardRulesTest.php‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,16 @@ public static function provideValidCCNumber(): iterable
100100
'abcd efgh ijkl mnop',
101101
false,
102102
],
103+
'decimal_point_visa' => [
104+
'visa',
105+
'41.1111111111111',
106+
false,
107+
],
108+
'decimal_point_mastercard' => [
109+
'mastercard',
110+
'5351367.37861108',
111+
false,
112+
],
103113
'bad_length' => [
104114
'amex',
105115
'3782 8224 6310 0051',

‎user_guide_src/source/changelogs/v4.7.5.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ Bugs Fixed
5959
- **Honeypot:** Fixed a bug where bot detection returned an HTTP 500 response instead of 403 (Forbidden).
6060
- **I18n:** Fixed a bug where ``Time::today()``, ``Time::yesterday()``, and ``Time::tomorrow()`` ignored the specified ``$timezone`` and ``setTestNow()`` when calculating the day.
6161
- **Logger:** Fixed a bug where interpolating a log message with array or non-stringable context values could raise PHP warnings or errors.
62+
- **Validation:** Fixed a bug where ``valid_cc_number`` accepted non-digit characters (e.g., a decimal point) in the card number. Such values could pass the Luhn check and triggered an ``Undefined array key`` warning inside it; the number is now checked with ``ctype_digit()``.
6263

6364
See the repo's
6465
`CHANGELOG.md <https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md>`_

0 commit comments

Comments
 (0)