Skip to content

Accept before/after and RFC 3339 offsets on the v3 advisory list - #106

Merged
rockythorn merged 1 commit into
resf:mainfrom
rockythorn:distro-tools/t_feb6e021-apollo-v3-advisories-honor-after-before
Nov 16, 2026
Merged

rockythorn merged 1 commit into
resf:mainfrom
rockythorn:distro-tools/t_feb6e021-apollo-v3-advisories-honor-after-before

Conversation

@rockythorn

Copy link
Copy Markdown
Collaborator

GET /api/v3/advisories/ only read its date filters from before_raw and after_raw, the Python argument names. FastAPI drops unknown query parameters, so a client sending ?after= got the whole catalog back with no error. That name is what every other filter on this endpoint, and v2's filters.after, suggest. CEM's incremental RESF sync sends after= and so walks every page on every run.

A timezone offset also broke both list APIs. parse_rfc3339_date only stripped a trailing Z, so +00:00 (Python's isoformat() for an aware datetime) or -07:00 produced an aware datetime. fetch_advisories binds that as $6 :: timestamp, and asyncpg refuses it:

asyncpg.exceptions.DataError: invalid input for query argument $6: datetime.datetime(2026, 11, 12, 20, 0, 0... (can't subtract offset-naive and offset-aware datetimes)

The request then fails with a 500. This affects the v3 list (after_raw/before_raw) and v2 filters.after/filters.before.

Changes

  • The v3 list reads before/after. before_raw/after_raw keep working as deprecated fallbacks (deprecated in OpenAPI). A request that sets both spellings of one filter gets a 400 instead of Apollo guessing which one wins. An empty or unparseable value is a 400, as it already was for the *_raw names.
  • parse_rfc3339_date converts offsets to naive UTC, the same value a Z suffix already produced. An offset that overflows the datetime range is treated as invalid input (400), not a 500. The v2 compat routes share the parser, so they get the same fix. v2's parameter names (filters.before/filters.after) were already right.
  • web/docs/apollo/openapi.md and the OpenAPI descriptions document before/after and mark the *_raw names deprecated.

Related: #96 fixes the OSV list's after= 500 inside fetch_advisories. This PR doesn't touch that file, and the two merge without conflicts between them. With both merged, #96's naive_utc() is a no-op for these routes.

Verification

  • Unit tests: test_api_advisories gained 11 tests (TestListAdvisoriesDateParams) and test_api_compat gained 3 (TestFetchAdvisoriesCompatDates). They cover Z, +00:00 with microseconds, -07:00 and +02:30, the plain and *_raw names, both names at once, and invalid, empty and overflowing values. Eleven of them fail without this change. All 17 CI unit targets pass under Bazel, and pylint scores 10.00 on the changed files.

  • Against Postgres: I ran the real v3, v2 and OSV routers against a local Postgres holding 10,433 advisories, with a cutoff of 2026-11-12T20:00:00:

    Request Before After
    v3 after=…Z 200, 10433 (ignored) 200, 9
    v3 after=…+00:00 200, 10433 (ignored) 200, 9
    v3 after=2026-11-12T13:00:00-07:00 200, 10433 (ignored) 200, 9
    v3 after_raw=…Z 200, 9 200, 9
    v3 after_raw=….160727+00:00 500 200, 9
    v3 before=2023-01-01T00:00:00+00:00 200, 10433 (ignored) 200, 4929
    v3 after=…&after_raw=… 200, 9 400
    v3 after=bad 200, 10433 (ignored) 400
    v2 filters.after=…+00:00 500 200, 9
    v2 filters.after=…-07:00 500 200, 9

GET /api/v3/advisories/ only read its date filters from before_raw and
after_raw, the Python argument names. FastAPI drops unknown query
parameters, so a client sending ?after=, the name every other filter on
this endpoint and v2's filters.after suggest, got the whole catalog back
with no error. CEM's incremental RESF sync does exactly that and walks
every page on every run.

Read before/after, keep before_raw/after_raw as deprecated fallbacks for
existing clients, and reject a request that sets both spellings of one
filter with a 400 instead of guessing which one wins. An empty or
unparseable before/after is a 400, as it already was for the *_raw
names.

parse_rfc3339_date only stripped a trailing Z, so an offset such as
+00:00 (Python's isoformat() for an aware datetime) or -07:00 produced
an aware datetime. fetch_advisories binds it as a naive timestamp and
asyncpg refuses to encode an aware value there, so the request failed
with a 500 on both the v3 list and v2 filters.before/filters.after.
Convert offsets to naive UTC, which is what a Z value already produced,
and treat an offset that overflows the datetime range as invalid input.
@rockythorn
rockythorn merged commit cb41c17 into resf:main Nov 16, 2026
1 check passed
@rockythorn
rockythorn deleted the distro-tools/t_feb6e021-apollo-v3-advisories-honor-after-before branch November 16, 2026 21:15
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.

1 participant