Skip to content

fix(das): validate the since query param instead of returning 500#227

Open
tryeverything24 wants to merge 1 commit into
entrius:testfrom
tryeverything24:fix-miners-since-validation
Open

fix(das): validate the since query param instead of returning 500#227
tryeverything24 wants to merge 1 commit into
entrius:testfrom
tryeverything24:fix-miners-since-validation

Conversation

@tryeverything24

Copy link
Copy Markdown

PR body — tryeverything24 — entrius/das-github-mirror

Branch: fix-miners-since-validation (in WSL Ubuntu-22.04 clone /root/dgm, commit 0e1c106, based on origin/test @ a188d3b)
Base: test
Title: fix(miners): validate since query param so malformed input returns 400, not 500


Bug

GET /api/v1/miners/:githubId/pulls?since=... and GET /api/v1/miners/:githubId/issues?since=... pass the raw since query string straight into SQL, where it hits a timestamptz comparison (p.merged_at >= $2 etc.). Any value Postgres can't parse as a timestamp makes the query itself fail, so the endpoint returns 500 Internal Server Error for what is a malformed client input:

GET /api/v1/miners/1/pulls?since=banana   -> 500 (QueryFailedError: invalid input syntax for type timestamp with time zone)
GET /api/v1/miners/1/issues?since=        -> 500 (empty string binds "" into the $2::timestamptz IS NULL check)

MinersService.resolveSince only substitutes the default window when since is falsy — a present-but-garbage value is forwarded untouched. On the /issues GET path the controller forwards since ?? null, so even an empty since= binds "" and fails the cast.

This is inconsistent with the rest of the API: the POST variants of these same endpoints (parseSinceByRepo) and the dashboard controller both validate timestamps and return 400 with a clear message. It also matters for consumers: 5xx is conventionally retryable, so a client with a bad since will retry a request that can never succeed instead of surfacing its own bug.

Fix

Add parseSinceQuery() in the controller, applied to both GET endpoints:

  • absent or empty sinceundefined, preserving existing defaults (resolveSince window on /pulls, open-issue-load null mode on /issues);
  • anything else must parse as a date, is normalized with toISOString() (same normalization as parseSinceByRepo and the dashboard controller), otherwise → BadRequestException ("since must be a valid ISO timestamp").

No service or SQL changes.

Tests

New miners.controller.spec.ts (unit, mocked MinersService):

  • garbage since on /pulls and /issuesBadRequestException, service never called;
  • valid since normalized to full ISO before reaching the service;
  • omitted since → default window on /pulls, null on /issues;
  • empty since= on /issues → treated as omitted (null) instead of binding "".

Written red-first against the current test tip: 5 of 7 cases fail before the fix, all pass after.

Local checks

  • npm test — 32 passed (4 suites)
  • npm run lint — clean
  • npm run format:check — clean
  • npm run build — clean

…400, not 500

GET /api/v1/miners/:githubId/pulls?since=... and /issues?since=... pass the
raw query string straight into a ::timestamptz cast. A non-timestamp value
(e.g. since=banana, or since= on /issues, which binds the empty string)
makes Postgres reject the cast, surfacing as a QueryFailedError 500 instead
of a 400 — misclassifying a client mistake as a server failure. Consumers
that treat 5xx as retryable (the usual convention) will then hammer a
request that can never succeed.

The POST variants of the same endpoints (parseSinceByRepo) and the
dashboard controller already validate and normalize timestamps to ISO;
this brings the two GET endpoints in line: absent/empty keeps the existing
default behavior, anything else must parse as a date and is normalized
with toISOString() before it reaches SQL.

Adds controller unit tests covering rejection, normalization, the default
window on /pulls, and the omitted/empty null mode on /issues.
@xiao-xiao-mao xiao-xiao-mao Bot added the enhancement New feature or request label Jul 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant