Skip to content

fix(gentime): reject out-of-range dates and zone offsets - #600

Merged
millert merged 1 commit into
sudo-project:mainfrom
jagajaga:fix/gentime-range-check
Nov 20, 2026
Merged

millert merged 1 commit into
sudo-project:mainfrom
jagajaga:fix/gentime-range-check

Conversation

@jagajaga

Copy link
Copy Markdown
Contributor

parse_gentime() does not range-check the fields of a Generalized Time string; timegm()/mktime() silently normalize them, so a typo in NOTBEFORE/NOTAFTER (or sudoNotBefore/sudoNotAfter) moves the time window and visudo does not complain.

Reproduction (there is no February 30):

$ cat sudoers.repro
root ALL = NOTAFTER=20260230235959Z /usr/bin/id

$ visudo -c -f sudoers.repro
sudoers.repro: parsed OK

$ testsudoers -T 20260301120000Z root /usr/bin/id < sudoers.repro
Command allowed                # the rule silently runs until March 2

NOTAFTER=20269999999999Z is accepted too and expires in 2034.

With this change:

$ visudo -c -f sudoers.repro
sudoers.repro:1:21: invalid notafter value

Month, day (including days that do not exist in the month), hour, minute, second and zone offset values outside the RFC 4517 ranges are rejected. Leap days, leap seconds and 24:00:00 as the end of the day (ISO 8601, which already meant 00:00:00 of the next day) are still accepted; any other hour 24 is rejected.

Compatibility: a sudoers rule with such a date becomes a syntax error, so with the default error_recovery that rule is skipped, and with error_recovery=false the file is rejected. An LDAP entry with such a date is treated as expired, as for any other invalid sudoNotBefore/sudoNotAfter value.

Testing: 21 new check_gentime cases; make check passes (47 suites, built with -fsanitize=address,undefined).

Found by comparing parse_gentime() against an RFC 4517 specification over an exhaustive set of boundary values.

parse_gentime() did not range-check the fields of a Generalized Time
string, so timegm()/mktime() silently normalized them and visudo
reported "parsed OK".  A typo in a NOTAFTER (or sudoNotAfter) value
could extend a time-limited rule, e.g.

    NOTAFTER=20260230235959Z  ->  expires March 2 (no February 30)
    NOTAFTER=20269999999999Z  ->  expires in 2034

Reject month, day (including days that do not exist in the month),
hour, minute, second and time zone offset values outside the ranges
allowed by RFC 4517.  Leap days and leap seconds are still accepted,
and so is 24:00:00 as the end of the day (ISO 8601), which already
meant 00:00:00 of the next day; any other hour 24 is rejected.  Add
the corresponding check_gentime cases.

A sudoers rule with such a date is now a syntax error: with the
default error_recovery that rule is skipped, with error_recovery=false
the file is rejected.  An LDAP entry with such a date is treated as
expired, as for any other invalid sudoNotBefore/sudoNotAfter value.

@millert millert left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, producing an error is probably better than normalizing the values.

@millert
millert merged commit 98f3337 into sudo-project:main Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants