Skip to content

Commit debc957

Browse files
committed
fix(diagnostics): redact target userinfo
1 parent ab1eca2 commit debc957

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

src/lib/diagnostics/managed-transport.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ describe("safeTargetRef", () => {
3333
it("drops query and userinfo from non-URL values", () => {
3434
expect(safeTargetRef("user:secret@host:8080?token=x")).toBe("host:8080");
3535
});
36+
37+
it("drops every userinfo segment before the final at sign", () => {
38+
const target = "user:secret@second:credential@host:8080?token=x";
39+
40+
expect(safeTargetRef(target)).toBe("host:8080");
41+
expect(safeTargetRef(target)).not.toContain("credential");
42+
});
3643
});
3744

3845
describe("safeCauseChain", () => {

src/lib/diagnostics/managed-transport.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ export function safeTargetRef(value: string): string {
9393
}
9494
}
9595
const withoutQuery = value.split(/[?#]/, 1)[0] ?? "";
96-
return withoutQuery.replace(/^[^@]*@/, "");
96+
const finalAt = withoutQuery.lastIndexOf("@");
97+
return finalAt === -1 ? withoutQuery : withoutQuery.slice(finalAt + 1);
9798
}
9899

99100
const MAX_CAUSE_DEPTH = 8;

0 commit comments

Comments
 (0)