Commit b23a65b
committed
fix(sandbox-router-extproc): close validation gaps + lock down dst-host trust
Mirror the parity fixes that just landed on PR kubernetes-sigs#838, in the shapes
that fit the ext_proc design. Together with the per-PR ingress strip,
this closes the four-finding security review from @aditya-shantanu.
1. X-Sandbox-ID DNS-label validation. The Python router runs ID
through ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$ (max 63 chars) so a caller
can't interpolate extra DNS components into "<id>.<ns>.svc.
<cluster-domain>" via the DNS-form fallback. We validated namespace
and port but not ID. Now applied to both ID and namespace through
a shared validDNSLabel helper.
2. Tightened namespace validation. The previous validNamespace allowed
uppercase, leading/trailing hyphens, and unbounded length. K8s
itself rejects all three, so the practical risk was just routing
to FQDNs that can't exist — but tightening to the same DNS-1123
rule used for ID keeps the validation surface uniform and matches
Python exactly. validNamespace removed in favor of validDNSLabel.
3. Authorization header strip. Always add "authorization" to the
HeaderMutation.RemoveHeaders so the sandbox never sees the
caller's bearer credential. Without this, a sandbox could
impersonate the caller against the K8s API or any other
Bearer-protected service. Matches the Python router and the same
fix on kubernetes-sigs#838.
4. x-envoy-original-dst-host ingress strip (defense in depth). A new
envoy.filters.http.header_mutation filter runs BEFORE ext_proc in
the HCM chain and removes any client-supplied
x-envoy-original-dst-host. ext_proc still always sets it via
HeaderMutation, so after the filter chain the value reaching the
ORIGINAL_DST cluster is provably the one ext_proc wrote — or
absent if a future route disables ext_proc, in which case the
cluster fails closed with 503 rather than dispatching to whatever
the client asked for. Without this, the security of the data path
would rest on "ext_proc is enabled on every route", which the
existing /healthz route already demonstrates is not a load-
bearing assumption.
Tests: TestHandle_InvalidIDRejected covers the six classes of
DNS-injection / traversal inputs (dot, slash, underscore, uppercase,
leading hyphen, trailing hyphen). TestHandle_AlwaysStripsAuthorization
asserts the RemoveHeaders mutation contains "authorization" on both
upgrade and non-upgrade paths. TestValidDNSLabel replaces the old
TestValidNamespace with the stricter table (accepts 1abc per RFC 1123,
rejects MY-NS, -x, x-, length > 63).
README documents the new validation surface, the headers we strip
before forwarding (Authorization, Origin-on-upgrade, and the
listener-level x-envoy-original-dst-host strip), and the rationale
for each.1 parent d4fd268 commit b23a65b
4 files changed
Lines changed: 168 additions & 31 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
42 | 42 | | |
43 | | - | |
44 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
45 | 47 | | |
46 | 48 | | |
47 | 49 | | |
| |||
51 | 53 | | |
52 | 54 | | |
53 | 55 | | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
54 | 64 | | |
55 | 65 | | |
56 | 66 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
96 | 112 | | |
97 | 113 | | |
98 | 114 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
208 | 208 | | |
209 | 209 | | |
210 | 210 | | |
211 | | - | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
212 | 220 | | |
213 | 221 | | |
214 | 222 | | |
| |||
246 | 254 | | |
247 | 255 | | |
248 | 256 | | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
249 | 268 | | |
250 | 269 | | |
251 | 270 | | |
| |||
369 | 388 | | |
370 | 389 | | |
371 | 390 | | |
372 | | - | |
| 391 | + | |
| 392 | + | |
373 | 393 | | |
374 | | - | |
| 394 | + | |
375 | 395 | | |
376 | | - | |
377 | | - | |
378 | | - | |
379 | | - | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
380 | 405 | | |
381 | 406 | | |
382 | | - | |
383 | 407 | | |
384 | 408 | | |
385 | 409 | | |
386 | | - | |
387 | | - | |
| 410 | + | |
| 411 | + | |
388 | 412 | | |
389 | | - | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
390 | 417 | | |
391 | 418 | | |
392 | 419 | | |
393 | 420 | | |
394 | | - | |
| 421 | + | |
395 | 422 | | |
396 | 423 | | |
397 | 424 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
198 | 198 | | |
199 | 199 | | |
200 | 200 | | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
201 | 230 | | |
202 | 231 | | |
203 | 232 | | |
| |||
350 | 379 | | |
351 | 380 | | |
352 | 381 | | |
353 | | - | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
354 | 387 | | |
355 | | - | |
356 | | - | |
357 | | - | |
358 | | - | |
359 | | - | |
360 | | - | |
361 | | - | |
362 | | - | |
363 | | - | |
364 | | - | |
365 | | - | |
366 | | - | |
367 | | - | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
368 | 405 | | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
369 | 414 | | |
370 | 415 | | |
371 | | - | |
372 | | - | |
| 416 | + | |
| 417 | + | |
373 | 418 | | |
374 | 419 | | |
375 | 420 | | |
| |||
509 | 554 | | |
510 | 555 | | |
511 | 556 | | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
512 | 596 | | |
513 | 597 | | |
514 | 598 | | |
| |||
0 commit comments