Skip to content

Add 'debug auth' command to inspect Docker Desktop JWT#1861

Merged
dgageot merged 1 commit intodocker:mainfrom
dgageot:debug-auth
Feb 27, 2026
Merged

Add 'debug auth' command to inspect Docker Desktop JWT#1861
dgageot merged 1 commit intodocker:mainfrom
dgageot:debug-auth

Conversation

@dgageot
Copy link
Member

@dgageot dgageot commented Feb 26, 2026

Add a new 'cagent debug auth' subcommand that fetches the JWT from Docker Desktop, parses its claims, and displays authentication status.

Supports a --json flag for machine-readable output.

Assisted-By: cagent

Add a new 'cagent debug auth' subcommand that fetches the JWT from
Docker Desktop, parses its claims, and displays authentication status.
Supports a --json flag for machine-readable output.

Assisted-By: cagent
@dgageot dgageot requested a review from a team as a code owner February 26, 2026 16:05
Copy link

@docker-agent docker-agent bot left a comment

Choose a reason for hiding this comment

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

Review Summary

Found 1 critical issue that needs to be addressed.

Critical Issue

  • Panic Risk: The token display logic doesn't validate token length, which will cause a panic if the token is shorter than 10 characters.

}

func printAuthInfoText(w io.Writer, info *authInfo) {
fmt.Fprintf(w, "Token: %s...%s\n", info.Token[:10], info.Token[len(info.Token)-10:])
Copy link

Choose a reason for hiding this comment

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

🚨 Index out of bounds panic when token is shorter than 10 characters

This line will panic if info.Token is less than 10 characters long.

The Problem:
When slicing info.Token[len(info.Token)-10:] with a token shorter than 10 characters, the expression len(info.Token)-10 becomes negative, causing a panic. For example, with a 5-character token:

  • len(info.Token) = 5
  • len(info.Token)-10 = -5
  • info.Token[-5:] → panic: negative slice index

Fix:
Validate the token length before slicing:

if len(info.Token) < 20 {
    fmt.Fprintf(w, "Token:      %s\n", info.Token)
} else {
    fmt.Fprintf(w, "Token:      %s...%s\n", info.Token[:10], info.Token[len(info.Token)-10:])
}

While JWTs are typically much longer than 20 characters, edge cases (malformed tokens, test data, etc.) could trigger this panic.

@dgageot dgageot merged commit 4b28b50 into docker:main Feb 27, 2026
8 checks passed
@dgageot dgageot deleted the debug-auth branch February 27, 2026 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants