Repository navigation
fix(account): never log raw tokens, report only unexpected token failures - #11059
Merged
ArtyomSavchenko merged 2 commits intoOct 7, 2026
Merged
ArtyomSavchenko merged 2 commits into
ArtyomSavchenko merged 2 commits into
Conversation
…ures getLoginInfoByToken and getLoginWithWorkspaceInfo logged the full token on every validation failure and reported each failure to Analytics, although expired or stale session tokens are routine. getWorkspacesInfo and updateLastVisit logged the token when rejecting a non-system caller. Log a keyed fingerprint instead of the credential (omitted when no server secret is configured) together with a fixed failure reason. A TokenError is logged at warn level and not reported to Analytics, as wrap() already treats it. Any other error is logged at error level and reported as a fresh error that carries only the error class name, never the original message, stack, cause or custom fields. Status codes and responses are unchanged. Signed-off-by: Michael Uray <michaeluray@users.noreply.github.com>
Member
|
Could you also fix formatting? |
Reference the mocked Analytics.handleError through one local jest.Mock per test file instead of passing the unbound method to expect(), which tripped @typescript-eslint/unbound-method in the formatting job. Signed-off-by: Michael Uray <michaeluray@users.noreply.github.com>
Contributor
Author
|
@ArtyomSavchenko Fixed in c77b971: the new tests passed the unbound |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
getLoginInfoByTokenandgetLoginWithWorkspaceInfolog the full token wheneverit fails validation (
ctx.error('Invalid token', { token })) and report every suchfailure to
Analytics.handleError. Expired or stale session tokens are routine, sothe error reporter receives expected failures and bearer credentials end up in log
storage.
getWorkspacesInfoandupdateLastVisitlog the token the same way whenthey reject a non-system caller. The logged error message is not safe either: the
token decoder passes the underlying library message through, and a decoder message
can quote the malformed input.
Change
tokenFingerprint(token)inserver/account/src/utils.ts: 16 hex characters ofan HMAC-SHA256 over the token, keyed with a key derived from the server secret.
Logs keep a stable handle to correlate repeated failures of one token; the
credential itself is never written, and the handle cannot be recomputed without
the server secret. If no server secret is configured, no fingerprint is logged.
reportInvalidToken(ctx, token, err):TokenError(bad signature, expired, not yet active, revoked) is logged atwarn level with the fingerprint and a fixed reason (a known decoder message,
otherwise
other) and is not reported to Analytics. This matches howwrap()already treats
TokenErroras an expectedUnauthorized;name and the reason
unexpected, and is reported to Analytics as a fresh errorthat carries only the class name. The original error, its message, stack,
causeand custom fields are never passed on.responses are unchanged.
decodeTokenVerbosekeeps logging the decoded claimsof an unverifiable token, so operators lose no information.
Tests
utils.test.ts: fingerprint format, determinism, dependence on the serversecret, no fingerprint without a secret, empty input;
tokenErrorReason;reportInvalidTokenforTokenError(warn, no Analytics) and for other errors(error, Analytics with a fresh error), with adversarial cases where the raw token
is in the message, in
cause, in a custom field, in the error name, or is part ofa thrown string — asserting it appears in no log or Analytics call.
operations.test.ts: the server-token mock now exports the realTokenErrorandthe plugin default (
__esModule: true), Analytics is mocked. New cases forgetLoginInfoByToken(expired token, decoder message quoting the token, non-tokenfailure, no token),
getLoginWithWorkspaceInfoand the caller checks ofgetWorkspacesInfo/updateLastVisit; the two existing token-error tests throwTokenErrornow.