Skip to content

Commit 3604144

Browse files
committed
fix: scrubbing more aggressively anything in the logs that MIGHT be password affiliated (handling spaces in secrets)
1 parent cb651dd commit 3604144

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

.changeset/shaggy-garlics-joke.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"builder-util": patch
3+
---
4+
5+
fix: scrubbing more aggressively anything in the logs that MIGHT be password affiliated (handling spaces in secrets)

packages/builder-util/src/util.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,29 @@ export function serializeToYaml(object: any, skipInvalid = false, noRefs = false
4242
})
4343
}
4444

45-
export function removePassword(input: string) {
46-
return input.replace(/(-String |-P |pass:| \/p |-pass |--secretKey |--accessKey |-p )([^ ]+)/g, (match, p1, p2) => {
47-
if (p1.trim() === "/p" && p2.startsWith("\\\\Mac\\Host\\\\")) {
48-
// appx /p
49-
return `${p1}${p2}`
45+
export function removePassword(input: string): string {
46+
const blockList = ["--accessKey", "--secretKey", "-P", "-p", "-pass", "-String", "/p", "pass:"]
47+
48+
// Create a regex pattern that supports:
49+
// - space-separated unquoted values: --key value
50+
// - quoted values: --key "value with spaces" or 'value with spaces'
51+
const blockPattern = new RegExp(`(${blockList.map(s => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|")})\\s*(?:(["'])(.*?)\\2|([^\\s]+))`, "g")
52+
53+
input = input.replace(blockPattern, (_match, prefix, quote, quotedVal, unquotedVal) => {
54+
const value = quotedVal ?? unquotedVal
55+
56+
if (prefix.trim() === "/p" && value.startsWith("\\\\Mac\\Host\\\\")) {
57+
return `${prefix}${quote ?? ""}${value}${quote ?? ""}`
5058
}
51-
return `${p1}${createHash("sha256").update(p2).digest("hex")} (sha256 hash)`
59+
60+
const hashed = createHash("sha256").update(value).digest("hex")
61+
return `${prefix}${quote ?? ""}${hashed} (sha256 hash)${quote ?? ""}`
62+
})
63+
64+
// Also handle `/b ... /c` block format
65+
return input.replace(/(\/b\s+)(.*?)(\s+\/c)/g, (_match, p1, p2, p3) => {
66+
const hashed = createHash("sha256").update(p2).digest("hex")
67+
return `${p1}${hashed} (sha256 hash)${p3}`
5268
})
5369
}
5470

0 commit comments

Comments
 (0)