Commit 70cbf3f
fix: backport Copilot review fixes from PR rboarescu#15 (/viz) to main
Same shape as 152e428 — production at disks runs fork main, so
review amendments to the in-flight upstream PR need to ship here too.
Eight Copilot comments addressed across main.py and static/viz.html.
## Auth (was: /viz served publicly)
main.py: /viz now goes through _check_auth on the same code path as
every other endpoint. Accepts the key from either the X-Api-Key header
(preferred) or the ?key=… query param (bookmarkable shortcut).
_check_auth is a no-op when PALACE_API_KEY is unset, so the
zero-config local-dev experience is unchanged. Production deployments
with PALACE_API_KEY set will now 401 unauthenticated /viz requests —
matches every other endpoint.
## CDN integrity (was: D3 + Mermaid loaded without SRI, version not pinned)
static/viz.html: pinned to d3@7.8.5 and mermaid@10.9.1 with SHA-384
SRI hashes via cdn.jsdelivr.net. Added crossorigin="anonymous" (required
for SRI on cross-origin scripts) and referrerpolicy="no-referrer".
## Mermaid sanitization
static/viz.html:
- mermaidSafe() now strips ASCII control chars (\\n, \\r, \\t, etc.) in
addition to the existing parser-breaking chars.
- mermaid.initialize({ securityLevel: "strict" }) — was "loose" which
relaxes label sanitization and enables clickable diagram nodes.
The dashboard never needs node click handlers, and our own
mermaidSafe() runs before labels reach Mermaid anyway.
## Mermaid render-error fallback (was: <div> appended inside <pre>)
static/viz.html: target was <pre id="hierarchy">; appending a <div>
inside it produced invalid HTML and inconsistent cross-browser
rendering. Surface the error as plain text inside the existing element
and tag with class="err" so CSS can style it.
## ?key= leakage warning
static/viz.html: comment on the KEY parsing block calls out that
?key=… leaks into browser history, referer headers, and proxy logs.
Same caveat in the /viz docstring.
## Docstring drift (was: "cached at module load" but actually lazy)
main.py: docstring rewritten to describe the actual lazy-load behaviour
("lazy-loaded on first request and cached in-process thereafter; one
disk read per daemon process").
All five fixes are amendments on the corresponding upstream PR rboarescu#15
branch (force-pushed earlier today). No behaviour change for the
healthy unauthenticated-local case; the changes harden security
surface that was caught in review.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 2778832 commit 70cbf3f
2 files changed
Lines changed: 63 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
885 | 885 | | |
886 | 886 | | |
887 | 887 | | |
888 | | - | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
889 | 892 | | |
890 | 893 | | |
891 | | - | |
892 | | - | |
| 894 | + | |
| 895 | + | |
893 | 896 | | |
894 | | - | |
895 | | - | |
896 | | - | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
897 | 908 | | |
898 | 909 | | |
899 | 910 | | |
900 | 911 | | |
901 | 912 | | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
902 | 918 | | |
903 | 919 | | |
904 | 920 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
39 | | - | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
40 | 54 | | |
41 | 55 | | |
42 | 56 | | |
| |||
218 | 232 | | |
219 | 233 | | |
220 | 234 | | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
221 | 241 | | |
222 | 242 | | |
223 | 243 | | |
| |||
341 | 361 | | |
342 | 362 | | |
343 | 363 | | |
344 | | - | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
345 | 368 | | |
346 | | - | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
347 | 373 | | |
348 | 374 | | |
349 | 375 | | |
| |||
371 | 397 | | |
372 | 398 | | |
373 | 399 | | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
374 | 403 | | |
375 | | - | |
| 404 | + | |
| 405 | + | |
376 | 406 | | |
377 | 407 | | |
378 | 408 | | |
| |||
466 | 496 | | |
467 | 497 | | |
468 | 498 | | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
469 | 504 | | |
470 | 505 | | |
471 | 506 | | |
472 | | - | |
| 507 | + | |
473 | 508 | | |
474 | 509 | | |
475 | 510 | | |
| |||
0 commit comments