Skip to content

Commit 742f917

Browse files
committed
fix(security): rand.Read error check in session token creation
dashauth: createSession now panics on crypto/rand failure instead of silently producing weak tokens. Entropy failure is unrecoverable for a security system.
1 parent f0c1e43 commit 742f917

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

internal/dashauth/dashauth.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,12 @@ func (d *DashAuth) handleStatus(w http.ResponseWriter, r *http.Request) {
226226
// --- Session management ---
227227

228228
func (d *DashAuth) createSession(ip string) string {
229-
tokenBytes := make([]byte, tokenBytes)
230-
rand.Read(tokenBytes)
231-
token := hex.EncodeToString(tokenBytes)
229+
tokenBuf := make([]byte, tokenBytes)
230+
if _, err := rand.Read(tokenBuf); err != nil {
231+
// Entropy failure is unrecoverable for a security system
232+
panic("crypto/rand.Read failed: " + err.Error())
233+
}
234+
token := hex.EncodeToString(tokenBuf)
232235

233236
now := time.Now()
234237
d.sessions.Store(token, &Session{

0 commit comments

Comments
 (0)