Skip to content

Commit 3f7db15

Browse files
committed
Redact sensitive args from handshake debug log
1 parent 8c99f41 commit 3f7db15

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

src/node/cli.ts

+12-5
Original file line numberDiff line numberDiff line change
@@ -435,15 +435,22 @@ export const parse = (
435435

436436
logger.debug(() => [
437437
`parsed ${opts?.configFile ? "config" : "command line"}`,
438-
field("args", {
438+
field("args", redactArgs(args)),
439+
])
440+
441+
return args
442+
}
443+
444+
/**
445+
* Redact sensitive information from arguments for logging.
446+
*/
447+
export const redactArgs = (args: UserProvidedArgs): UserProvidedArgs => {
448+
return {
439449
...args,
440450
password: args.password ? "<redacted>" : undefined,
441451
"hashed-password": args["hashed-password"] ? "<redacted>" : undefined,
442452
"github-auth": args["github-auth"] ? "<redacted>" : undefined,
443-
}),
444-
])
445-
446-
return args
453+
}
447454
}
448455

449456
/**

src/node/wrapper.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as cp from "child_process"
33
import * as path from "path"
44
import * as rfs from "rotating-file-stream"
55
import { Emitter } from "../common/emitter"
6-
import { DefaultedArgs } from "./cli"
6+
import { DefaultedArgs, redactArgs } from "./cli"
77
import { paths } from "./util"
88

99
const timeoutInterval = 10000 // 10s, matches VS Code's timeouts.
@@ -44,10 +44,11 @@ export function onMessage<M, T extends M>(
4444
}
4545

4646
const onMessage = (message: M) => {
47-
;(customLogger || logger).debug("got message", field("message", message))
4847
if (fn(message)) {
4948
cleanup()
5049
resolve(message)
50+
} else {
51+
;(customLogger || logger).debug("got unhandled message", field("message", message))
5152
}
5253
}
5354

@@ -181,6 +182,10 @@ export class ChildProcess extends Process {
181182
},
182183
this.logger,
183184
)
185+
this.logger.debug("got message", field("message", {
186+
type: message.type,
187+
args: redactArgs(message.args),
188+
}))
184189
return message.args
185190
}
186191

@@ -339,13 +344,14 @@ export class ParentProcess extends Process {
339344
if (!this.args) {
340345
throw new Error("started without args")
341346
}
342-
await onMessage<ChildMessage, ChildHandshakeMessage>(
347+
const message = await onMessage<ChildMessage, ChildHandshakeMessage>(
343348
child,
344349
(message): message is ChildHandshakeMessage => {
345350
return message.type === "handshake"
346351
},
347352
this.logger,
348353
)
354+
this.logger.debug("got message", field("message", message))
349355
this.send(child, { type: "handshake", args: this.args })
350356
}
351357

0 commit comments

Comments
 (0)