Skip to content

Commit 856aac5

Browse files
anandgupta42claude
andcommitted
fix(telemetry): cut the error line at the first credential word, path or escape
Quoted labels (`"password": x`), backslash-escaped quotes and paths containing spaces could carry values past the token-by-token template. The line is now cut at the token holding the first credential stem or path separator and the rest masked. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 8e6309d commit 856aac5

2 files changed

Lines changed: 25 additions & 5 deletions

File tree

‎packages/opencode/src/altimate/telemetry/error-detail.ts‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,25 @@ const isCredential = (token: string) =>
6161
* `@`, `=`, quoted content, capitalized names) becomes `<x>`. English-like words
6262
* that happen to spell a SQL statement are not recognised and can survive.
6363
*/
64+
// The line is cut at the token holding the first of: a credential stem (also inside quotes or a
65+
// compound key), a path separator, or an escape. Everything from there on is masked, because a
66+
// value, path or escaped string can run on past whitespace and quote boundaries.
67+
const CUT = new RegExp(`${CREDENTIAL_STEMS.join("|")}|[\\\\/]`, "i")
68+
69+
function cutAtUnsafe(line: string): string {
70+
const hit = CUT.exec(line)
71+
if (!hit) return line
72+
const tokenStart = line.lastIndexOf(" ", hit.index) + 1
73+
const lead = line.slice(0, tokenStart)
74+
const token = line.slice(tokenStart).split(/\s/, 1)[0]
75+
const unquoted = token.replace(/['"]/g, "")
76+
const label = unquoted.replace(/[:=,]+$/, "")
77+
// keep a plain credential label (`password:`) so the shape stays readable
78+
return isCredential(label) && WORD.test(label) ? `${lead}${unquoted} ${PLACEHOLDER}` : `${lead}${PLACEHOLDER}`
79+
}
80+
6481
export function templateErrorMessage(raw: string): string {
65-
const first = raw
66-
.split(/[\r\n]/, 1)[0]
82+
const first = cutAtUnsafe(raw.split(/[\r\n]/, 1)[0])
6783
.replace(/'[^']*'|"[^"]*"/g, ` ${PLACEHOLDER} `)
6884
.replace(/['"].*$/, ` ${PLACEHOLDER}`)
6985
const out: string[] = []

‎packages/opencode/test/telemetry/error-detail.test.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ describe("templateErrorMessage", () => {
2828
})
2929

3030
test.each([
31-
"/Users/bob/proj/a.ts",
32-
"C:\\Users\\bob\\a.ts",
3331
34-
pgUri,
3532
"AKIAIOSFODNN7EXAMPLE",
3633
"ghp_abcdefghijklmnopqrstuvwxyz0123456789",
3734
"eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjM0In0.sig",
@@ -47,6 +44,13 @@ describe("templateErrorMessage", () => {
4744
["login failed password: supersecret", "login failed password: <x>"],
4845
["Authorization: Bearer secrettoken", "Authorization: <x>"],
4946
["bad api key hunter, retry", "bad api key <x>"],
47+
["bad /Users/bob/proj/a.ts here", "bad <x>"],
48+
["bad C:\\Users\\bob\\a.ts here", "bad <x>"],
49+
[`bad ${pgUri} here`, "bad <x>"],
50+
['bad "password": hunter here', "bad password: <x>"],
51+
['open "C:\\Program Files\\acme corp\\a.ts" failed', "open <x>"],
52+
["open /home/x/my customer name/a.ts failed", "open <x>"],
53+
['value "a \\" customer name" bad', "value <x>"],
5054
["fetch https://h.example.com/p?token=zzz failed", "fetch <x>"],
5155
["auth failed: client_secret: abc def ghi", "auth <x>"],
5256
["bad access_token=hunter two three", "bad <x>"],

0 commit comments

Comments
 (0)