[PR #1093] [CLOSED] [security] generate_secret_key should use a csprng #12163

Closed
opened 2025-12-29 22:19:58 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/1093
Author: @tam7t
Created: 4/20/2017
Status: Closed

Base: developHead: security-csprng


📝 Commits (1)

  • 72be867 [security] generate_secret_key should use a csprng

📊 Changes

1 file changed (+2 additions, -4 deletions)

View changed files

📝 netbox/generate_secret_key.py (+2 -4)

📄 Description

Fixes: #1092

Original implementation used a very large seed (2048 bytes) but then performed
encoding using the insecure Mersenne Twister pseudo random number generator.
random.seed would actually take a hash of the input resulting in a much
smaller keyspace (64bits) and then biases in the insecure random number
generator could result in more predictable keys than intended.

The new implementation uses the system's cryptographically secure pseudo
random number generator (os.urandom) with 512 bits and then does a
straight encoding of that using base64, resulting in ~312 bits entropy.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbox-community/netbox/pull/1093 **Author:** [@tam7t](https://github.com/tam7t) **Created:** 4/20/2017 **Status:** ❌ Closed **Base:** `develop` ← **Head:** `security-csprng` --- ### 📝 Commits (1) - [`72be867`](https://github.com/netbox-community/netbox/commit/72be86794ed0d33f83d2ba32469a3d8263728ddb) [security] generate_secret_key should use a csprng ### 📊 Changes **1 file changed** (+2 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `netbox/generate_secret_key.py` (+2 -4) </details> ### 📄 Description <!-- Thank you for your interest in contributing to NetBox! Please note that our contribution policy requires that a feature request or bug report be opened for approval prior to filing a pull request. This helps avoid wasting time and effort on something that we might not be able to accept. Please indicate the relevant feature request or bug report below. --> ### Fixes: #1092 <!-- Please include a summary of the proposed changes below. --> Original implementation used a very large seed (2048 bytes) but then performed encoding using the insecure Mersenne Twister pseudo random number generator. `random.seed` would actually take a `hash` of the input resulting in a much smaller keyspace (64bits) and then biases in the insecure random number generator could result in more predictable keys than intended. The new implementation uses the system's cryptographically secure pseudo random number generator (`os.urandom`) with `512` bits and then does a straight encoding of that using base64, resulting in ~312 bits entropy. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-29 22:19:58 +01:00
adam closed this issue 2025-12-29 22:19:59 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#12163