You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SQL Injection in PaginatedUtmLinksPresenter via Unvalidated Sort Direction #7
Source: The sort_direction variable originates from the params[:sort][:direction] parameter, likely passed through the Api::Internal::UtmLinksController#index action.
Analysis: The code validates the sort_key against an allow-list (SORT_KEYS). However, the sort_direction variable, derived from params[:sort][:direction], is directly interpolated into the Arel.sql fragment without being validated against expected values like 'asc' or 'desc'.
Impact: An attacker can manipulate the sort[direction] request parameter to inject arbitrary SQL into the ORDER BY clause. This can be used for time-based blind SQL injection to exfiltrate data, cause denial of service, or potentially perform other database operations depending on the context and database permissions.
Proof of Concept (Conceptual):
A request targeting the relevant endpoint (e.g., /api/internal/utm_links) with parameters like: ?sort[key]=created_at&sort[direction]=desc,(SELECT+CASE+WHEN+(1=1)+THEN+SLEEP(5)+ELSE+SLEEP(0)+END)
If the database is MySQL/MariaDB, this could cause a 5-second delay, confirming the injection. The exact payload needs adjustment based on the specific database system.
Recommendation: Strictly validate the sort_direction parameter against an allow-list (e.g., ['asc', 'desc']) before using it in the SQL query. If the value is not 'asc' or 'desc', default to a safe value (e.g., 'asc') or raise an error.
Activity
msrkp commentedon Apr 14, 2025