A value that looks like a secret is made with rand, whose output can be predicted
What it finds
session->token = rand();: rand and random are generators whose whole state can be worked out from a few outputs, and are often seeded with the time. Keys, tokens, salts and nonces need a cryptographic source such as getrandom or arc4random.
The result must be stored, directly or in an expression, in a variable or field whose name has a part such as key, token, secret, nonce, salt or password.
From the rule's source, predictable_random_secret.rs.
#include <stdlib.h> struct session { int token; int count; }; void make(struct session *s){ int session_key = rand();tx0 reports: session_key is made with rand, whose output can be predicted s->token = rand() % 1000;tx0 reports: token is made with rand s->count = rand(); (void)session_key;} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/c:predictable-random-secret" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/c:predictable-random-secret] reason="..."tx0 explain tx0/c:predictable-random-secret shows the same in the terminal. Found a false positive? Report it.