fix(release): redact the token in the GitHub and GitLab release error output - #36852
fix(release): redact the token in the GitHub and GitLab release error output#36852AgentEnder wants to merge 10 commits into
Conversation
… output - The API-error output printed `Token Header Data: [object Object]`. It never leaked a token, but it read as a formatting bug and the obvious fix (`JSON.stringify`, as the adjacent `Body:` line does) would have written the bearer token to CI logs. - Print the header name with the value redacted instead, or `none` when no token was configured, so a failing release still shows which credential source was used. - Add specs for both clients asserting the token never appears in the output. Flagged by the Socket gptSecurity analysis of nx 23.1.2.
✅ Deploy Preview for nx-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for nx-dev ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
View your CI Pipeline Execution ↗ for commit 71cb8aa
☁️ Nx Cloud last updated this comment at |
… output [Self-Healing CI Rerun]
The fallback branch of handleError logged the raw error object, and an axios error carries the real token in `config.headers` and `request._header`. Dump it through util.inspect with the token value replaced by `<redacted>` instead.
… value
The dump is searched for the raw env value, but the rendered text can differ:
axios trims header values before sending, and inspect() escapes them. A token
with trailing whitespace therefore matched nothing and was printed in full,
while auth still succeeded, so the misconfiguration gave no signal.
Trim the token before searching and also redact its inspected rendering. The
trim doubles as the empty-token guard: the previous check tested tokenData,
not the token, so a blank value made split('') interleave the marker between
every character of the dump.
… value [Self-Healing CI Rerun]
The two needles coincide whenever the token has nothing for inspect() to escape, which is the normal case. The second pass then scans the whole dump again for no gain, and rewrites the marker the first pass inserted.
Node strips CR/LF from outgoing header values, so a token that picked one up (a wrapped paste into a CI variable) authenticates on the stripped form while the dump held it unredacted. Same shape as the trimming case: the sent value differs from the configured one.
|
Assigned. One thing to carry into review: this is a credential-redaction change, so what needs checking is whether every path that can surface the token is covered, not just the two error messages in the diff.
|
inspect() renders a long value carrying a line break as concatenated per-line chunks, so no whole-token needle spans it and a wrapped paste of a github_pat_ token (~93 chars) leaked. Redact each line as well, skipping fragments short enough to collide with ordinary dump text. Also covers the gaps the fix left untested: the JOB-TOKEN header, a blank token leaving the dump untouched, and the missing string-type guard on the trailing-whitespace specs.
…-Healing CI Rerun]
There was a problem hiding this comment.
Nx Cloud has identified a flaky task in your failed CI:
🔂 Since the failure was identified as flaky, we triggered a CI rerun by adding an empty commit to this branch.
🔔 Heads up, your workspace has pending recommendations ↗ to auto-apply fixes for similar failures.
🎓 Learn more about Self-Healing CI on nx.dev
Current Behavior
When creating a GitHub or GitLab release fails, the error output includes
Token Header Data: [object Object]. It doesn't leak the token today, but it reads like a formatting bug, and the obvious fix (JSON.stringify, like theBody:line next to it) would print the bearer token in CI logs.Expected Behavior
The line names the header the token was sent under, with the value redacted:
Token Header: Authorization: Bearer <redacted>, orToken Header: nonewhen no token was configured. Specs assert the token itself never appears.The unknown-error fallback right below had the same problem: it dumped the raw axios error, which carries the token in
config.headers. It now prints the error with the token value replaced by<redacted>.Related Issue(s)
Fixes #
NXC-4910, raised by https://socket.dev/npm/package/nx/alerts/23.1.2?alert_name=gptSecurity
View Polygraph session ↗