Skip to content

fix(metrics): validate metrics date-range query params#70

Merged
Bccorb merged 1 commit into
mainfrom
fix/metrics-window-validation
Jul 7, 2026
Merged

fix(metrics): validate metrics date-range query params#70
Bccorb merged 1 commit into
mainfrom
fix/metrics-window-validation

Conversation

@Bccorb

@Bccorb Bccorb commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Addresses #17 (date-window validation portion)

Summary

The metrics controller had a TODO: need to parse these for valid time ranges; from/to were passed straight into new Date(...), so an invalid value became Invalid Date and silently produced an empty or bogus filter instead of an error.

This adds validation to MetricsQuerySchema (used by both the summary and timeseries endpoints):

  • Reject unparseable from/to.
  • Reject inverted ranges (from after to).
  • Reject windows larger than ~1 year (guards against oversized/expensive scans).

Notes

  • Fixes a pre-existing test that was named "returns 400 for invalid query" but asserted 200 — it was documenting the missing validation. It now asserts 400, matching its name and the corrected behavior.
  • New unit test covers valid, empty, invalid-date, inverted, and oversized cases.

Out of scope (issue stays open)

The second half of #17 — broadening the timeseries beyond login_success/login_failed to cover OTP/WebAuthn/magic-link activity — is a larger, response-shape-affecting change and is left for a follow-up. I'll note this on the issue.

Testing

Typecheck + lint clean; metrics + internal suites pass.

Add date-window validation to MetricsQuerySchema: reject unparseable
from/to dates, inverted ranges (from after to), and windows larger than
~1 year. This removes the TODO in the metrics controller and makes both
the summary and timeseries endpoints reject bad ranges with 400 instead
of silently coercing Invalid Date into the query.

Fix a pre-existing internal test that was named 'returns 400 for invalid
query' but asserted 200 (it documented the missing validation). Add unit
coverage for the schema.

Addresses #17 (date-window validation). Broadening the timeseries beyond
login success/failure remains open.
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.66667% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/schemas/internal.query.ts 86.66% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@Bccorb Bccorb merged commit a18d278 into main Jul 7, 2026
2 of 3 checks passed
@Bccorb Bccorb deleted the fix/metrics-window-validation branch July 7, 2026 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants