Skip to content

🛡️ Sentinel: [MEDIUM] Add timeouts to external fetch calls to prevent server resource exhaustion - #36

Open
felirami wants to merge 1 commit into
mainfrom
sentinel-fetch-timeouts-1927136245366074214
Open

felirami wants to merge 1 commit into
mainfrom
sentinel-fetch-timeouts-1927136245366074214

Conversation

@felirami

@felirami felirami commented Jun 30, 2026 •

Copy link
Copy Markdown
Collaborator

User description

🚨 Severity: MEDIUM
💡 Vulnerability: External fetch calls in Next.js backend routes (/api/network-status, /api/snap-market) and static generation scripts (scripts/sync-sources.mjs) lacked explicit timeouts. By default, the native fetch API does not time out, meaning network hangs or unresponsive third-party APIs (like Dexscreener, GitHub, or public nodes) could cause server routes and builds to hang indefinitely, exhausting server resources and leading to Denial of Service (DoS).
🎯 Impact: Unresponsive external services could cause the Hypersnap API endpoints to hang indefinitely, leading to resource exhaustion (e.g., connection pool depletion, high memory usage) and bringing down the Next.js server or hanging the build process.
🔧 Fix: Added explicit timeouts to all external fetch calls using signal: AbortSignal.timeout(TIMEOUT_MS):

  • 10_000ms for GitHub API calls in sync-sources.mjs.
  • 10_000ms for the public Farcaster node info probe in network.ts.
  • 10_000ms for the Dexscreener API in snap-market.ts.
    ✅ Verification: Ran npm run lint, npm run typecheck, and npm run build. Verified that the build completes successfully without errors. Tested that NODE_PROBE_TIMEOUT_MS was already correctly defined in src/lib/network.ts.

PR created automatically by Jules for task 1927136245366074214 started by @felirami


Note

Low Risk
Small, defensive networking change with no auth or data-model impact; worst case is earlier failures when third parties are slow.

Overview
Adds 10s AbortSignal.timeout guards on outbound fetch calls that previously could hang indefinitely when GitHub, Dexscreener, or the public node probe stalls.

scripts/sync-sources.mjs introduces GITHUB_TIMEOUT_MS and applies it to both fetchGithubJson and fetchGithubText. getNetworkStatus in network.ts now uses the existing NODE_PROBE_TIMEOUT_MS on its info probe. snap-market.ts adds MARKET_TIMEOUT_MS for the Dexscreener market fetch.

Existing error handling paths (e.g. timeout messaging in network.ts) should surface failures instead of leaving builds or API routes blocked on slow peers.

Reviewed by Cursor Bugbot for commit 043c27c. Bugbot is set up for automated code reviews on this repo. Configure here.


CodeAnt-AI Description

Add timeouts to external fetches so slow services don't hang the app

What Changed

  • Added a 10-second timeout to the public node status check, so the status page fails fast instead of waiting on an unresponsive node
  • Added a 10-second timeout to Snap market data requests, reducing the chance of stalled market updates
  • Added a 10-second timeout to GitHub requests used during source sync, so builds and sync jobs stop waiting indefinitely on slow GitHub responses

Impact

✅ Fewer hanging API requests
✅ Faster failure when third-party services are slow
✅ Lower risk of build or server resource exhaustion

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

Note

Add 10-second timeouts to external fetch calls to prevent server resource exhaustion

  • Adds AbortSignal.timeout(10000) to GitHub JSON and text fetches in sync-sources.mjs; requests now reject with an AbortError instead of hanging indefinitely.
  • Adds AbortSignal.timeout(NODE_PROBE_TIMEOUT_MS) to the node probe fetch in network.ts; timeouts now return ok=false with the timeout error message.
  • Adds AbortSignal.timeout(10000) to the market data fetch in snap-market.ts; timeouts return an error response with ok=false.
  • Behavioral Change: callers that previously waited indefinitely on stalled requests will now receive timeout errors after ~10 seconds.
📊 Macroscope summarized 043c27c. 3 files reviewed, 0 issues evaluated, 0 issues filtered, 0 comments posted

🗂️ Filtered Issues

No issues evaluated.

…stion

Co-authored-by: felirami <6752178+felirami@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@vercel

vercel Bot commented Jun 30, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
hypersnaporg Ready Ready Preview, Comment Jun 30, 2026 9:19pm

Request Review

@codeant-ai

codeant-ai Bot commented Jun 30, 2026

Copy link
Copy Markdown

CodeAnt AI is reviewing your PR.

@codeant-ai

codeant-ai Bot commented Jun 30, 2026

Copy link
Copy Markdown

Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@codeant-ai codeant-ai Bot added the size:XS This PR changes 0-9 lines, ignoring generated files label Jun 30, 2026
Comment thread scripts/sync-sources.mjs
"X-GitHub-Api-Version": "2022-11-28",
...(githubToken ? { Authorization: `Bearer ${githubToken}` } : {}),
},
signal: AbortSignal.timeout(GITHUB_TIMEOUT_MS),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Adding a hard timeout here makes optional: true calls fail the whole sync on transient network slowness, because aborts throw before your optional-status handling runs. Handle timeout/abort errors in fetchGithubJson when optional is true and return null so optional data fetches degrade gracefully instead of terminating the script. [api mismatch]

Severity Level: Major ⚠️
- ⚠️ Scheduled `sync-farcasterorg-sources` GitHub Action can fail.
- ⚠️ `src/data/farcasterorg-sources.json` snapshot may not refresh.
- ⚠️ Docs and node metadata in site can become stale.
- ⚠️ Optional repo-tree enrichment can now abort whole sync.
Steps of Reproduction ✅
1. From `package.json:11`, run the sync script via `npm run sync:sources`, which executes
`node scripts/sync-sources.mjs` and calls `main()` defined at
`scripts/sync-sources.mjs:247-255`.

2. Inside `main()`, the script iterates repositories and calls `buildRepoSnapshot(repo)`
at `scripts/sync-sources.mjs:254`, which in turn invokes `getRepoTree(repo.name,
defaultBranch)` at `scripts/sync-sources.mjs:182`.

3. `getRepoTree()` calls `fetchGithubJson(...)` with `{ optional: true }` at
`scripts/sync-sources.mjs:152-155`, expecting that missing tree data is treated as
optional and returning `tree?.tree ?? []` at `scripts/sync-sources.mjs:157` rather than
failing the whole run.

4. When the GitHub `git/trees` API endpoint is slow or hangs longer than 10 seconds, the
call in `fetchGithubJson()` at `scripts/sync-sources.mjs:29-37` uses `signal:
AbortSignal.timeout(GITHUB_TIMEOUT_MS)` at line 36, causing an `AbortError` to be thrown
before the `(response.status === 404 || response.status === 409) && optional` fallback at
`scripts/sync-sources.mjs:39-41` can run; because no caller catches this abort, the
promise from `getRepoTree()` rejects, `buildRepoSnapshot()` never completes, and `main()`
crashes, terminating the sync instead of degrading gracefully for this optional GitHub
request.

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** scripts/sync-sources.mjs
**Line:** 36:36
**Comment:**
	*Api Mismatch: Adding a hard timeout here makes `optional: true` calls fail the whole sync on transient network slowness, because aborts throw before your optional-status handling runs. Handle timeout/abort errors in `fetchGithubJson` when `optional` is true and return `null` so optional data fetches degrade gracefully instead of terminating the script.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

Comment thread scripts/sync-sources.mjs
"X-GitHub-Api-Version": "2022-11-28",
...(githubToken ? { Authorization: `Bearer ${githubToken}` } : {}),
},
signal: AbortSignal.timeout(GITHUB_TIMEOUT_MS),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: This timeout introduces the same contract break for optional text fetches: an abort throws and exits main() instead of returning an empty string for non-critical content. Catch timeout/abort in fetchGithubText and return "" when optional is true to preserve the function’s optional semantics. [api mismatch]

Severity Level: Major ⚠️
- ⚠️ Daily source sync workflow can terminate on slow GitHub.
- ⚠️ Optional README and docs content can crash pipeline.
- ⚠️ Docs navigation and public node metadata may not update.
- ⚠️ Upstream timeout breaks established optional-text contract.
Steps of Reproduction ✅
1. Invoke the source sync pipeline via `npm run sync:sources` (script wired in
`package.json:11`), which runs `scripts/sync-sources.mjs` and enters `main()` at
`scripts/sync-sources.mjs:247-255`.

2. For each repository, `main()` calls `buildRepoSnapshot(repo)` at
`scripts/sync-sources.mjs:254`; inside this function, optional README and docs content is
fetched via `fetchGithubText(..., { optional: true })` at
`scripts/sync-sources.mjs:179-181`, `190-195`, and `200-211`, and in the docs case further
processed by `enrichDocsLinks()` at `scripts/sync-sources.mjs:213`.

3. `enrichDocsLinks()` at `scripts/sync-sources.mjs:54-87` calls `fetchGithubText(...)`
with `{ optional: true }` at `scripts/sync-sources.mjs:59-62` and then checks `if
(!markdown)` at `scripts/sync-sources.mjs:64-66` to push placeholder entries when optional
content is missing, relying on the function’s contract to return an empty string for
non-critical failures.

4. If any of the GitHub raw-content endpoints (README, SUMMARY.md, introduction.md,
getting-started.md, or per-link markdown) are slow or hang beyond 10 seconds, the
`fetchGithubText()` implementation at `scripts/sync-sources.mjs:51-70` uses `signal:
AbortSignal.timeout(GITHUB_TIMEOUT_MS)` at line 58, causing an `AbortError` before the
`(response.status === 404 || response.status === 409) && optional` fallback at
`scripts/sync-sources.mjs:61-63` executes; this abort is not caught, so
`fetchGithubText()` rejects instead of returning `""`, which bubbles through
`enrichDocsLinks()` and `buildRepoSnapshot()` to `main()`, making the Node process exit
with an uncaught abort and preventing `src/data/farcasterorg-sources.json` from being
regenerated.

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** scripts/sync-sources.mjs
**Line:** 58:58
**Comment:**
	*Api Mismatch: This timeout introduces the same contract break for optional text fetches: an abort throws and exits `main()` instead of returning an empty string for non-critical content. Catch timeout/abort in `fetchGithubText` and return `""` when `optional` is true to preserve the function’s optional semantics.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

@codeant-ai

codeant-ai Bot commented Jun 30, 2026

Copy link
Copy Markdown

CodeAnt AI finished reviewing your PR.

This branch was successfully deployed

1 active deployment
Preview — 043c27c6 Deployed Jun 30, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS This PR changes 0-9 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant