Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions plugin/scripts/post-tool-failure.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -136,21 +136,20 @@ const JSON_WHITESPACE_ESCAPES = {
r: "\r",
t: " "
};
const SECRET_KEY_WORDS = new Set([
const SECRET_KEY_SUFFIXES = [
"apikey",
"secret",
"token",
"password",
"passwd",
"credential",
"credentials",
"auth",
"authorization"
]);
"credentials"
];
const SECRET_KEY_WORDS = new Set(["auth", "authorization"]);
function isSecretKeyName(key) {
if (!/^[\w.-]{1,64}$/.test(key)) return false;
const words = key.replace(/([a-z0-9])([A-Z])/g, "$1_$2").toLowerCase().split(/[_.-]+/);
return words.some((word, i) => SECRET_KEY_WORDS.has(word) || word === "api" && words[i + 1] === "key");
const words = key.replace(/([a-z])([A-Z])/g, "$1_$2").replace(/([A-Za-z])(\d)/g, "$1_$2").toLowerCase().split(/[_.\-\d]+/).filter(Boolean);
return words.some((word, i) => SECRET_KEY_WORDS.has(word) || SECRET_KEY_SUFFIXES.some((suffix) => word.endsWith(suffix)) || word === "api" && words[i + 1] === "key");
}
function redactSecretKeys(value) {
if (Array.isArray(value)) return value.map(redactSecretKeys);
Expand Down
13 changes: 6 additions & 7 deletions plugin/scripts/post-tool-use.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -138,21 +138,20 @@ const JSON_WHITESPACE_ESCAPES = {
r: "\r",
t: " "
};
const SECRET_KEY_WORDS = new Set([
const SECRET_KEY_SUFFIXES = [
"apikey",
"secret",
"token",
"password",
"passwd",
"credential",
"credentials",
"auth",
"authorization"
]);
"credentials"
];
const SECRET_KEY_WORDS = new Set(["auth", "authorization"]);
function isSecretKeyName(key) {
if (!/^[\w.-]{1,64}$/.test(key)) return false;
const words = key.replace(/([a-z0-9])([A-Z])/g, "$1_$2").toLowerCase().split(/[_.-]+/);
return words.some((word, i) => SECRET_KEY_WORDS.has(word) || word === "api" && words[i + 1] === "key");
const words = key.replace(/([a-z])([A-Z])/g, "$1_$2").replace(/([A-Za-z])(\d)/g, "$1_$2").toLowerCase().split(/[_.\-\d]+/).filter(Boolean);
return words.some((word, i) => SECRET_KEY_WORDS.has(word) || SECRET_KEY_SUFFIXES.some((suffix) => word.endsWith(suffix)) || word === "api" && words[i + 1] === "key");
}
function redactSecretKeys(value) {
if (Array.isArray(value)) return value.map(redactSecretKeys);
Expand Down
17 changes: 14 additions & 3 deletions src/hooks/_capture-filter.ts
Comment thread
rohitg00 marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,23 @@ export function truncateText(value: string, max: number): string {

const JSON_WHITESPACE_ESCAPES: Record<string, string> = { n: "\n", r: "\r", t: "\t" };

const SECRET_KEY_WORDS = new Set(["apikey", "secret", "token", "password", "passwd", "credential", "credentials", "auth", "authorization"]);
const SECRET_KEY_SUFFIXES = ["apikey", "secret", "token", "password", "passwd", "credential", "credentials"];
const SECRET_KEY_WORDS = new Set(["auth", "authorization"]);

function isSecretKeyName(key: string): boolean {
if (!/^[\w.-]{1,64}$/.test(key)) return false;
const words = key.replace(/([a-z0-9])([A-Z])/g, "$1_$2").toLowerCase().split(/[_.-]+/);
return words.some((word, i) => SECRET_KEY_WORDS.has(word) || (word === "api" && words[i + 1] === "key"));
const words = key
.replace(/([a-z])([A-Z])/g, "$1_$2")
.replace(/([A-Za-z])(\d)/g, "$1_$2")
.toLowerCase()
.split(/[_.\-\d]+/)
.filter(Boolean);
return words.some(
(word, i) =>
SECRET_KEY_WORDS.has(word) ||
SECRET_KEY_SUFFIXES.some((suffix) => word.endsWith(suffix)) ||
(word === "api" && words[i + 1] === "key"),
);
}

function redactSecretKeys(value: unknown): unknown {
Expand Down
6 changes: 4 additions & 2 deletions test/capture-filter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,13 @@ describe("truncateCaptureOutput redacts structured values before serializing", (
});

it("keeps values whose key only contains a secret word inside another word", () => {
const value = { tokenization: "words", secretary: "office", access_token: "T".repeat(40), pad: "y".repeat(200) };
const out = truncateJson(value, 120);
const value = { tokenization: "words", secretary: "office", access_token: "T".repeat(40), accesstoken: "U".repeat(40), apiKey2: "V".repeat(40), pad: "y".repeat(200) };
const out = truncateJson(value, 200);
expect(out).toContain("words");
expect(out).toContain("office");
expect(out).not.toContain("TTTT");
expect(out).not.toContain("UUUU");
expect(out).not.toContain("VVVV");
});

it("leaves a short value with a secret-like key unchanged", () => {
Expand Down
Loading