-
Notifications
You must be signed in to change notification settings - Fork 302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add jwt token back to wsl connections #1841
Changes from all commits
b383ad2
0035b6c
d5fa489
cee9251
d4d23d8
fd962ae
bf7d820
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -262,6 +262,10 @@ func StartWslShellProc(ctx context.Context, termSize waveobj.TermSize, cmdStr st | |
conn.Debugf(ctx, "packed swaptoken %s\n", packedToken) | ||
cmdCombined = fmt.Sprintf(`%s=%s %s`, wavebase.WaveSwapTokenVarName, packedToken, cmdCombined) | ||
} | ||
jwtToken := cmdOpts.SwapToken.Env[wavebase.WaveJwtTokenVarName] | ||
if jwtToken != "" { | ||
cmdCombined = fmt.Sprintf(`%s=%s %s`, wavebase.WaveJwtTokenVarName, jwtToken, cmdCombined) | ||
} | ||
Comment on lines
+265
to
+268
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prevent nil-pointer dereference and sensitive token leakage
Below are sample diffs to mitigate both issues: --- a/pkg/shellexec/shellexec.go
+++ b/pkg/shellexec/shellexec.go
@@ -264,7 +264,11 @@ func StartWslShellProc(ctx context.Context, termSize waveobj.TermSize, cmdStr st
}
- jwtToken := cmdOpts.SwapToken.Env[wavebase.WaveJwtTokenVarName]
+ if cmdOpts.SwapToken == nil || cmdOpts.SwapToken.Env == nil {
+ conn.Infof(ctx, "warning: SwapToken or SwapToken.Env is nil; skipping JWT token injection")
+ } else {
+ jwtToken := cmdOpts.SwapToken.Env[wavebase.WaveJwtTokenVarName]
+ if jwtToken != "" {
+ cmdCombined = fmt.Sprintf(`%s=%s %s`, wavebase.WaveJwtTokenVarName, jwtToken, cmdCombined)
+ }
+ }
log.Printf("full combined command: %s", cmdCombined) // Potential token leak And to mask the leaked token in logs (outside the annotated lines): - log.Printf("full combined command: %s", cmdCombined)
+ // Avoid logging sensitive token
+ maskedCommand := strings.ReplaceAll(
+ cmdCombined,
+ fmt.Sprintf("%s=%s", wavebase.WaveJwtTokenVarName, jwtToken),
+ fmt.Sprintf("%s=***REDACTED***", wavebase.WaveJwtTokenVarName),
+ )
+ log.Printf("full combined command: %s", maskedCommand)
|
||
log.Printf("full combined command: %s", cmdCombined) | ||
ecmd := exec.Command("wsl.exe", "~", "-d", client.Name(), "--", "sh", "-c", cmdCombined) | ||
if termSize.Rows == 0 || termSize.Cols == 0 { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Empty WSL host validation is required
The review is correct. The regex pattern
^wsl://[^/]+
would match an empty string after "wsl://" prefix, and the codebase expects a valid distro name in multiple places (wslconn, wshserver, blockcontroller). The suggested fix to validate the host is appropriate to prevent potential issues downstream.🔗 Analysis chain
Handle empty host scenario for WSL URIs.
If the pattern fails to match (e.g.,
wsl://
with no host),.FindString(rest)
will be""
, passing an emptyhost
downstream unintentionally. Consider returning an error in that scenario.Apply the following diff snippet to validate the host:
🏁 Scripts executed
The following scripts were executed for the analysis:
Error: No shell scripts found
Script:
Length of output: 16431