You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Python's random is the Mersenne-Twister-based stream and is not
cryptographically secure. Knowing the previous 624 outputs of random.choices, the rest of the stream is mathematically recoverable
in O(2¹⁹) work. Today nothing else emits Mersenne bits so the stream
is unobserved, but the moment another random call exists elsewhere in
the request path (a future randomize_*() helper is foreseeable) the
seed state widens.
Why It Matters
Referral codes propagate via DMs, links, QR codes, social media. Their
predictability is a social-engineering foothold: an attacker who can
guess the codes mints tomorrow's valid referral codes for known
wallet_ids, hijacking referrals en masse.
Expected Outcome
A 16-character alphanumeric code generated from secrets.choice over a
62-symbol alphabet, with key input via secrets.token_bytes.
Acceptance Criteria
Cross-product distribution test (10k draws) yields each char with frequency 1/62 ± 0.5%.
Hypothesis test against uniform random distribution p > 0.99.
secrets.token_bytes is the source; random.random / random.choices not invoked anywhere in the function.
No measurable entropy loss (≥ 95 bits for 16 alphanumeric chars).
For higher performance under load, derive from secrets.token_bytes once:
defgenerate_random_string(length=16):
raw=secrets.token_bytes(length) # unbiased as long as 256 >= len(ALPHABET); here 256 > 62return"".join(ALPHABET[b%len(ALPHABET)] forbinraw)
Difficulty: good-first-issue · Effort: XS · Impact: every referral link
Problem Statement
quantara/web_app/api/referal.pyline 54 reads:Python's
randomis the Mersenne-Twister-based stream and is notcryptographically secure. Knowing the previous 624 outputs of
random.choices, the rest of the stream is mathematically recoverablein O(2¹⁹) work. Today nothing else emits Mersenne bits so the stream
is unobserved, but the moment another
randomcall exists elsewhere inthe request path (a future
randomize_*()helper is foreseeable) theseed state widens.
Why It Matters
Referral codes propagate via DMs, links, QR codes, social media. Their
predictability is a social-engineering foothold: an attacker who can
guess the codes mints tomorrow's valid referral codes for known
wallet_ids, hijacking referrals en masse.
Expected Outcome
A 16-character alphanumeric code generated from
secrets.choiceover a62-symbol alphabet, with key input via
secrets.token_bytes.Acceptance Criteria
secrets.token_bytesis the source;random.random/random.choicesnot invoked anywhere in the function.Implementation Notes
For higher performance under load, derive from
secrets.token_bytesonce:Files / Modules Affected
quantara/web_app/api/referal.pyquantara/web_app/tests/test_create_referal_link.pyDependencies: standalone.