Skip to content

fix(github): add the Content-Length DoS pre-check to handleOrbRelay - #8940

Merged
loopover-orb[bot] merged 2 commits into
JSONbored:mainfrom
kai392:fix/critical-issue-orb-relay-content-length
Jul 26, 2026
Merged

fix(github): add the Content-Length DoS pre-check to handleOrbRelay#8940
loopover-orb[bot] merged 2 commits into
JSONbored:mainfrom
kai392:fix/critical-issue-orb-relay-content-length

Conversation

@kai392

@kai392 kai392 commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Summary

handleGitHubWebhook rejects an oversized request via a content-length header check (413
fast-path) before touching the body (#197, "Harden GitHub webhook endpoint against large-body DoS").
handleOrbRelay — which processes the identical GitHub payload shape — went straight to
readBodyWithLimit, enforcing the byte cap only after buffering up to it. The two receivers diverged
on this bound with no explanation.

Adds the same content-length pre-check (413 before touching the body) to handleOrbRelay, matching
handleGitHubWebhook's existing pattern exactly.

Test plan

  • New: an oversized content-length header returns 413 with a bad signature — proving the pre-check short-circuits before the body is read/verified (would be 401 otherwise)
  • New: a within-cap content-length header still reaches 202 (the pre-check doesn't false-positive)
  • Non-vacuity verified: removing the pre-check makes the oversized request fall through to a 401 and the 413 test fails
  • npx vitest run test/unit/webhook.test.ts — 23/23 pass; tsc --noEmit clean

Closes #8888

@kai392
kai392 requested a review from JSONbored as a code owner July 26, 2026 13:52
@superagent-security

Copy link
Copy Markdown
Contributor

Superagent didn't find any vulnerabilities or security issues in this PR.

RealDiligent and others added 2 commits July 26, 2026 21:56
handleGitHubWebhook rejects an oversized request via a content-length header check (413 fast-path)
before touching the body (JSONbored#197). handleOrbRelay, processing the identical GitHub payload shape, went
straight to readBodyWithLimit — enforcing the cap only after buffering up to it. Add the same
content-length pre-check so an oversized relay request is rejected at the header stage, matching
handleGitHubWebhook's DoS-hardening pattern exactly.

Closes JSONbored#8888

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@codecov

codecov Bot commented Jul 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.59%. Comparing base (469e8e6) to head (76e77ee).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8940      +/-   ##
==========================================
+ Coverage   90.56%   90.59%   +0.03%     
==========================================
  Files          96       97       +1     
  Lines       22490    22584      +94     
  Branches     3884     3914      +30     
==========================================
+ Hits        20367    20461      +94     
  Misses       1945     1945              
  Partials      178      178              
Flag Coverage Δ
backend 100.00% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/github/webhook.ts 100.00% <100.00%> (ø)

@loopover-orb loopover-orb Bot added the gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. label Jul 26, 2026
@loopover-orb

loopover-orb Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Tip

✅ LoopOver review result - approve/merge recommended

Review updated: 2026-07-26 14:14:31 UTC

2 files · 1 AI reviewer · no blockers · readiness 93/100 · CI green · clean

✅ Suggested Action - Approve/Merge

  • safe to merge

Review summary
This PR adds the identical Content-Length pre-check that handleGitHubWebhook already uses to handleOrbRelay, closing the gap where the relay receiver only enforced the body-size cap after buffering. The change is a straightforward copy of the existing pattern (src/github/webhook.ts:80-83 mirrored at :242-246), and the two new tests correctly prove the pre-check fires (413 with a bad signature that would otherwise yield 401) and doesn't false-positive on an in-cap request. This is a narrow, well-targeted fix tied to a real behavioral divergence between two receivers processing the same payload shape.

Nits — 5 non-blocking
  • src/github/webhook.ts:80-83 and :242-246 now duplicate the same content-length pre-check logic verbatim — consider factoring it into a small shared helper (e.g. `checkContentLengthCap(header, max)`) to avoid drift if the cap logic ever changes.
  • The `413` status magic number recurs at src/github/webhook.ts:244 same as the existing one at line ~82 — pre-existing pattern, not introduced here, but a named constant would help if you touch this again.
  • The flagged 'secret' strings in test/unit/webhook.test.ts:696/711 are test fixture values (`orbenr_testsecret`), not real credentials — no action needed.
  • Consider extracting the repeated Content-Length pre-check into a shared helper used by both handleGitHubWebhook and handleOrbRelay to keep the two receivers from re-diverging in the future.
  • Possible secret-shaped assignment in the diff (generic_secret_assignment) — Verify the value is not a real credential.

Decision drivers

  • ✅ Code review — No blockers (1 reviewer)
  • ✅ Gate result — Passing (No configured blocker found.)
Context & advisory signals — never blocks the verdict
Signal Result Evidence
Linked issue ✅ Linked #8888
Related work ✅ No active overlap found No same-issue or scoped active PR overlap found.
Change scope ✅ 20/20 Low review scope from cached public metadata (1 linked issue).
Validation posture ✅ 25/25 PR body includes validation/test evidence.
Contributor workload ✅ 10/10 Author activity: 133 registered-repo PR(s), 66 merged, 6 issue(s).
Contributor context ✅ Confirmed Gittensor contributor kai392; Gittensor profile; 133 PR(s), 6 issue(s).
Improvement ✅ Minor risk: clean · value: minor · LLM: minor
Linked issue satisfaction

Addressed
The PR adds a content-length pre-check to handleOrbRelay that returns 413 before readBodyWithLimit is called, matching handleGitHubWebhook's pattern, and includes tests verifying both the oversized-rejection (413 vs. would-be 401) and within-cap acceptance cases.

Review context
  • Author: kai392
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: Python, Cuda, JavaScript, Kotlin, Perl, TypeScript, Vue
  • Official Gittensor activity: 133 PR(s), 6 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Start here: Triage stale or unlinked PRs.
Signal definitions
  • Related work = same linked issue, overlapping active PRs, or title/path similarity.
  • Change scope = cached public metadata such as size labels, draft state, and review-burden hints.
  • Validation posture = whether the PR provides enough public validation/test evidence for maintainer review.
  • Contributor workload = public contributor activity and cleanup pressure, not a repo-wide quality failure.
  • Contributor context = public GitHub/Gittensor identity context; non-Gittensor status is not a blocker.
🧪 Chat with LoopOver

Ask LoopOver a question about this PR directly in a comment — grounded only in the same cached, public-safe facts shown above, never a new claim.

  • @loopover ask &lt;question&gt; answers contribution-quality Q&A with source citations and freshness.
  • @loopover chat &lt;question&gt; answers in natural prose from cached decision-pack facts via local inference (maintainer/collaborator; read-only).
  • A plain-language @loopover mention with a real question is routed to the closest matching read-only command automatically — no exact syntax required.

Full command reference: https://loopover.ai/docs/loopover-commands

🧪 Experimental — new and may change.

🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed


💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →.

Checked by LoopOver, a quiet PR intelligence layer for OSS maintainers.

  • Re-run LoopOver review

@loopover-orb loopover-orb Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LoopOver approves — the gate is satisfied and CI is green.

@loopover-orb
loopover-orb Bot merged commit e24584d into JSONbored:main Jul 26, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(github): handleOrbRelay skips the pre-read Content-Length rejection that handleGitHubWebhook has

2 participants