Commit 815bbd7
fix(security): patch chat-parser over-read and validate companion WS origin
Two independent issues found during a codebase security review.
1. NINJAM chat message parser (src/core/mpb.cpp)
mpb_chat_message::parse assigned parms[x] = p before walking for the
next NUL, and only checked for end-of-buffer AFTER an unconditional
p++. A malicious server could send a chat message whose final
parameter had no NUL terminator; parms[x] then pointed at
unterminated memory. Downstream, njclient.cpp consumes the pointer
via snprintf(" %s", ...) and ChatMessage_Callback, both of which
C-string-walk past the buffer until they hit a stray NUL — a
reliable heap info-disclosure primitive leaking bytes into chat UI
and logs. The fix only records parms[x] AFTER confirming a NUL was
seen strictly before endp; unterminated walks now break out of the
loop and leave that slot null.
2. Video companion WebSocket server (juce/video/VideoCompanion.cpp,.h)
The ixwebsocket server bound to 127.0.0.1:7170 accepted any
handshake with no Origin or Host validation. Browsers do NOT apply
SOP/CORS to raw WebSocket upgrades, so any webpage the user visited
in another tab could open ws://127.0.0.1:7170 and, on Open, receive
the config push (VDO.Ninja room ID, local username) plus subsequent
roster broadcasts — then join the VDO.Ninja room directly to lurk
on public-server sessions.
- On Open, require Origin == "https://jamwide.audio" AND Host ==
"127.0.0.1:<port>" or "localhost:<port>". Failures are closed
with code 1008 ("origin not allowed") BEFORE any state is sent.
- A new validatedClients_ set (guarded by wsMutex_) tracks which
clients passed validation. broadcastRoster, broadcastBufferDelay,
requestPopout, and the deactivate farewell now iterate
wsServer_->getClients() but only send when the raw pointer is in
validatedClients_, so an unvalidated client that ixwebsocket
briefly keeps in its client list during close cannot receive
state.
- Close/Error messages remove the pointer from the set; stop and
destructor clear the set entirely so stale pointers cannot carry
across a server restart.
The legitimate companion page at https://jamwide.audio opens
ws://127.0.0.1:7170 and both headers match, so the check is
transparent to users. Host validation also mitigates DNS rebinding.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent 8df2436 commit 815bbd7
3 files changed
Lines changed: 96 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| 59 | + | |
59 | 60 | | |
60 | 61 | | |
61 | 62 | | |
| |||
273 | 274 | | |
274 | 275 | | |
275 | 276 | | |
| 277 | + | |
276 | 278 | | |
277 | 279 | | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
278 | 321 | | |
279 | 322 | | |
280 | | - | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
281 | 332 | | |
282 | 333 | | |
283 | 334 | | |
| |||
319 | 370 | | |
320 | 371 | | |
321 | 372 | | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
322 | 378 | | |
323 | 379 | | |
324 | 380 | | |
| |||
451 | 507 | | |
452 | 508 | | |
453 | 509 | | |
454 | | - | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
455 | 515 | | |
| 516 | + | |
456 | 517 | | |
457 | 518 | | |
458 | | - | |
| 519 | + | |
| 520 | + | |
459 | 521 | | |
460 | 522 | | |
461 | 523 | | |
| |||
485 | 547 | | |
486 | 548 | | |
487 | 549 | | |
| 550 | + | |
488 | 551 | | |
489 | | - | |
| 552 | + | |
| 553 | + | |
490 | 554 | | |
491 | 555 | | |
492 | 556 | | |
| |||
501 | 565 | | |
502 | 566 | | |
503 | 567 | | |
| 568 | + | |
504 | 569 | | |
505 | | - | |
| 570 | + | |
| 571 | + | |
506 | 572 | | |
507 | 573 | | |
508 | 574 | | |
| |||
539 | 605 | | |
540 | 606 | | |
541 | 607 | | |
| 608 | + | |
542 | 609 | | |
543 | | - | |
| 610 | + | |
| 611 | + | |
544 | 612 | | |
545 | 613 | | |
546 | 614 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
156 | 156 | | |
157 | 157 | | |
158 | 158 | | |
159 | | - | |
| 159 | + | |
160 | 160 | | |
161 | 161 | | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
162 | 170 | | |
163 | 171 | | |
164 | 172 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
868 | 868 | | |
869 | 869 | | |
870 | 870 | | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
871 | 880 | | |
872 | 881 | | |
873 | 882 | | |
874 | 883 | | |
875 | | - | |
| 884 | + | |
876 | 885 | | |
877 | | - | |
878 | | - | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
879 | 889 | | |
880 | 890 | | |
881 | 891 | | |
| |||
0 commit comments