Skip to content

Commit

Permalink
Redact sensitive args from handshake debug log
Browse files Browse the repository at this point in the history
  • Loading branch information
code-asher committed May 4, 2023
1 parent 8c99f41 commit 3f7db15
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
17 changes: 12 additions & 5 deletions src/node/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,15 +435,22 @@ export const parse = (

logger.debug(() => [
`parsed ${opts?.configFile ? "config" : "command line"}`,
field("args", {
field("args", redactArgs(args)),
])

return args
}

/**
* Redact sensitive information from arguments for logging.
*/
export const redactArgs = (args: UserProvidedArgs): UserProvidedArgs => {
return {
...args,
password: args.password ? "<redacted>" : undefined,
"hashed-password": args["hashed-password"] ? "<redacted>" : undefined,
"github-auth": args["github-auth"] ? "<redacted>" : undefined,
}),
])

return args
}
}

/**
Expand Down
12 changes: 9 additions & 3 deletions src/node/wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as cp from "child_process"
import * as path from "path"
import * as rfs from "rotating-file-stream"
import { Emitter } from "../common/emitter"
import { DefaultedArgs } from "./cli"
import { DefaultedArgs, redactArgs } from "./cli"
import { paths } from "./util"

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

const onMessage = (message: M) => {
;(customLogger || logger).debug("got message", field("message", message))
if (fn(message)) {
cleanup()
resolve(message)
} else {
;(customLogger || logger).debug("got unhandled message", field("message", message))
}
}

Expand Down Expand Up @@ -181,6 +182,10 @@ export class ChildProcess extends Process {
},
this.logger,
)
this.logger.debug("got message", field("message", {
type: message.type,
args: redactArgs(message.args),
}))
return message.args
}

Expand Down Expand Up @@ -339,13 +344,14 @@ export class ParentProcess extends Process {
if (!this.args) {
throw new Error("started without args")
}
await onMessage<ChildMessage, ChildHandshakeMessage>(
const message = await onMessage<ChildMessage, ChildHandshakeMessage>(
child,
(message): message is ChildHandshakeMessage => {
return message.type === "handshake"
},
this.logger,
)
this.logger.debug("got message", field("message", message))
this.send(child, { type: "handshake", args: this.args })
}

Expand Down

0 comments on commit 3f7db15

Please sign in to comment.