-
Notifications
You must be signed in to change notification settings - Fork 1
fix(runtime-node): stop redaction masking GenAI/usage token counts #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f31c9a3
56c2227
d001c3b
29a86db
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -124,3 +124,58 @@ | |
| assert.deepEqual(redactAttributes(), {}); | ||
| assert.deepEqual(redactAttributes(null), {}); | ||
| }); | ||
|
|
||
|
Check warning on line 127 in packages/runtime-node/test/redact.test.mjs
|
||
| test("keeps canonical GenAI usage counts only when numeric", () => { | ||
|
Check warning on line 128 in packages/runtime-node/test/redact.test.mjs
|
||
| const out = redactAttributes({ | ||
| "gen_ai.usage.input_tokens": 512, | ||
| "gen_ai.usage.output_tokens": 128, | ||
| "gen_ai.usage.prompt_tokens": 256, | ||
| "gen_ai.usage.completion_tokens": 128, | ||
| "gen_ai.usage.total_tokens": 640, | ||
| "gen_ai.usage.token_count": 42, | ||
| "gen_ai.usage.input_tokens_string": "secret", | ||
| max_tokens: 1000, | ||
| "secret.input_tokens": 999, | ||
| }); | ||
|
|
||
| assert.deepEqual(out, { | ||
| "gen_ai.usage.input_tokens": 512, | ||
| "gen_ai.usage.output_tokens": 128, | ||
| "gen_ai.usage.prompt_tokens": 256, | ||
| "gen_ai.usage.completion_tokens": 128, | ||
| "gen_ai.usage.total_tokens": 640, | ||
| "gen_ai.usage.token_count": 42, | ||
| "gen_ai.usage.input_tokens_string": MASK, | ||
| max_tokens: MASK, | ||
| "secret.input_tokens": MASK, | ||
| }); | ||
| }); | ||
|
|
||
| test("redacts non-numeric canonical GenAI usage values", () => { | ||
| const out = redactAttributes({ | ||
| "gen_ai.usage.input_tokens": "secret", | ||
| "gen_ai.usage.output_tokens": -1, | ||
| "gen_ai.usage.total_tokens": NaN, | ||
|
Check warning on line 158 in packages/runtime-node/test/redact.test.mjs
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 [deterministic] Biome: lint/style/useNumberNamespace — Risk: 55/100 Use Number.NaN instead of the equivalent global. 🛠 AI fix prompt (copy & paste into your coding agent)Flagged by Autter security & observability checks. |
||
| "gen_ai.usage.token_count": Infinity, | ||
|
Check warning on line 159 in packages/runtime-node/test/redact.test.mjs
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 [deterministic] Biome: lint/style/useNumberNamespace — Risk: 55/100 Use Number.POSITIVE_INFINITY instead of the equivalent global. 🛠 AI fix prompt (copy & paste into your coding agent)Flagged by Autter security & observability checks. |
||
| }); | ||
|
|
||
| assert.deepEqual(out, { | ||
| "gen_ai.usage.input_tokens": MASK, | ||
| "gen_ai.usage.output_tokens": MASK, | ||
| "gen_ai.usage.total_tokens": MASK, | ||
| "gen_ai.usage.token_count": MASK, | ||
| }); | ||
| }); | ||
| test("still masks secret token keys ending in token", () => { | ||
| const out = redactAttributes({ | ||
| token: "raw", | ||
| access_token: "raw", | ||
| refresh_token: "raw", | ||
| authToken: "raw", | ||
| token_value: "raw", | ||
| tokenString: "raw", | ||
| token_id: "raw", | ||
| id_token_hint: "raw", | ||
| }); | ||
| for (const value of Object.values(out)) assert.equal(value, MASK); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟠 [ai] Canonical usage exemption ignores additional key redaction patterns — Risk: 56/100
The canonical GenAI branch returns before checking
r.keyPatterns, so a caller-suppliedadditionalKeyPatternsmatch can never redact a valid numeric value under a canonical usage key such asgen_ai.usage.input_tokens. This is reachable through the documentedredactAttributes(attributes, { additionalKeyPatterns: [...] })API and violates the option contract that extra key patterns extend the built-in key rules, allowing a configured policy to be silently bypassed for these attributes.packages/runtime-node/src/redact.ts🛠 AI fix prompt (copy & paste into your coding agent)
Flagged by Autter security & observability checks.