Commit b9b7b08
committed
feat: implement WebSocket authentication system with UUID tokens
This commit adds comprehensive authentication support to the claudecode.nvim WebSocket server:
- Generate UUID v4 tokens with enhanced entropy for each server session
- Store authentication tokens in lock files at ~/.claude/ide/[port].lock
- Validate auth tokens via x-claude-code-ide-authorization header during WebSocket handshake
- Reject connections with missing, invalid, or malformed authentication tokens
- Authentication tokens are 36-character UUIDs with proper format validation
- Token length limits (10-500 chars) prevent abuse
- Enhanced logging for authentication events and failures
- Secure token generation with multiple entropy sources
- Modified server startup to generate and pass auth tokens through the stack
- Updated handshake validation to check authentication headers
- Added comprehensive error handling for auth token generation and validation
- Enhanced client connection processing with authentication state tracking
- Added handshake_spec.lua with authentication test coverage
- Updated existing tests to support authenticated and unauthenticated modes
- Added auth token validation tests in lockfile_test.lua
- Enhanced integration tests with authentication flow testing
- Updated CLAUDE.md with authentication testing procedures and manual testing guides
- Updated PROTOCOL.md with authentication flow documentation and examples
- Added logging best practices and authentication debugging guides
This implementation follows the official Claude Code IDE authentication protocol
and ensures secure connections between Claude CLI and the Neovim plugin.
Change-Id: I4632b8e538cff23712a40a79289d10ae314cadec
Signed-off-by: Thomas Kosiewski <tk@coder.com>1 parent 3f09b51 commit b9b7b08
File tree
16 files changed
+1180
-38
lines changed- lua/claudecode
- server
- scripts
- tests
- integration
- unit
- server
16 files changed
+1180
-38
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
25 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
26 | 30 | | |
27 | 31 | | |
28 | 32 | | |
| 33 | + | |
| 34 | + | |
29 | 35 | | |
30 | 36 | | |
31 | 37 | | |
| |||
45 | 51 | | |
46 | 52 | | |
47 | 53 | | |
48 | | - | |
| 54 | + | |
49 | 55 | | |
50 | 56 | | |
51 | 57 | | |
52 | 58 | | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
53 | 68 | | |
54 | 69 | | |
55 | 70 | | |
| |||
76 | 91 | | |
77 | 92 | | |
78 | 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 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
79 | 187 | | |
80 | 188 | | |
| 189 | + | |
| 190 | + | |
81 | 191 | | |
82 | 192 | | |
83 | | - | |
84 | | - | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
85 | 204 | | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
86 | 210 | | |
| 211 | + | |
| 212 | + | |
87 | 213 | | |
88 | 214 | | |
89 | 215 | | |
| |||
134 | 260 | | |
135 | 261 | | |
136 | 262 | | |
137 | | - | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
138 | 266 | | |
139 | 267 | | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
41 | 52 | | |
42 | 53 | | |
43 | 54 | | |
| |||
503 | 514 | | |
504 | 515 | | |
505 | 516 | | |
| 517 | + | |
506 | 518 | | |
507 | 519 | | |
508 | 520 | | |
509 | 521 | | |
510 | | - | |
| 522 | + | |
| 523 | + | |
511 | 524 | | |
512 | 525 | | |
513 | 526 | | |
| |||
523 | 536 | | |
524 | 537 | | |
525 | 538 | | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
526 | 545 | | |
527 | 546 | | |
528 | 547 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
| 70 | + | |
70 | 71 | | |
71 | 72 | | |
72 | 73 | | |
| |||
76 | 77 | | |
77 | 78 | | |
78 | 79 | | |
| 80 | + | |
79 | 81 | | |
80 | 82 | | |
81 | 83 | | |
| |||
357 | 359 | | |
358 | 360 | | |
359 | 361 | | |
360 | | - | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
361 | 386 | | |
362 | 387 | | |
363 | | - | |
364 | | - | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
365 | 394 | | |
366 | 395 | | |
367 | 396 | | |
368 | 397 | | |
| 398 | + | |
369 | 399 | | |
370 | | - | |
371 | | - | |
| 400 | + | |
372 | 401 | | |
373 | 402 | | |
374 | 403 | | |
375 | 404 | | |
376 | 405 | | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
377 | 415 | | |
378 | | - | |
379 | | - | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
380 | 426 | | |
381 | 427 | | |
382 | 428 | | |
| |||
422 | 468 | | |
423 | 469 | | |
424 | 470 | | |
| 471 | + | |
425 | 472 | | |
426 | 473 | | |
427 | 474 | | |
| |||
0 commit comments