flowfi icon indicating copy to clipboard operation
flowfi copied to clipboard

[API] Enforce query cost limits on the unauthenticated GraphQL endpoint

Open blurbeast opened this issue 1 week ago • 4 comments

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

  1. Cap first in backend/src/graphql/resolvers/stream.resolver.ts:65 and add depth/complexity limits at backend/src/graphql/routes.ts:46-59.
  2. Add take to batchEventsByStreamIds (backend/src/graphql/dataloaders/index.ts:42-56).
  3. Mirror the REST MAX_USER_STREAMS cap in resolveAccountOverview (stream.resolver.ts:131-150).
  4. 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.ts
  • backend/src/graphql/resolvers/stream.resolver.ts
  • backend/src/graphql/dataloaders/index.ts

Acceptance Criteria

  • [ ] first is 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.

blurbeast avatar Nov 18 '26 19:11 blurbeast

@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.

Asaidsasp avatar Nov 21 '26 08:11 Asaidsasp

@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.

Peace-001 avatar Nov 21 '26 11:11 Peace-001

@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.

entitydev30 avatar Nov 21 '26 14:11 entitydev30

@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.

Nanafancy avatar Nov 21 '26 22:11 Nanafancy

@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.

Stanley-Owoh avatar Nov 22 '26 08:11 Stanley-Owoh

Hi @LabsCrypt team! 👋

I would love to implement query cost limits on unauthenticated pool searches.

Implementation Plan:

  1. 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.
  2. Standardized 429 Responses:
    • Return clean 429 Too Many Requests responses with Retry-After headers.
  3. 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! 🚀

sparkysolutions10-pixel avatar Nov 29 '26 17:11 sparkysolutions10-pixel