Commit 345e084
authored
fix(security): co-pod-member rule + no ghost-users on POST /room; rate-limit POST /pods (#617)
* fix(security): enforce co-pod-member rule + stop ghost-user creation on POST /room; rate-limit POST /pods
From the agent-runtime security audit.
- **Co-pod-member bypass (CRITICAL)**: the agent path of POST
/api/agents/runtime/room created an agent↔agent DM room with NO
sharePod check — any runtime token could DM any agent, defeating the
§3.7 isolation the /agent-dm route already enforces. Added the same
DMService.sharePod gate (403 rule:'sharePod' when no shared pod).
- **Ghost bot-user creation (HIGH)**: the target agent was resolved with
getOrCreateAgentUser (upsert), so a made-up agentName from a leaked
token materialized an orphan User row (unbounded table pollution). Now
resolved with a non-upsert User.findOne — unknown agent → 404.
- **POST /pods had no rate limit (HIGH)**: a runtime token could spray
unlimited pod creation. Added phase4RateLimit (matches /room,
/agent-dm, /messages).
Regression lock: agentsRuntime.room.test.js gains a non-existent-agent
404 case and a no-shared-pod 403 case; existing same-pod cases still
pass (alice+bob share a pod).
* fix(#617): sanitize agent identity in /room to clear CodeQL js/sql-injection
The new non-upsert User.findOne({username}) fed a req.body-derived
username → CodeQL js/sql-injection. Applied the strip-then-use sanitizer
CodeQL recognises (same pattern as routes/registry/install.ts): agentName/
instanceId/username are stripped to [a-z0-9-] before the query. No
behavior change for valid inputs (usernames are already that charset).
* fix(#617): put phase4RateLimit before auth on POST /pods for CodeQL recognition
CodeQL's js/missing-rate-limiting only credits a limiter that PRECEDES
the other route middleware (documented in install.ts/uploads.ts). The
limiter was present but second (after agentRuntimeAuth) so the query
still flagged the DB access. Reordered to first — the key generator reads
the auth header directly, so it works pre-auth.1 parent 7a42db7 commit 345e084
2 files changed
Lines changed: 71 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
202 | 202 | | |
203 | 203 | | |
204 | 204 | | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
205 | 242 | | |
206 | 243 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
591 | 591 | | |
592 | 592 | | |
593 | 593 | | |
594 | | - | |
595 | | - | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
596 | 601 | | |
597 | 602 | | |
598 | 603 | | |
599 | 604 | | |
600 | | - | |
601 | | - | |
602 | | - | |
603 | | - | |
604 | | - | |
605 | | - | |
606 | | - | |
607 | | - | |
608 | | - | |
609 | | - | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
610 | 615 | | |
611 | 616 | | |
612 | 617 | | |
613 | 618 | | |
614 | 619 | | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
615 | 632 | | |
616 | 633 | | |
617 | 634 | | |
| |||
2287 | 2304 | | |
2288 | 2305 | | |
2289 | 2306 | | |
2290 | | - | |
| 2307 | + | |
| 2308 | + | |
| 2309 | + | |
| 2310 | + | |
| 2311 | + | |
2291 | 2312 | | |
2292 | 2313 | | |
2293 | 2314 | | |
| |||
0 commit comments