Repository navigation
fix(posts): scope post listings to the caller's pods; gate follows, likes and comments on the post's pod - #2185
Merged
Merged
Conversation
- GET /api/posts/search: with no podId, results are global posts plus the pods the caller can view, pushed into the query as one podId filter. A named podId takes the same canViewPod gate as GET /api/posts?podId= (404 missing pod, 403 not viewable). - GET /api/posts/following/threads: drops threads whose pod the caller can no longer view. - POST/DELETE /api/posts/:id/follow: require canViewPod on the post's pod. Global posts stay open. - POST /api/posts/:id/comments: commenting on a pod post requires pod membership (callerHasPodWriteAccess). The mention and activity records take their pod from the post; the request-body podId is no longer read. - DMService.listViewablePodIds: the set form of canViewPod (admin -> all pods; otherwise memberships plus the agent-dm fan-out), with a test asserting the two agree over one fixture. POST/DELETE /api/messages/:messageId/follow already checked the message's own pod with the shared write gate for both human and agent callers; this adds executing coverage of that refusal path. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01UPw8eqDcnT3Q6yPxVqpAC1
… check the pod - GET /api/posts with no podId now returns global posts plus the caller's own pods, the same filter search uses. - Listing surfaces (feed and search with no podId, followed threads) use DMService.listPodIdsForListing: membership plus the agent-dm fan-out, with no admin bypass. A named podId and reads by id keep canViewPod, admin bypass included. The filter carries ObjectIds so the hot sort's aggregate $match applies it. - GET /api/posts?podId=<id> filters on the pod's ObjectId, so the hot sort returns that pod's posts (the query string matched none). - POST /api/posts/:id/like (like and unlike) on a pod post requires pod membership (callerHasPodWriteAccess). Global posts unchanged. - DELETE /api/posts/:id/follow no longer checks pod access, so a user can always remove their own follow. Following still requires canViewPod. - ApiDevPage: the posts list, get-by-id and search entries require auth. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01UPw8eqDcnT3Q6yPxVqpAC1
…t every posts route - podId from the request (feed, search, create) is checked with mongoose.Types.ObjectId.isValid and cast to an ObjectId before it reaches a query (docs/security-patterns.md). A malformed podId is a 400; 'global'/'none' still work on reads. - category and each tag are coerced to strings before reaching a filter, so an object in the query string is matched as text. - routes/posts.ts: inline read (240/min) and write (60/min) limiters, the same budgets as routes/messages.ts, keyed on a hash of the caller's token (Authorization or x-auth-token) rather than IP, and placed ahead of auth on every route. The posts.ts rows leave the rate-limit guard baseline. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01UPw8eqDcnT3Q6yPxVqpAC1
lilyshen0722
commented
Oct 14, 2026
lilyshen0722
left a comment
Contributor
Author
There was a problem hiding this comment.
Review at 11f7b4e (eng lead, code and security gate; my reading of fac5fa2's logic carries forward, and this binds the PASS to the head that includes the CodeQL fixes).
Checked:
- Listing scope: the feed (recent, hot, total) and search without a podId return global posts plus
DMService.listPodIdsForListing, which is membership plus the §3.7 agent-dm fan-out with no admin bypass. A named podId and reads by id still go throughcanViewPod. - Writes and follows: like/unlike and comments require membership on pod posts, and the mention and activity pod comes from the post. Follow requires
canViewPod, followed threads are re-filtered against current visibility on every read, and unfollow is always allowed. - Input: a query or body
podIdmust passObjectId.isValidand is cast before any query (feed, search, create), with 'global' and 'none' kept.categoryandtagsare coerced to strings. This is the canonical sanitizer in docs/security-patterns.md, and it closes main's js/sql-injection record on this file. - Rate limits: all 13 routes in routes/posts.ts carry an inline read (240/min) or write (60/min) limiter ahead of
auth. The key is a hash of Authorization or x-auth-token, falling back to the Cloudflare-aware IP key. The per-process buckets match messages.ts; I accept that as Cofounder noted. - CI: CodeQL reports no new alerts and nothing was dismissed. All checks are green.
- Tests at this head: 55 backend suites touching posts, DM visibility, thread state and the rate-limit guard pass (588 tests), and lint shows 0 errors on the changed files.
Product consequence, ruled acceptable by Cofounder: category=Social lists now reach only members of the Global Social Feed pod. I'll check at deploy that any curator agent still reading them is a member.
GATE: PASS
samxu01
pushed a commit
that referenced
this pull request
Oct 14, 2026
Picks up #2185. The only conflict was routeRateLimitGuard.baseline.json: main's version is kept, minus the seven moltbot rows this branch retires. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01UPw8eqDcnT3Q6yPxVqpAC1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Post routes now check the post's own pod, under three rules:
podId, and followed threads) show global posts plus the caller's own pods. Admins get no bypass on these, per the CLAUDE.md rule that admins don't bypass membership on default listing surfaces.DMService.canViewPod, admin bypass included. This is unchanged forGET /api/posts/:idandGET /api/posts?podId=.callerHasPodWriteAccess.Global posts (no pod) are open to any signed-in user throughout. Refusals are 403 with a JSON
error.What each endpoint now checks
GET /api/postswith nopodId(the main feed)total.GET /api/posts?podId=<id>canViewPod: 404 for a missing pod, 403 for one the caller can't view). The filter now uses the pod's ObjectId, so the hot sort returns the pod's posts; before, the query string matched nothing in the aggregate$match.GET /api/posts/searchpodId, the same listing filter as the feed. A namedpodIdgoes throughcanViewPod, as on the feed.podId=global/noneis unchanged.GET /api/posts/following/threadsPOST /api/posts/:id/followcanViewPodon the post's pod. Global posts stay open.DELETE /api/posts/:id/followPOST /api/posts/:id/like(like and unlike)callerHasPodWriteAccess). Global posts are unchanged.POST /api/posts/:id/commentscallerHasPodWriteAccess). The agent-mention enqueue and thethread_commentactivity take their pod from the post, and the request-bodypodIdis no longer read. On a global post the mention still falls back to a pod the commenter belongs to.POST/DELETE /api/messages/:messageId/followcallerHasPodWriteAccess, for both human (req.userId) and agent (req.agentUser) callers. This PR adds tests that run that refusal path.DELETE /api/posts/:id/comments/:commentId,PATCH /api/posts/:id/agent-commentsInput validation and rate limits
podIdfrom the request (feed, search, create post) is checked withmongoose.Types.ObjectId.isValidand cast withnew mongoose.Types.ObjectId(...)before it reachesPod.findByIdor aPostfilter. This is the sanitizer indocs/security-patterns.md. A malformedpodIdis a 400{ error: 'Invalid podId' }.globalandnonestill work on reads.categoryand each tag are coerced to strings before they reach a filter. An object in the query string (for examplecategory[$ne]=x) is now matched as text rather than treated as an operator.routes/posts.ts. There are two inlinerateLimit({...})limiters, built the same way as inroutes/messages.ts.GET /,/search,/following/threads,/:id): 240 per minute.Authorizationorx-auth-token, the two headersmiddleware/authreads), not on IP. In productionreq.ipis a cloudflared pod for every caller.authon every route. Theroutes/posts.tsrows are removed from the rate-limit guard baseline.mainhas the same rate-limiting alert on those routes, and it is one limiter for the whole file.DMService.listPodIdsForListing(userId)is new and sits next tocanViewPod. It returns the podscanViewPodadmits minus the admin bypass: the user's memberships plus the agent-dm pods that share a member with one of them. The listing filter passes ObjectIds because the hot sort runs it through an aggregate$match, which Mongoose does not cast.docs/development/BACKEND.mdnow describes these rules, and the comments row no longer lists apodIdbody field. InApiDevPage.tsx, the posts list, get-by-id and search entries now say auth is required, which has been the case since those routes started requiring auth.Known scaling note. The agent-dm fan-out query in
listPodIdsForListingpasses every co-member id of the user's pods to$in. For a user in a pod with thousands of members, that list is large. It is left as is for now.Behaviour to be aware of. External social feed posts are stored in the pod of their integration (the "Global Social Feed" pod for global feeds). After this change,
GET /api/posts?category=Socialwith nopodIdreturns them only to members of that pod.Tests
All tests run on memory Mongo with the real models and access services. Only the JWT check and the mention fan-out are stubbed. Suites were run individually on Node 22.
backend/__tests__/unit/routes/posts.podAccess.test.js(new, 42 tests):total; an admin gets only their own pods; an admin naming a pod still reads it; a non-member naming a pod gets 403; a named pod works on the hot sort;podId=globalandpodId=nonereturn global posts only; a malformedpodIdor one sent as an object gets 400; acategorysent as an object is matched as text.categoryandtagssent as objects matched as text.podIdgets 400 and nothing is created; a valid pod still works.likedByunchanged; global posts are open.backend/__tests__/unit/controllers/threadStateController.podAccess.test.js(new, 6 tests): message follow and unfollow. A member is allowed; a non-member gets 403 with no row written or changed; an agent in the pod is allowed; an agent outside it gets 403.backend/__tests__/services/dmService.agentDm.test.ts(+4 tests):listPodIdsForListingequalscanViewPod's set for non-admin members, fan-out readers and outsiders.canViewPodadmits every pod while the listing returns only the pods they had before promotion.backend/__tests__/unit/routes/posts.test.js(+13 tests): a presence test, not a timing test. Every read route answers with the 240 limiter'sRateLimit-Limitheader and every write route with the 60 limiter's. A request thatauthrefuses still carries the header, which shows the limiter runs first.backend/__tests__/unit/routes/routeRateLimitGuard.test.js: passes with the 12routes/posts.tsbaseline rows removed.frontend/src/components/ApiDevPage.test.tsx: passes unchanged.Result: 6 backend suites with 108 tests and 1 frontend suite with 8 tests, all passing.
npm run lint:tsreports 0 errors.CodeQL on the head: "No new alerts in code changed by this pull request", and no open alerts on
routes/posts.tsorcontrollers/postController.tson the PR ref.Mutation check. 26 single-site reverts against this head, each restored from a saved copy, and each turned its paired tests red while the suite still ran its full test count:
podIdObjectId guard and cast on the feed, search and create post.category(feed and search) and oftags.auth, and putting a write route on the read budget.🤖 Generated with Claude Code
https://claude.ai/code/session_01UPw8eqDcnT3Q6yPxVqpAC1