Repository navigation
Conversation
ListWithParams built the ORDER BY clause with sortBy + " " + sortOrder, both taken straight from the sort_by and sort_order query params on GET /api/v1/transcription/list with no validation. Anything after the column name in sortBy reaches the query as-is. sortBy is now checked against a fixed set of actual column names, and sortOrder against asc/desc. Anything else falls back to the existing default sort (created_at desc) instead of reaching the query. Added tests: a sortBy value with a trailing SQL fragment is rejected (falls back to default sort rather than erroring or building the query), and a real column name still sorts correctly. Confirmed the first test fails against the old code, the driver actually receives the injected ORDER BY text as part of the query.
|
Independent review: this issue is still present on current This PR is still mergeable. Current The Actions run is currently marked failed, but GitHub exposes zero jobs for that run, so there is no visible indication that the code or tests themselves failed. The patch is narrow, preserves the existing default sort behavior, and adds coverage for both rejected unknown sort fields and a valid sort field. Given that the report has already been public for some time and the affected code remains in the released branch, merging or rebasing this fix promptly would reduce exposure rather than meaningfully increase it. |
Fixes #468.
ListWithParamsbuilt the ORDER BY clause withsortBy + " " + sortOrder, and both come straight from thesort_by/sort_orderquery params onGET /api/v1/transcription/listwith no validation. Anything past the intended column name in
sortByreaches the query text as-is.
sortByis now checked against a fixed set of the actual sortablecolumn names (
created_at,updated_at,title,status,audio_path), andsortOrderagainstasc/desc. Anything elsefalls back to the existing default sort (
created_at desc) instead ofreaching the query, same as an empty
sortByalready did before.Tests. Added two tests in
internal/repository/implementations_test.goagainst an in-memory sqlite DB: a
sortByvalue with a trailing SQLfragment is rejected and falls back to the default sort instead of
reaching the query, and a real column name still sorts correctly. Ran
the first one against the old code first, and the driver actually
received the injected text as part of the query
(
ORDER BY id; DROP TABLE transcription_jobs; -- desc), confirmingthe injection reaches the database layer.
go vetandgofmtareclean on the changed files, and the full
internal/repositorypackagesuite passes.