validator.js icon indicating copy to clipboard operation
validator.js copied to clipboard

isISO8601 accepts impossible calendar dates (2021-02-30, 2021-04-31, 2021-02-29 in a non-leap year)

Open philppplik opened this issue 1 month ago • 1 comments

Describe the bug

isISO8601 checks the date components with a regex, so it rejects impossible months (00, 13) and day 00, but it does not verify that the day exists in the given month/year. Calendar-invalid dates pass:

const validator = require("validator"); // 13.15.35

validator.isISO8601("2021-02-30");        // => true (Feb has 28/29 days)
validator.isISO8601("2021-04-31");        // => true (Apr has 30 days)
validator.isISO8601("2021-02-29");        // => true (2021 is not a leap year)
validator.isISO8601("2021-13-01");        // => false (month 13 correctly rejected)
validator.isISO8601("2021-00-10");        // => false
validator.isISO8601("2021-02-00");        // => false

The library's own isDate disagrees:

validator.isDate("2021-02-30");           // => false
validator.isDate("2021-02-29");           // => false

ISO 8601 calendar dates are defined as valid Gregorian dates, so a 2021-02-30 is not a valid ISO 8601 date, and isISO8601 returning true for it makes the validator unreliable as a gate before parsing.

Note: #2841 covers the same problem for isRFC3339; this report is specifically about isISO8601, which still accepts these dates in 13.15.35.

Expected behavior

isISO8601("2021-02-30"), isISO8601("2021-04-31") and isISO8601("2021-02-29") (non-leap year) should return false.

Environment

  • validator.js: 13.15.35
  • Node.js: v22.23.3
  • OS: Linux

philppplik avatar Oct 22 '26 04:10 philppplik

Withdrawn - my report is wrong. The README documents strict: false (the default) as syntax-only validation, and strict: true correctly rejects every example I gave:

validator.isISO8601("2021-02-30", { strict: true }); // false
validator.isISO8601("2021-04-31", { strict: true }); // false
validator.isISO8601("2021-02-29", { strict: true }); // false
validator.isISO8601("2020-02-29", { strict: true }); // true (valid leap day)

So the behavior I described is the documented default mode, not a bug. Apologies for the noise - please feel free to close this.

philppplik avatar Oct 22 '26 04:10 philppplik