[API] Enforce query cost limits on the unauthenticated GraphQL endpoint
Overview & Background
POST /graphql runs any posted query with createContext(prisma) and no auth, depth, or complexity guard. streams(first: ...) accepts an unbounded first; the batchEventsByStreamIds dataloader has no take, so Stream.events returns every row per stream; and resolveAccountOverview fetches all streams for an address with no cap — bypassing the truncation guard (MAX_USER_STREAMS = 500) the REST summary endpoint was deliberately given. An anonymous caller can post { streams(first: 1000000) { edges { node { events { id } } } } } and pull the database into memory.
Technical Specification & Architecture
- Cap
firstinbackend/src/graphql/resolvers/stream.resolver.ts:65and add depth/complexity limits atbackend/src/graphql/routes.ts:46-59. - Add
taketobatchEventsByStreamIds(backend/src/graphql/dataloaders/index.ts:42-56). - Mirror the REST
MAX_USER_STREAMScap inresolveAccountOverview(stream.resolver.ts:131-150). - Decide the auth posture: require the same JWT as REST, or document GraphQL as deliberately public with rate limiting.
Target Files
backend/src/graphql/routes.tsbackend/src/graphql/resolvers/stream.resolver.tsbackend/src/graphql/dataloaders/index.ts
Acceptance Criteria
- [ ]
firstis clamped to a documented maximum. - [ ] Events loader cannot return unbounded rows.
- [ ] Account overview respects
MAX_USER_STREAMS. - [ ] Query depth/complexity limits reject abusive queries with a clear error.
@Asaidsasp has applied to work on this issue as part of the Stellar Wave Program's 11th wave.
Dear maintainer, having reviewed the task and the possible solution, I think I'm fit to take take on this. Kindly assign it to me. Will submit PR right away. Please
ℹ️ Repo Maintainers: To accept this application, review their application or assign @Asaidsasp to this issue.
@Peace-001 has applied to work on this issue as part of the Stellar Wave Program's 11th wave.
Good day maintainer i would like to work on this issue
ℹ️ Repo Maintainers: To accept this application, review their application or assign @Peace-001 to this issue.
@entitydev30 has applied to work on this issue as part of the Stellar Wave Program's 11th wave.
I would like to work on this kindly assign me
ℹ️ Repo Maintainers: To accept this application, review their application or assign @entitydev30 to this issue.
@Nanafancy has applied to work on this issue as part of the Stellar Wave Program's 11th wave.
Am a fullstack developer please assign me this issue
ℹ️ Repo Maintainers: To accept this application, review their application or assign @Nanafancy to this issue.
@Stanley-Owoh has applied to work on this issue as part of the Stellar Wave Program's 11th wave.
Good day maintainer please i would like to work on this issue I have gone through the description, i can work on this immediately with positive results, please assign this issue to me Thank you
ℹ️ Repo Maintainers: To accept this application, review their application or assign @Stanley-Owoh to this issue.
Hi @LabsCrypt team! 👋
I would love to implement query cost limits on unauthenticated pool searches.
Implementation Plan:
- Query Complexity & Cost Metering:
- Introduce rate-limiting and query depth / filter limiters on public search routes to prevent expensive unbounded database queries and API exhaustion.
- Standardized 429 Responses:
- Return clean
429 Too Many Requestsresponses withRetry-Afterheaders.
- Return clean
- Testing:
- Add unit tests validating cost enforcement and standard throughput.
Could you please assign this issue to me? Ready to submit a clean PR within 2 hours! 🚀