Repository navigation
Fix weak session-cookie RNG fallback in cgi_set_sid() - #1752
Merged
michaelrsweet merged 1 commit intoOct 9, 2026
Merged
Conversation
michaelrsweet
requested changes
Oct 9, 2026
michaelrsweet
left a comment
Member
There was a problem hiding this comment.
Don't need the editorial about not using CUPS_RAND or the advantages of cupsGetRand.
But honestly you are overblowing the risk - the seed is microseconds and you can't send requests fast enough to successfully attack the CGI programs, and a "smart" attacker would just GET a CGI page and harvest the SID...
cgi_set_sid() in cgi-bin/var.c built the CUPS web-admin session ID (CUPS_SID cookie) using the legacy CUPS_RAND()/CUPS_SRAND() macro chain, seeded only from wall-clock time (curtime.tv_sec + curtime.tv_usec). Switch to cupsGetRand() (cups/rand.c), which is already used for other randomness in this codebase -- HTTP digest-auth nonces (http-support.c) and OAuth state bytes (oauth.c) -- for consistency, removing the now-unused gettimeofday()/curtime seeding. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
mounichalla06
force-pushed
the
fix/cgi-session-id-weak-rng
branch
from
October 9, 2026 17:12
a9ba564 to
5891f40
Compare
Author
|
Thanks — dropped the comment and trimmed to just the |
michaelrsweet
approved these changes
Oct 9, 2026
michaelrsweet
left a comment
Member
There was a problem hiding this comment.
I'm fine taking it with the changes. Thanks!
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.
Summary
cgi_set_sid()incgi-bin/var.cbuilds the CUPS web-admin session ID (CUPS_SIDcookie) from 8 bytes pulled via the legacyCUPS_RAND()macro, seeded once viaCUPS_SRAND(curtime.tv_sec + curtime.tv_usec)-- wall-clock time at microsecond resolution.CUPS_RAND/CUPS_SRANDare defined by a compile-time fallback chain inconfig.h:HAVE_ARC4RANDOMis only defined when./configuredetects a nativearc4random(). When it's absent the session ID collapses torandom()/lrand48()/rand()seeded only from wall-clock time -- an attacker who can bound the request time (e.g. from the response's ownDate:header) can brute-force the seed space and regenerate the session cookie.This isn't a narrow edge case: the pre-generated Windows build config (
vcnet/config.h) hasHAVE_ARC4RANDOM,HAVE_RANDOM, andHAVE_LRAND48all undefined, so Windows builds always land on the weakest link in the chain,rand()/srand().This was originally reported via Google (Project Zero issue tracker, bug 42450776, going back to the CVE-2018-4700 era); the same code path flagged there is still present verbatim at current
master.Fix
cups/rand.calready shipscupsGetRand(), a proper cross-platform CSPRNG for exactly this purpose:rand_s()(real OS entropy)arc4random()/dev/urandomIt's already used elsewhere in this codebase for other security-sensitive randomness -- HTTP digest-auth nonces (
http-support.c) and OAuth state bytes (oauth.c). This PR makescgi_set_sid()use the same facility instead of rolling its own weaker randomness viaCUPS_RAND()/CUPS_SRAND(), and drops the now-unusedgettimeofday()/curtimeseeding. Net -1 line, no new dependencies.Test plan
master,./configure --disable-sharedsucceedsmake -C cups libcups.abuilds cleanmake -C cgi-bin all--var.c(the only file touched) compiles with zero warnings/errors for both arm64 and x86_64 slices and archives successfully intolibcupscgi.acupsdweb-admin instance with real attacker-side cookie brute-forcing -- this is a static-analysis-driven hardening fix, not an exploit-verified PoCAI-assisted analysis and patch authored with assistance from Claude (Anthropic).
🤖 Generated with Claude Code