Commit 875dc07
committed
fix(api): harden token handling after code review
Addresses seven findings from reviewing the client-verification feature:
- Percent-decode the ?token= query carrier. The web client escapes the
token in the SSE URL, so a CCTRACE_API_TOKEN containing URL-reserved
characters used to fail only on the EventSource path.
- Give the unpersisted fallback token its own source, "ephemeral", instead
of reporting it as env-provided. Settings now explains that the token
file could not be written rather than blaming CCTRACE_API_TOKEN, and
Regenerate is disabled with an accurate message.
- Heal multi-process divergence: on a token mismatch the middleware
re-reads the token file once and adopts a rotated value before
rejecting, so a second cctrace process sharing the file no longer
returns 401 until restarted. Happy-path requests never touch the disk.
- Rotate atomically via a 0600 temp file and rename, so concurrent readers
(the TUI re-reads per request, Vite watches the file) never observe an
empty file. The first-run reader also retries briefly while the O_EXCL
creator is still writing.
- The Node helper no longer fabricates a token when the file exists but is
empty; it retries briefly, then throws so Vite fails loudly instead of
baking a token no backend accepts.
- MessageDetail drops the saved main-body scroll offset when a panel is
replaced at the same depth, instead of restoring a stale position on the
next unrelated push or pop.
- The static-fallback cookie middleware resolves the origin allowlist only
for HTML responses, not for every asset request.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ARMV5uP7TQ9NyXsqAjpo2E1 parent 7f90c2a commit 875dc07
11 files changed
Lines changed: 558 additions & 101 deletions
File tree
- bin
- specs
- src-tauri/src
- commands
- src/components
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
46 | 66 | | |
47 | 67 | | |
48 | 68 | | |
| |||
63 | 83 | | |
64 | 84 | | |
65 | 85 | | |
66 | | - | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
67 | 96 | | |
68 | 97 | | |
69 | 98 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
22 | 27 | | |
23 | 28 | | |
24 | 29 | | |
| |||
96 | 101 | | |
97 | 102 | | |
98 | 103 | | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
| 104 | + | |
104 | 105 | | |
105 | 106 | | |
106 | 107 | | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
107 | 124 | | |
108 | 125 | | |
109 | 126 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
81 | | - | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
82 | 83 | | |
83 | 84 | | |
84 | 85 | | |
| |||
401 | 402 | | |
402 | 403 | | |
403 | 404 | | |
404 | | - | |
405 | | - | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
406 | 410 | | |
407 | 411 | | |
408 | | - | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
409 | 417 | | |
410 | 418 | | |
411 | 419 | | |
| |||
446 | 454 | | |
447 | 455 | | |
448 | 456 | | |
449 | | - | |
450 | | - | |
451 | | - | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
452 | 461 | | |
453 | 462 | | |
454 | 463 | | |
| |||
0 commit comments