Skip to content

fix(api): avoid forced extrinsics index for broad/malformed time filters#2028

Merged
JSONbored merged 4 commits into
mainfrom
codex/propose-fix-for-extrinsics-query-dos-vulnerability
Jun 26, 2026
Merged

fix(api): avoid forced extrinsics index for broad/malformed time filters#2028
JSONbored merged 4 commits into
mainfrom
codex/propose-fix-for-extrinsics-query-dos-vulnerability

Conversation

@JSONbored

Copy link
Copy Markdown
Owner

Motivation

  • Forcing idx_extrinsics_observed_order whenever from/to were present made broad or malformed time filters (malformed values were coerced to 0) cause D1/SQLite to scan-and-sort large retained windows before LIMIT, creating an unauthenticated query-amplification/availability risk.
  • clampInt previously returned a default for non-finite inputs, which turned malformed bounds into a broad window start at epoch 0.
  • The handler must ignore malformed bounds and only force the timestamp-leading index when the observed-at window is meaningfully narrow so the query planner can pick an order-aligned path for broad public requests.

Description

  • Replace the previous coercion with a strict parseTimeBound that treats missing, empty, or non-finite from/to values as null in workers/request-handlers/entities.mjs.
  • Only force the idx_extrinsics_observed_order hint when both fromMs and toMs are present and the window is narrow (toMs - fromMs <= DAY_MS), leaving broad/malformed filters planner-selected.
  • Add regression tests in tests/request-handlers-entities.test.mjs to verify broad standalone time filters do not force the timestamp index and malformed time filters are ignored.

Testing

  • Ran the focused unit tests with npm test -- --run tests/request-handlers-entities.test.mjs and all tests passed (128 passed).
  • Ran formatting with npx prettier --check (and applied fixes), then ran npm run lint and npm run build, all of which succeeded.
  • Ran npm run validate:api and the full npm run validate after the build and both completed successfully.

Codex Task

@superagent-security

Copy link
Copy Markdown

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

@codecov

codecov Bot commented Jun 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.27%. Comparing base (796da14) to head (23d3e36).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2028   +/-   ##
=======================================
  Coverage   93.26%   93.27%           
=======================================
  Files          48       48           
  Lines        7755     7759    +4     
  Branches     2839     2840    +1     
=======================================
+ Hits         7233     7237    +4     
  Misses         92       92           
  Partials      430      430           
Files with missing lines Coverage Δ
workers/request-handlers/entities.mjs 98.70% <100.00%> (+0.01%) ⬆️
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JSONbored JSONbored self-assigned this Jun 26, 2026
@JSONbored JSONbored merged commit 940b1b4 into main Jun 26, 2026
10 checks passed
@JSONbored JSONbored deleted the codex/propose-fix-for-extrinsics-query-dos-vulnerability branch June 26, 2026 23:33
@github-actions github-actions Bot mentioned this pull request Jun 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant