Skip to content

Validate sort/direction against SQL injection on index screens - #5

Merged
HafizMMoaz merged 1 commit into
masterfrom
fix/sort-injection
Sep 7, 2026
Merged

HafizMMoaz merged 1 commit into
masterfrom
fix/sort-injection

Conversation

@HafizMMoaz

Copy link
Copy Markdown
Member

?sort= went straight into orderBy(). Eloquent binds values but not identifiers, so the column name was interpolated into the SQL. (The direction is safe already: the framework throws on anything that is not asc/desc.)

6 call site(s) now go through a sortSafe macro that accepts the column only if it exists on the model's table, falling back to the order each screen already used with no sort.

Registered in this package's provider, guarded, because modules are installed independently with no shared dependency.

Tests: 4 cases covering an injected column, an injected direction, a valid column, and an unknown column. Verified they fail when the validation is removed.

Part of the platform-wide sweep tracked on zerp-pk/zerp#39.

The index screens ordered by a column and direction taken straight from the
query string. Eloquent binds values but not identifiers, so ?sort= was
interpolated into the SQL: a 500 on a bad column at best, an injection
surface at worst. The direction is checked by the framework, which throws
on anything that is not asc or desc, so the column is the exploitable half.

Call sites now go through a sortSafe macro that keeps the column only if it
is a real column on the model's table, and the direction only if it is asc
or desc. Each site falls back to the order it already used when no sort was
given, so an invalid sort behaves like no sort instead of erroring.

The macro is registered in this package's own provider rather than shared.
The modules are installed independently and declare no common dependency,
so one cannot rely on another having booted. The registration is guarded,
so whichever module loads first wins and the definitions are identical.

Part of the platform-wide sweep tracked on zerp-pk/zerp#39.
@HafizMMoaz
HafizMMoaz requested a review from a team as a code owner September 7, 2026 11:15
@HafizMMoaz
HafizMMoaz merged commit 5b2c5b7 into master Sep 7, 2026
2 checks passed
@HafizMMoaz
HafizMMoaz deleted the fix/sort-injection branch September 7, 2026 11:20
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