Use OS randomness for web interface session IDs - #1695
Closed
Elvand-Lie wants to merge 1 commit into
Closed
Conversation
Web interface session IDs protect CGI form submissions against CSRF. On configurations where CUPS_RAND uses a timestamp-seeded PRNG, the current construction does not provide an unpredictable session secret; the earlier CVE-2018-4700 change increased the timestamp seed's resolution but retained time-derived seeding. Generate each new session ID from 16 bytes of operating-system cryptographic randomness (rand_s on Windows, arc4random where available, raw /dev/urandom reads otherwise), preserve the 32-character hexadecimal cookie format, and remove the environment/time mixing. If secure random data cannot be obtained, terminate the CGI invocation before issuing a session cookie. Follows up on Project Zero issue 42450776 and the earlier change b9ff93c. Session-ID generation only; other random-number users are unchanged.
Member
|
This change only introduces another failure point. Many systems, particularly after bootup, lack sufficient entropy to supply the values you are trying to get. The |
Elvand-Lie
added a commit
to Elvand-Lie/cups
that referenced
this pull request
Sep 11, 2026
The web interface session ID is generated from a time-seeded PRNG mixed with REMOTE_ADDR, SERVER_NAME and SERVER_PORT. On configurations where CUPS_RAND is random(), the ID is predictable from values the requester already knows. CVE-2018-4700 improved the seed resolution but kept it time-derived; Project Zero issue 42450776 asked for real entropy. Generate the ID from 16 bytes of cupsGetRand, keeping the 32-character hexadecimal cookie format. Follow-up to OpenPrinting#1695, reworked to use cupsGetRand as suggested there.
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.
The
org.cups.sidsession cookie is the CSRF protection for the web interface. It is currently generated fromCUPS_RAND(), seeded withtv_sec + tv_usec, then MD5-hashed together withREMOTE_ADDR,SERVER_NAMEandSERVER_PORT. On Linux systems whose libc predatesarc4random(Ubuntu 22.04, RHEL 8/9, musl),CUPS_RAND()israndom()and the whole token is a function of a time-derived seed and values the requester already knows, so the ID is predictable. Even wherearc4random()is used, only 8 of its bytes are hashed together withREMOTE_ADDR/SERVER_NAME/SERVER_PORT, so this construction is an improvement there too. CVE-2018-4700 (b9ff93c) improved the seed's resolution but kept it time-derived; Project Zero issue 42450776 asked for real entropy back in 2018 and that never landed.This generates the ID from 16 bytes of OS entropy (
rand_son Windows,arc4randomwhere available, otherwise a raw/dev/urandomread with short-read and EINTR handling), keeps the existing 32-hex cookie format, and stops issuing the cookie entirely if the entropy read fails. Only session-ID generation changes; the otherCUPS_RANDusers are untouched. CHANGES.md is updated.Tested: the file compiles clean on Windows and Linux toolchains for all three code paths, and a small harness exercises the failure paths (entropy unavailable, short read, EINTR,
rand_serror: no cookie is issued; partial reads recover). Not yet run against a complete CUPS build; happy to add an in-tree CGI test if you want one.The same fix applies to master. I can open that PR or leave the port to you, whichever is easier.