Commit 00a62e8
committed
fix: harden telemetry security + address code-review-squad findings
Security (Critical):
- buildTelemetryUrl now rejects protocol-relative //prefix, zero-width
and BOM codepoints, CR/LF/tab, userinfo, path/query/fragment, and
loopback/RFC1918/IMDS/localhost/GCP+Azure-metadata hosts. Defeats
the SSRF-shaped Bearer-token exfil vector an attacker-influenced
host (env var, tampered config) could trigger.
- redactSensitive now covers real Databricks secret shapes: dapi/
dkea/dskea/dsapi/dose PATs, JWT triplets, JSON-quoted access_token/
client_secret/refresh_token/id_token/password/api_key, Basic auth,
URL-embedded credentials. Re-applies after truncation.
- Unauthenticated export now omits system_configuration entirely,
strips userAgentEntry from User-Agent, and blanks stack_trace, so
on-path observers cannot re-identify clients on the unauth path.
- sanitizeProcessName drops argv tail (handles node --db-password=X
app.js shape).
Correctness (High):
- MetricsAggregator gained a closed flag; close() no longer races
with batch-triggered flushes that would resurrect the interval.
- evictExpiredStatements now runs from the periodic flush timer so
idle clients actually reclaim orphan statement entries.
- Evicted statements emit their buffered error events as standalone
metrics before being dropped — first-failure signal survives.
- Batch-size and terminal-error flush paths pass resetTimer=false so
sustained overflow cant starve the periodic tail drain.
- TelemetryTerminalError introduced for host-validation refusals,
separating that taxonomy from AuthenticationError.
- authMissingWarned re-arms after a successful export so operators
see a fresh signal the next time auth breaks.
- Retry log denominator uses totalAttempts (not maxRetries); negative
maxRetries falls back to default; retry log includes the redacted
failing error so ops can see whats being retried.
API / hygiene:
- CircuitBreakerOpenError, CIRCUIT_BREAKER_OPEN_CODE, and
TelemetryTerminalError re-exported from lib/index.ts so consumers
can instanceof-check.
- DBSQLClient.getAuthProvider marked @internal.
- DEFAULT_TELEMETRY_CONFIG / DEFAULT_CIRCUIT_BREAKER_CONFIG frozen.
- pushBoundedError uses if instead of while.
- CIRCUIT_BREAKER_OPEN_CODE typed as const.
- Default export on buildTelemetryUrl removed (no callers).
- Dropped wasted new Error allocation in processErrorEvent.
Tests:
- New telemetryUtils.test.ts (53 tests): URL-rejection table covering
every known bypass, redactor shapes, sanitize process name.
- DatabricksTelemetryExporter: 13 new tests covering Authorization
on-the-wire, authMissingWarned idempotency + re-arm, unauth
correlation/system_configuration/userAgentEntry/stack_trace
stripping, malformed-host drop, loopback drop, dispose idempotency,
errorStack to redacted stack_trace flow.
- MetricsAggregator: 2 new tests for async close() awaiting the
exporter promise (prevents process.exit truncation) and no timer
resurrection after close.
700 unit tests pass, ESLint clean.
Co-authored-by: Isaac
Signed-off-by: samikshya-chand_data <samikshya.chand@databricks.com>1 parent 1205fff commit 00a62e8
File tree
16 files changed
+1327
-456
lines changed- lib
- contracts
- telemetry
- tests/unit
- .stubs
- telemetry
16 files changed
+1327
-456
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | 5 | | |
7 | 6 | | |
8 | 7 | | |
| |||
239 | 238 | | |
240 | 239 | | |
241 | 240 | | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
242 | 247 | | |
243 | 248 | | |
244 | 249 | | |
| |||
354 | 359 | | |
355 | 360 | | |
356 | 361 | | |
357 | | - | |
358 | | - | |
359 | | - | |
360 | | - | |
361 | | - | |
362 | | - | |
363 | | - | |
364 | | - | |
365 | | - | |
366 | | - | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
367 | 371 | | |
368 | 372 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | 1 | | |
3 | 2 | | |
4 | 3 | | |
| |||
29 | 28 | | |
30 | 29 | | |
31 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
32 | 34 | | |
33 | 35 | | |
34 | 36 | | |
35 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
36 | 41 | | |
37 | 42 | | |
38 | 43 | | |
| |||
45 | 50 | | |
46 | 51 | | |
47 | 52 | | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | 53 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
26 | 31 | | |
27 | 32 | | |
28 | 33 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | 20 | | |
24 | | - | |
25 | 21 | | |
26 | | - | |
27 | 22 | | |
28 | | - | |
29 | 23 | | |
30 | 24 | | |
31 | 25 | | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | 26 | | |
36 | | - | |
37 | 27 | | |
38 | | - | |
39 | 28 | | |
40 | | - | |
41 | 29 | | |
42 | 30 | | |
43 | 31 | | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
| 32 | + | |
48 | 33 | | |
49 | | - | |
| 34 | + | |
50 | 35 | | |
51 | | - | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
52 | 39 | | |
53 | 40 | | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
61 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
62 | 55 | | |
63 | 56 | | |
64 | 57 | | |
| |||
68 | 61 | | |
69 | 62 | | |
70 | 63 | | |
71 | | - | |
72 | 64 | | |
73 | 65 | | |
74 | 66 | | |
| |||
80 | 72 | | |
81 | 73 | | |
82 | 74 | | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
83 | 97 | | |
84 | | - | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
85 | 102 | | |
86 | | - | |
87 | | - | |
88 | | - | |
| 103 | + | |
| 104 | + | |
89 | 105 | | |
90 | | - | |
| 106 | + | |
91 | 107 | | |
92 | 108 | | |
93 | | - | |
94 | 109 | | |
95 | 110 | | |
96 | | - | |
| 111 | + | |
97 | 112 | | |
98 | | - | |
99 | 113 | | |
100 | 114 | | |
101 | 115 | | |
102 | 116 | | |
103 | 117 | | |
104 | 118 | | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | 119 | | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | 120 | | |
123 | | - | |
| 121 | + | |
124 | 122 | | |
| 123 | + | |
| 124 | + | |
125 | 125 | | |
| 126 | + | |
| 127 | + | |
126 | 128 | | |
127 | 129 | | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | 130 | | |
132 | 131 | | |
133 | 132 | | |
134 | 133 | | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | 134 | | |
139 | 135 | | |
140 | 136 | | |
141 | 137 | | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | 138 | | |
146 | 139 | | |
147 | 140 | | |
148 | 141 | | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | 142 | | |
153 | 143 | | |
154 | 144 | | |
155 | | - | |
156 | 145 | | |
157 | 146 | | |
158 | 147 | | |
| |||
163 | 152 | | |
164 | 153 | | |
165 | 154 | | |
166 | | - | |
167 | 155 | | |
168 | 156 | | |
169 | 157 | | |
| |||
172 | 160 | | |
173 | 161 | | |
174 | 162 | | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | 163 | | |
179 | 164 | | |
180 | 165 | | |
181 | 166 | | |
182 | | - | |
| 167 | + | |
183 | 168 | | |
184 | 169 | | |
185 | 170 | | |
186 | | - | |
187 | | - | |
188 | 171 | | |
189 | 172 | | |
190 | 173 | | |
191 | | - | |
192 | 174 | | |
193 | 175 | | |
194 | 176 | | |
| |||
197 | 179 | | |
198 | 180 | | |
199 | 181 | | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | 182 | | |
206 | 183 | | |
207 | 184 | | |
208 | 185 | | |
209 | 186 | | |
210 | 187 | | |
211 | 188 | | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | 189 | | |
220 | 190 | | |
221 | 191 | | |
| |||
230 | 200 | | |
231 | 201 | | |
232 | 202 | | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | 203 | | |
238 | 204 | | |
239 | 205 | | |
240 | 206 | | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | 207 | | |
248 | 208 | | |
249 | 209 | | |
250 | 210 | | |
251 | 211 | | |
252 | 212 | | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
257 | 213 | | |
258 | 214 | | |
259 | 215 | | |
| |||
0 commit comments