[Bug] Python JWT nonce uses non-CSPRNG random source
- Dominant language
- Python
- Stars
- 200
- Forks
- 191
- Avg merge
- 6h 16m
- Merged PRs (30d)
- 17
Description
## Summary
`python/cdp/auth/utils/jwt.py` generates the JWT nonce using Python's `random` module, which is NOT cryptographically secure.
## Affected Code
```python
# python/cdp/auth/utils/jwt.py
def _generate_nonce() -> str:
return "".join(random.choices("0123456789", k=16))
```
## Impact
Nonces generated with `random` are predictable. An attacker who can observe enough nonces can predict future ones, potentially enabling replay attacks against the CDP API.
## Fix
Use the `secrets` module instead:
```python
import secrets
def _generate_nonce() -> str:
return "".join(secrets.choice("0123456789") for _ in range(16))
```
The TypeScript SDK already does this correctly via `getRandomValues` from `uncrypto`.
## References
- TypeScript equivalent: `typescript/packages/cdp-sdk/src/auth/utils/jwt.ts`
- Python docs: https://docs.python.org/3/library/secrets.html
Contributor guide
Research direction
Start in python/cdp/auth/utils/jwt.py at _generate_nonce and compare the equivalent implementation in typescript/packages/cdp-sdk/src/auth/utils/jwt.ts. Replace the Python random source with the secrets-based approach described in the issue, then verify that the JWT nonce remains a 16-digit string and that the relevant Python checks pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- authentication, security
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 88/100