Commit f26e656
authored
fix(selfhost): stop the redaction scrubber nulling every AI token count (#10212)
SECRET_KEY matches /token/i, so scrubRecord -- wired as posthog-node's
before_send -- rewrote PostHog's own $ai_input_tokens and $ai_output_tokens to
the "[redacted]" STRING, which PostHog then coerced to null on its
numerically-typed properties.
The result: not one AI call in the project has ever carried a token count.
posthog.ai_events.input_tokens/output_tokens/total_tokens are NULL for every
model over the retention window, including claude-sonnet-5 at 2,321 calls and
$498.43 of real spend. $ai_total_cost_usd came through untouched because it has
no secret-shaped word in it. PostHog derives $ai_input_cost_usd/$ai_output_cost_usd
from tokens, so those could not be computed either -- and the miner-side split
landed in #10199 would have been scrubbed the same way.
A secret-shaped key holding a NUMBER is a counter, not a credential: every secret
this module exists to catch is a string, and there is no numeric form of one to
leak. Skip redaction for numbers only; a string, object, array or boolean under
the same key is still redacted exactly as before.
Deliberately general rather than an allowlist of the two $ai_* keys -- an
allowlist goes stale the moment PostHog adds $ai_cache_read_input_tokens, and it
would fail the same silent way.
Closes #102111 parent fa9789e commit f26e656
2 files changed
Lines changed: 61 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
232 | 232 | | |
233 | 233 | | |
234 | 234 | | |
235 | | - | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
236 | 243 | | |
237 | 244 | | |
238 | 245 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
0 commit comments