GHSA-3gw8-3mg3-jmpc OpenSTAManager has a Time-Based Blind SQL Injection via `options[stato]` Parameter
DescriptionMultiple AJAX select handlers in OpenSTAManager <= 2.10.1 are vulnerable to Time-Based Blind SQL Injection through the `options[stato]` GET parameter. The user-supplied value is read from `$superselect['stato']` and concatenated directly into SQL WHERE clauses as a bare expression, without any sanitization, parameterization, or allowlist validation.An authenticated attacker can inject arbitrary SQL statements to extract sensitive data from the database, including usernames, password hashes, financial records, and any other information stored in the MySQL database.Affected EndpointsThree modules share the same vulnerability pattern:1. Preventivi (Quotes) - Primary**Endpoint:** `GET /ajax_select.php?op=preventivi`**File:** `modules/preventivi/ajax/select.php`, line 60**Required parameters:** `options[idanagrafica]` (any valid ID)**Vulnerable code:**The `$stato` variable is inserted as a bare expression inside parentheses. The resulting SQL fragment becomes `({user_input} = 1)`, allowing an attacker to break out of the expression and inject arbitrary SQL.2. Ordini (Orders)**Endpoint:** `GET /ajax_select.php?op=ordini-cliente`**File:** `modules/ordini/ajax/select.php`, line 52**Required parameters:** `options[idanagrafica]` (any valid ID)**Vulnerable code:**The `$stato` variable is inserted as a column name reference. The resulting SQL fragment becomes `` `or_statiordine`.{user_input} = 1 ``, allowing injection after the table-column reference.3. Contratti (Contracts)**Endpoint:** `GET /ajax_select.php?op=contratti`**File:** `modules/contratti/ajax/select.php`, line 57**Required parameters:** `options[idanagrafica]` (any valid ID)**Vulnerable code:**The `$stato` variable is inserted inside a subquery. The resulting SQL fragment becomes `WHERE {user_input} = 1)`, allowing an attacker to close the subquery and inject into the outer query.Root Cause AnalysisData FlowThe attacker sends a GET request with `options[stato]=<payload>` to `/ajax_select.php``ajax_select.php` (line 30) reads the value via `filter('options')`, which applies HTMLPurifier sanitizationHTMLPurifier strips HTML tags and the `>` character, but does **NOT** strip SQL keywords (`SELECT`, `SLEEP`, `IF`, `UNION`, etc.) or SQL-significant characters (`(`, `)`, `=`, `'`, etc.)The sanitized value is passed to `AJAX::select()` in `src/AJAX.php` (line 40)`AJAX::getSelectResults()` assigns `$superselect = $options` (line 273) and `require`s the module's `select.php` file (line 275)The module's `select.php` reads `$superselect['stato']` and concatenates it directly into the `$where[]` array`AJAX::selectResults()` joins all WHERE elements with `AND` and executes the query via `Query::executeAndCount()` (line 120)Why HTMLPurifier is InsufficientHTMLPurifier is an HTML sanitization library designed to prevent XSS attacks. It is **not** an SQL injection prevention mechanism. Specifically:It does **not** strip SQL keywords: `SELECT`, `SLEEP`, `IF`, `UNION`, `FROM`, `WHERE`It does **not** strip SQL operators: `=`, `(`, `)`, `,`, `+`, `-`, `*`It strips the `>` character (used in HTML), which can be bypassed using MySQL's `GREATEST()` functionIt provides zero protection against SQL injectionProof of ConceptPrerequisitesA valid user account on the OpenSTAManager instance (any privilege level)Network access to the applicationStep 1: AuthenticateSave the `PHPSESSID` cookie from the `Set-Cookie` response header.Step 2: Verify Injection (SLEEP test)**Baseline request** (normal response time ~200ms):**Injection request** (response time ~10 seconds):**Expected result:** The response is delayed by approximately 10 seconds, confirming that the `SLEEP(10)` function was executed by the database server. The response body in both cases is identical: `{"results":[],"recordsFiltered":0}`.Step 3: Data Extraction (demonstrating impact)Using binary search with time-based boolean conditions, an attacker can extract arbitrary data. The `>` character is stripped by HTMLPurifier, so the `GREATEST()` function is used as an equivalent:**Extract username length:**This technique was used to successfully extract:**Username:** `admin` (5 characters, extracted character by character)**Password hash prefix:** `$2y$10$qAo04wNbhR9cpxjHzrtcnu...` (bcrypt)**MySQL version:** `8.3.0`PoC for Other Endpoints**Ordini (orders):****Contratti (contracts):**Both endpoints show the same SLEEP-based timing delay, confirming the injection.Impact**Confidentiality:** An attacker can extract the entire database contents, including user credentials (usernames and bcrypt password hashes), personal identifiable information (PII), financial records (invoices, quotes, contracts, payments), and application configuration.**Integrity:** With MySQL's `INSERT`/`UPDATE` capabilities via subqueries, an attacker may be able to modify data.**Availability:** An attacker can execute `SLEEP()` with large values or resource-intensive queries to cause denial of service.Proposed RemediationOption A: Allowlist Validation (Recommended)Replace the direct concatenation with an allowlist of permitted column names:This approach is recommended because the `stato` parameter represents a database column name (not a value), so prepared statements cannot be used here. The allowlist ensures only known-safe column names are accepted.Option B: Regex Validation (Alternative)If the set of column names is dynamic, validate the format strictly:This ensures only alphabetic characters and underscores are accepted, preventing any SQL injection.Option C: Backtick Quoting (Supplementary)In addition to validation, wrap the column name in backticks to treat it as an identifier:**Note:** This alone is insufficient without input validation but provides defense-in-depth.Global RecommendationAudit all usages of `$superselect` across the codebase. Any value from `$superselect` that is used as part of a SQL expression (not as a parameterized value) must be validated against an allowlist. The `prepare()` function is already used correctly in other parts of the code — the issue is specifically where `$superselect` values are used as column names or bare expressions.CreditsOmar Ramirez
CVSS v3.1 score: 8.8