Commit 9e886c5
committed
fix: address critical security and code quality issues
This commit resolves multiple HIGH and MEDIUM severity issues found during
security audit. All tests pass after changes.
**HIGH Severity Fixes:**
1. Fix nil pointer panic with --print-openapi flag
- Added nil check before process.Wait() to prevent crash
- File: cmd/server/server.go
2. Fix goroutine leak in snapshot loop
- Added context cancellation with select statement
- Changed time.Sleep to ticker for proper cleanup
- File: lib/httpapi/server.go
3. Fix race condition in terminal screen reading
- Always hold lock when reading terminal state
- Prevents concurrent read/write on p.xp.State
- File: lib/termexec/termexec.go
4. Add defensive checks for unsafe reflection
- Added defer/recover to catch reflection failures
- Improved error logging with recovery attempts
- Warns about unsafe xpty dependency
- File: lib/termexec/termexec.go
**MEDIUM Severity Fixes:**
5. Add message size validation
- MaxMessageSize: 10MB for user messages
- MaxRawMessageSize: 1KB for raw terminal input
- Prevents DoS via oversized messages
- File: lib/httpapi/server.go
6. Add HTTP server timeouts
- ReadTimeout: 15s (prevent slow header attacks)
- ReadHeaderTimeout: 5s (specifically for headers)
- IdleTimeout: 60s (close idle connections)
- WriteTimeout: 0 (disabled for SSE long-polling)
- File: lib/httpapi/server.go
7. Replace panics with error handling
- logctx.From() returns default logger instead of panic
- conversation.statusInner() logs errors and returns safe fallback
- convertStatus() logs unknown status instead of panic
- Files: lib/logctx/logctx.go, lib/screentracker/conversation.go,
lib/httpapi/events.go
All existing tests pass (CGO_ENABLED=0 go test ./...).1 parent e47a7ca commit 9e886c5
File tree
6 files changed
+98
-31
lines changed- cmd/server
- lib
- httpapi
- logctx
- screentracker
- termexec
6 files changed
+98
-31
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
126 | 132 | | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | 133 | | |
131 | 134 | | |
132 | 135 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
78 | | - | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
79 | 81 | | |
80 | 82 | | |
81 | 83 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
64 | 72 | | |
65 | 73 | | |
66 | 74 | | |
| |||
264 | 272 | | |
265 | 273 | | |
266 | 274 | | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
267 | 278 | | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
272 | 288 | | |
273 | 289 | | |
274 | 290 | | |
| |||
354 | 370 | | |
355 | 371 | | |
356 | 372 | | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
357 | 385 | | |
358 | 386 | | |
359 | 387 | | |
| |||
447 | 475 | | |
448 | 476 | | |
449 | 477 | | |
450 | | - | |
451 | | - | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
452 | 484 | | |
453 | 485 | | |
454 | 486 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
| 25 | + | |
25 | 26 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
355 | 355 | | |
356 | 356 | | |
357 | 357 | | |
358 | | - | |
| 358 | + | |
359 | 359 | | |
360 | | - | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
361 | 364 | | |
362 | 365 | | |
363 | | - | |
| 366 | + | |
| 367 | + | |
364 | 368 | | |
365 | 369 | | |
366 | 370 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
77 | 91 | | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
78 | 96 | | |
79 | 97 | | |
80 | 98 | | |
81 | 99 | | |
82 | 100 | | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
83 | 106 | | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | 107 | | |
88 | 108 | | |
89 | 109 | | |
| |||
114 | 134 | | |
115 | 135 | | |
116 | 136 | | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
| 137 | + | |
122 | 138 | | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
123 | 143 | | |
124 | 144 | | |
125 | | - | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
126 | 151 | | |
127 | 152 | | |
128 | 153 | | |
| |||
0 commit comments