Skip to content

fix: guard RequestManagerChange token logging against an empty token - #373

Open
mrofreP wants to merge 1 commit into
UndernetIRC:masterfrom
mrofreP:fix/request-manager-change-token-slicing
Open

mrofreP wants to merge 1 commit into
UndernetIRC:masterfrom
mrofreP:fix/request-manager-change-token-slicing

Conversation

@mrofreP

@mrofreP mrofreP commented Jul 18, 2026

Copy link
Copy Markdown

RequestManagerChange logs the confirmation token as
confirmationToken[:8]+"...". On master, GenerateSecureToken swallows a
crypto/rand failure and returns "", so confirmationToken can be empty
and ""[:8] panics -- a live path, however rare. Guard it with
confirmationToken[:min(len(confirmationToken), 8)], matching the guard
applied to the user-supplied token in ConfirmManagerChange.

The guard is kept even though it is not the root fix: once
GenerateSecureToken propagates its error (companion PR, which should
merge first), the handler returns 500 before this line and the token is
guaranteed non-empty. The guard then costs nothing and future-proofs the
log line against a change in the token source.

Caveat left as-is: the "..." suffix is unconditional, so an empty token
logs just "..." (harmless -- it leaks nothing). Collapsing all six
copies of this masking expression into a shared helper is the right
cleanup but is out of scope here.

RequestManagerChange logs the confirmation token as
confirmationToken[:8]+"...". On master, GenerateSecureToken swallows a
crypto/rand failure and returns "", so confirmationToken can be empty
and ""[:8] panics -- a live path, however rare. Guard it with
confirmationToken[:min(len(confirmationToken), 8)], matching the guard
applied to the user-supplied token in ConfirmManagerChange.

The guard is kept even though it is not the root fix: once
GenerateSecureToken propagates its error (companion PR, which should
merge first), the handler returns 500 before this line and the token is
guaranteed non-empty. The guard then costs nothing and future-proofs the
log line against a change in the token source.

Caveat left as-is: the "..." suffix is unconditional, so an empty token
logs just "..." (harmless -- it leaks nothing). Collapsing all six
copies of this masking expression into a shared helper is the right
cleanup but is out of scope here.
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

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