Commit ca76bda
fix(control-plane): guard non-object JSON in approval-body parsing
CodeRabbit follow-up review on #672 (the only thread that didn't auto-
resolve after the previous fix pushes). The issue technically lives in
#671's plans.handler.ts but CodeRabbit only flagged it now after seeing
the post-fix state.
`JSON.parse("null")` returns null, `JSON.parse("[1,2]")` returns an
array, `JSON.parse("42")` returns a number. All three are syntactically
valid JSON but none of them is the object payload approvePlan/rejectPlan
expect. The previous code would parse successfully then crash later
when dereferencing `body.implementationModel` on `null` (TypeError) or
silently accept arrays and primitives as if they were valid bodies.
Reject these early with HTTP 400 (`code: "invalid_body"`) via the
existing InvalidApprovalBodyError path. Two new regression cases cover
JSON-null and JSON-array bodies.
Verification: npm run typecheck && npm test -w @open-inspect/control-plane
(65/65 files, 2 new test cases green).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 2f613bb commit ca76bda
2 files changed
Lines changed: 45 additions & 1 deletion
Lines changed: 30 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
224 | 224 | | |
225 | 225 | | |
226 | 226 | | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
227 | 257 | | |
228 | 258 | | |
229 | 259 | | |
| |||
Lines changed: 15 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
183 | 183 | | |
184 | 184 | | |
185 | 185 | | |
| 186 | + | |
186 | 187 | | |
187 | | - | |
| 188 | + | |
188 | 189 | | |
189 | 190 | | |
190 | 191 | | |
191 | 192 | | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
192 | 206 | | |
193 | 207 | | |
194 | 208 | | |
| |||
0 commit comments