Summary
Multiple repository classes in Hi.Events accept a user-controlled sort_by query parameter and pass it directly into Eloquent's orderBy() without validation, enabling SQL injection.
In PostgreSQL-backed deployments, this can allow attackers to inject arbitrary SQL, potentially including stacked queries, when they can influence sorting parameters on list or search endpoints.
Affected context
This vulnerability occurs in Hi.Events when HTTP endpoints expose a sort_by (or similar) query parameter that is mapped directly into Eloquent's orderBy() method.
It typically appears in listing, searching, or filtering views where the client can choose how results are sorted.
The issue is most severe when the underlying database is PostgreSQL with support for stacked queries and when database privileges allow modification or exfiltration of sensitive tables.
Exploit preconditions
- Attack surface: Public or authenticated web endpoints that accept a sort_by query parameter or equivalent.
- Required access: Ability to send crafted HTTP requests to affected listing/search APIs or pages.
- Trigger point: Backend repository classes calling orderBy() with user input interpolated into the column or direction argument without whitelisting or normalization.
- Why exploitation is possible: Eloquent's orderBy() is invoked with unsanitized user data, allowing injection of arbitrary SQL fragments because the ORM does not automatically parameterize identifiers or raw expressions supplied by the caller.
Why this happens
The underlying bug is a classic SQL Injection (CWE-89) issue where user input is incorporated into SQL query construction without proper validation or parameterization.
Instead of restricting sort_by to a fixed set of known, safe column names and directions, the repositories pass the raw query parameter into orderBy(), effectively treating untrusted data as part of the SQL structure.
ORMs like Eloquent only provide protection when using bound parameters and explicit query building patterns; using dynamic strings for identifiers or expressions bypasses that safety and reintroduces direct string concatenation into SQL.
Potential impact
- Reading data from tables that the application account can access, including user profiles, ticket information, and event metadata.
- Modifying or deleting records, potentially impacting ticket sales, reservations, or event configuration.
- Creating or modifying administrative or privileged accounts if the schema permits.
- Executing stacked queries on PostgreSQL, which can further expand impact depending on database permissions and extensions.
- Bypassing application-level authorization checks by directly querying or updating protected data.
General mitigation guidance
Effective mitigation centers on eliminating direct use of untrusted input in query structure and enforcing strict whitelisting:
- Restrict sort_by and similar parameters to a predefined map of allowed sort keys and directions; reject or default on unknown values.
- Use stable, internal identifiers (e.g., "name", "date", "price") that map to concrete column names instead of accepting arbitrary column or expression strings from the client.
- Avoid passing raw user input into orderBy() or other query builder methods that treat arguments as identifiers or SQL fragments; prefer parameterized queries and ORM abstractions that do not expose SQL syntax directly.
- Apply principle of least privilege at the database level so that even if a query is abused, the account has only minimal rights.
- Centralize sorting and filtering utilities so that validation and whitelisting are consistently applied across all repositories.
How teams detect issues like this
High-level detection typically involves both code-centric and behavior-centric approaches:
- Static analysis: Configure rules to flag uses of orderBy(), raw(), or similar query builder methods where arguments are derived from request parameters without validation against an allowlist.
- Code review: During pull requests, examine any dynamic query-building logic, especially for sorting, filtering, and searching, to ensure only whitelisted fields and directions are permitted.
- Security testing: Use automated scanners and fuzzing tools to send unexpected values in sorting and filtering parameters and observe database errors or anomalous responses that suggest SQL parsing issues.
- Runtime monitoring: Enable database query logging or application-level instrumentation to detect irregular SQL patterns, including injected clauses or stacked statements, and correlate them with incoming requests.

