Skip to content

fix(web): fail-fast on crypto/rand + drop bare auth-token log line#66

Merged
tzone85 merged 1 commit into
mainfrom
fix/auth-token-logging-and-rand-failfast
Jun 11, 2026
Merged

fix(web): fail-fast on crypto/rand + drop bare auth-token log line#66
tzone85 merged 1 commit into
mainfrom
fix/auth-token-logging-and-rand-failfast

Conversation

@tzone85

@tzone85 tzone85 commented Jun 11, 2026

Copy link
Copy Markdown
Owner

Summary

Two web-server security hardening fixes from the 2026-06-11 audit, bundled because they sit two lines apart in the same Start path.

  • crypto/rand fallback was insecure. Failed rand.Read fell back to time.Now().UnixNano() for the 16-byte session token. A nanosecond timestamp has ~30 bits of entropy in the low-order bits and is bruteforceable in milliseconds if an attacker knows roughly when the server started. Replace with log.Fatalf so OS entropy starvation surfaces instead of silently degrading.
  • Token logged bare to stderr. log.Printf("[web] auth token: %s", token) duplicated the token into any log aggregator (Datadog/Splunk/syslog) at INFO level — far wider read surface than the operator console. The URL line immediately above already carries the token for discovery. Drop the bare line.

Test plan

  • TestServer_Start_DoesNotLogBareAuthToken captures log output during a Start/Shutdown cycle and asserts the [web] auth token: prefix never appears.
  • go build ./..., go vet ./..., go test ./... -count=1 -timeout 240s all green locally.

Audit traceability

Security findings SEC-M1, SEC-M2 (2026-06-11 sweep).

Two web-server security hardening fixes from the 2026-06-11 audit,
bundled because they sit two lines apart and share one Start path.

- crypto/rand failure used to fall back to `time.Now().UnixNano()` for
  the 16-byte session token. A nanosecond timestamp has ~30 bits of
  entropy in the low-order bits and is bruteforceable in milliseconds
  if an attacker knows roughly when the server started. Replace the
  fallback with log.Fatalf so OS entropy starvation surfaces instead of
  silently degrading to insecure tokens.
- The `log.Printf("[web] auth token: %s", token)` line duplicated the
  token into log aggregators (Datadog/Splunk/syslog) at INFO level —
  far wider read surface than the operator console. The URL line
  immediately above already carries the token for operator discovery.
  Drop the bare line.

New TestServer_Start_DoesNotLogBareAuthToken captures log output
during a Start/Shutdown cycle and asserts the `[web] auth token:`
prefix never appears.

Surfaced by the 2026-06-11 security audit (SEC-M1, SEC-M2).
@tzone85 tzone85 merged commit fe4e3bb into main Jun 11, 2026
9 of 10 checks passed
@tzone85 tzone85 deleted the fix/auth-token-logging-and-rand-failfast branch June 11, 2026 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant