Skip to content

Commit 453b88e

Browse files
fix(cmd/login): mask SSO tokens and sanitize callback URL in logs
The oauth2login function logged the raw access token and refresh token directly via log.Printf, making them visible in any terminal or CI/CD log where --verbose is active. - Replace token log calls with utils.MaskSecret so the values are always printed as '[REDACTED]' regardless of --verbose state - Sanitize the OAuth2 callback URL logged on each redirect using utils.SanitizeString to redact any authorization codes or state params that may appear in query strings Fixes #265 Signed-off-by: Priyanshubhartistm <bhartipriyanshustm@gmail.com>
1 parent 9360ded commit 453b88e

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

cmd/login.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/microcks/microcks-cli/pkg/connectors"
2121
"github.com/microcks/microcks-cli/pkg/errors"
2222
"github.com/microcks/microcks-cli/pkg/util/rand"
23+
"github.com/microcks/microcks-cli/pkg/utils"
2324
"github.com/skratchdot/open-golang/open"
2425
"github.com/spf13/cobra"
2526
"golang.org/x/oauth2"
@@ -219,7 +220,7 @@ func oauth2login(
219220
// Authorization redirect callback from OAuth2 auth flow.
220221
// Handles both implicit and authorization code flow
221222
callbackHandler := func(w http.ResponseWriter, r *http.Request) {
222-
log.Printf("Callback: %s\n", r.URL)
223+
log.Printf("Callback: %s\n", utils.SanitizeString(r.URL.String()))
223224

224225
if formErr := r.FormValue("error"); formErr != "" {
225226
handleErr(w, fmt.Sprintf("%s: %s", formErr, r.FormValue("error_description")))
@@ -293,6 +294,8 @@ func oauth2login(
293294
ctx, cancel := context.WithTimeout(ctx, 1*time.Second)
294295
defer cancel()
295296
_ = srv.Shutdown(ctx)
297+
log.Printf("Token: %s\n", utils.MaskSecret(tokenString))
298+
log.Printf("Refresh Token: %s\n", utils.MaskSecret(refreshToken))
296299
return tokenString, refreshToken
297300
}
298301

0 commit comments

Comments
 (0)