Skip to content

Use OS randomness for web interface session IDs - #1695

Closed
Elvand-Lie wants to merge 1 commit into
OpenPrinting:2.4.xfrom
Elvand-Lie:sid-os-randomness
Closed

Use OS randomness for web interface session IDs#1695
Elvand-Lie wants to merge 1 commit into
OpenPrinting:2.4.xfrom
Elvand-Lie:sid-os-randomness

Conversation

@Elvand-Lie

@Elvand-Lie Elvand-Lie commented Sep 11, 2026

Copy link
Copy Markdown

The org.cups.sid session cookie is the CSRF protection for the web interface. It is currently generated from CUPS_RAND(), seeded with tv_sec + tv_usec, then MD5-hashed together with REMOTE_ADDR, SERVER_NAME and SERVER_PORT. On Linux systems whose libc predates arc4random (Ubuntu 22.04, RHEL 8/9, musl), CUPS_RAND() is random() and the whole token is a function of a time-derived seed and values the requester already knows, so the ID is predictable. Even where arc4random() is used, only 8 of its bytes are hashed together with REMOTE_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_s on Windows, arc4random where available, otherwise a raw /dev/urandom read 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 other CUPS_RAND users 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_s error: 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.

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.
@michaelrsweet michaelrsweet self-assigned this Sep 11, 2026
@michaelrsweet michaelrsweet added the investigating Investigating the issue label Sep 11, 2026
@michaelrsweet

Copy link
Copy Markdown
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 cupsGetRand function in CUPS 2.5 is what you want to use, and for 2.4.x we can decide whether it matters.

@michaelrsweet michaelrsweet added the wontfix This will not be worked on label Sep 11, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

investigating Investigating the issue wontfix This will not be worked on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants