fix: redact client credentials from OAuth error output#2
Merged
Conversation
Procurify echoes the token request (including client_id and client_secret) back in 401 error bodies. fetchToken embedded that raw body into the OAuthError message and body, so a failed `procure login` printed both credentials in plaintext to stderr. Add sanitizeResponseText() to mask client_id, client_secret, and token/password fields before any response body is surfaced in an error, preserving the last 4 chars for diagnosability. Covered by a regression test asserting the secret and full client id never appear in the error.
|
🎉 This PR is included in version 0.1.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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.
Summary
procure loginprinted the OAuth client_id and client_secret in plaintext to stderr on a failed token request. Procurify echoes the request body back inside its 401 error response, andfetchTokenembedded that raw body into theOAuthErrormessage/.body, whichhandleErrorthen prints.Changes
sanitizeResponseText()inlib/oauth.jsthat redactsclient_id,client_secret, and token/password/assertion fields before any response body is surfaced in an error. JSON bodies are parsed and masked structurally; non-JSON falls back to regex redaction.***ibAN) so output stays diagnosable and still lines up with Procurify's own "client_id ending in ibAN" hint.err.messageorerr.body.Before vs after (same failing login):
```
before: "client_id":"nIeayneGllGyilEeFkKhBzvgFZIwibAN","client_secret":"<plaintext>"
after: "client_id":"***ibAN","client_secret":"***Yldv"
```
Note: the
--debuglog line was already masked; this closes the remaining leak in the error body.Test plan
npx jest— 136 tests pass (incl. new redaction test)npx eslint lib/oauth.js test/oauth.test.js— cleanprocure login --profile sandboxno longer prints plaintext credentials