Validate sort_by parameter against allowed field names in views.py #36

Closed
opened 2026-02-20 06:51:00 +00:00 by cal · 1 comment
Owner

app/routers_v3/views.py:27 — The sort_by parameter is passed to getattr(SeasonBattingStats, stat, ...). Any arbitrary string can be passed. Should be a Literal type of allowed stat column names.

Priority: medium | Labels: security, enhancement

`app/routers_v3/views.py:27` — The `sort_by` parameter is passed to `getattr(SeasonBattingStats, stat, ...)`. Any arbitrary string can be passed. Should be a `Literal` type of allowed stat column names. **Priority**: medium | **Labels**: security, enhancement
cal added the
ai-working
label 2026-03-05 17:01:27 +00:00
cal removed the
ai-working
label 2026-03-05 17:03:45 +00:00
Author
Owner

Fixed in PR #44: #44

Changed sort_by: str to sort_by: Literal[...] in both get_season_batting_stats and get_season_pitching_stats. FastAPI will now reject arbitrary strings with a 422 before they reach the getattr call. Allowed values were derived directly from the column fields defined on SeasonBattingStats and SeasonPitchingStats in db_engine.py.

Fixed in PR #44: https://git.manticorum.com/cal/major-domo-database/pulls/44 Changed `sort_by: str` to `sort_by: Literal[...]` in both `get_season_batting_stats` and `get_season_pitching_stats`. FastAPI will now reject arbitrary strings with a 422 before they reach the `getattr` call. Allowed values were derived directly from the column fields defined on `SeasonBattingStats` and `SeasonPitchingStats` in `db_engine.py`.
cal added the
ai-pr-opened
label 2026-03-05 17:03:52 +00:00
cal closed this issue 2026-03-10 18:26:21 +00:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: cal/major-domo-database#36
No description provided.