Skip to content

fix(api): mask access token in Payload.toString() - #386

Open
buongarzoni wants to merge 3 commits into
masterfrom
fix/stop-logging-access-token
Open

buongarzoni wants to merge 3 commits into
masterfrom
fix/stop-logging-access-token

Conversation

@buongarzoni

@buongarzoni buongarzoni commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Description of the change

Payload.toString() printed the access token in plain text, and RollbarBase logs the payload at
DEBUG on every event (LOGGER.debug("Payload built: {}", payload)). Turning on DEBUG logging, which
people often do while debugging an incident, wrote the token to log files and any log shipper.

toString() now masks the token and keeps only its first 6 characters, as other Rollbar SDKs do, so
you can still tell which token is configured:

Before: Payload{accessToken='fake0000000000000000000000secret', data=...}
After:  Payload{accessToken='fake00****', data=...}

Tokens of 12 characters or fewer are fully masked ('****'). A null token still prints null.
Serialization (asJson()) is unchanged, so the token is still sent to the API.

RollbarBase now logs payload.toString() instead of the Payload object, guarded by isDebugEnabled(). Structured encoders such as Logstash's (with includeNonStructuredArguments) serialize log arguments through their getters, so passing the object would still expose the full token through getAccessToken().

Type of change

  • Bug fix (non-breaking change that fixes an issue)

Checklists

Development

  • Lint rules pass locally (checkstyleMain)
  • The code changed/added as part of this pull request has been covered with tests (except the RollbarBase log call, which would need a logging backend in the test classpath)
  • All tests related to the changed code pass in development (PayloadTest)

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-13T06:17:05.482413Z e96202b PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@devtools-agent

Copy link
Copy Markdown

AI Agent Review (anthropic, CLI default model; requested openai/openai-astra)

Scrutiny: standard (public API)

With DEBUG logging turned on, the SDK writes each error report to the application log just before sending it to Rollbar. That log line included the project access token in plain text. Anyone who could read the logs could copy the token, and so could any log shipper or archive the logs went to. After this change the log line shows only **** followed by the token's last four characters. That is enough to tell which token is configured. Tokens of eight characters or fewer show as **** only, and a missing token shows as null.

The token sent to Rollbar does not change. Reports still reach the API with the full token. Only the log text is masked.

Token configured Log line before Log line after
Normal-length token full token **** + last 4 characters
8 characters or fewer full token ****
No token 'null' null

The only visible difference besides the masking is that a missing token now prints as null without quotes. Nothing in the repository depends on that text.

Conclusion: I found no blocking problem. Things I checked:

  • Where the token was logged. Within the SDK, the only place the full token reached a log was this one DEBUG line. It runs once per reported error (rollbar-java/src/main/java/com/rollbar/notifier/RollbarBase.java:349-353). The senders put the token only into the HTTP request header and do not log it (SyncSender.java:69-70, reactive-streams AsyncSender.java:46-47). Other logging that mentions payloads prints only attempt counts or exceptions. The configuration objects have no text form that could print the token.
  • What is sent to Rollbar. The data sent to Rollbar still contains the full token (Payload.java:117-119). The included test shouldReturnAsJson still expects the full token there.
  • Edge cases. An empty token is fully masked. A missing token cannot cause an error, because it is handled before the token's length is read. The new constants are static, so the saved form of reports waiting in the on-disk queue does not change.
  • Tests. The new tests cover the long-token, short-token and missing-token cases, and the expected strings match the code.

Limits. I read the tests but did not run them. I also could not confirm the author's statement that the lint check (checkstyle) passes. The new lines look like they fit within the 100-character limit.

@rollbar-rivet
rollbar-rivet Bot requested a review from matux November 16, 2026 20:01
@linear-code

linear-code Bot commented Nov 16, 2026

Copy link
Copy Markdown

CR-1168

matux
matux previously approved these changes Nov 16, 2026
waltjones
waltjones previously approved these changes Nov 18, 2026
@buongarzoni
buongarzoni dismissed stale reviews from waltjones and matux via b6dbbfd November 23, 2026 05:15
@devtools-agent

Copy link
Copy Markdown

AI Agent Review (anthropic, CLI default model; requested openai/openai-astra)

Scrutiny: standard (public API)

When debug logging is enabled, the SDK logs every event it is about to send. Previously, that log line included the full project access token, so anyone with access to the logs (or any system they were shipped to) could read it off. Since debug logging is often turned on during incident investigation, this was especially risky at exactly the wrong time. The fix truncates the token in the debug log line to the first six characters followed by **** (e.g. accessToken='asdf33****'), which still lets you identify which token is configured without exposing it. Tokens of 12 characters or fewer are fully masked ('****'), and events with no token still log null. The actual payload sent to Rollbar is unchanged and still includes the full token, so reporting behavior is unaffected. I found no blocking issues: the log line in question is the only place in the SDK that logs a built event, no other code path logs out a token, and nothing else in the codebase depends on the old log format. The change stays within the project's line-length lint limit, and new tests cover a normal-length token, the 12-character boundary case, and the no-token case (read but not executed). One minor residual note: tokens just over the 12-character cutoff will still show six characters, a large fraction of a short token, but this only affects unusually short tokens and isn't a practical concern.

@rollbar-rivet
rollbar-rivet Bot requested a review from matux November 23, 2026 05:41
matux
matux previously approved these changes Nov 24, 2026
}

/**
* Masks the token so it never ends up in logs. Keeps the first characters of long enough tokens,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor documentation issue — When Logstash records DEBUG arguments, the full token can still appear in arg0.accessToken beside the masked message.

Evidence and suggested wording

RollbarBase passes the Payload object to the logger. With includeNonStructuredArguments enabled, the Logstash encoder serializes that object separately. Its public getAccessToken() returns the full token. The option is off by default. I verified this path in source and did not run the encoder. SDK log call · Logstash argument encoder

That behavior predates this PR. The new comment says the token “never ends up in logs.” A narrower description would be “Masks the access token in the string returned by Payload.toString().”

@devtools-agent

Copy link
Copy Markdown

AI Agent Review (anthropic, anthropic-balanced; requested openai/openai-astra)

Scrutiny: standard (public API)

This PR fixes a security issue in the Java SDK where enabling DEBUG logging could leak the full Rollbar access token in plain text. Payload.toString() now masks the token, showing only the first 6 characters followed by **** for tokens longer than 12 characters, fully masking shorter tokens as ****, and still printing null when no token is set. I verified the boundary logic by hand: the 6-character prefix is only taken when the token exceeds 12 characters, so the substring call is always safe, and there's no case where more than 6 characters leak. The change is scoped to toString(); asJson(), which builds the actual payload sent to the API, is untouched, so normal item sending is unaffected.

Separately, the DEBUG log call was changed to explicitly log payload.toString() (wrapped in an isDebugEnabled() check) instead of passing the Payload object directly to the logger. This matters because some logging setups can serialize an object's fields via getters rather than its toString(), and Payload.getAccessToken() returns the token unmasked — so logging the string form closes that gap. I found no other code relying on the old toString() format and no other log call passing a Payload object directly to a logger.

I found no blocking issues. The included tests cover a normal-length token, a short (12-char) fully-masked token, and a null token, matching the scenarios described. I read these tests but did not run them. A note in the PR explains that a test for the actual log line wasn't added because it requires a logging backend in the test classpath — a reasonable, declared limitation since the core masking logic is already covered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants