Summary
SuiteCRM's AOR_Reports module contains a second-order SQL injection issue where a user-controlled field_function value is stored in the database and later concatenated into a SQL SELECT query without sanitization.
Any authenticated user with access to the Reports feature can abuse this behavior to extract arbitrary database contents, and on MySQL instances with FILE privilege, this may be escalated to remote code execution via SELECT INTO OUTFILE.
Affected context
This vulnerability arises in SuiteCRM deployments where:
- The AOR_Reports module is enabled and accessible to authenticated users.
- Users are allowed to create or edit reports, causing their POSTed
field_functiondata to be stored in theaor_fieldstable without validation. - Stored
field_functionvalues are later interpolated directly into SQL SELECT queries at report execution time.
The issue is most impactful where the CRM database contains sensitive data such as password hashes, API tokens, or configuration secrets, and where the underlying MySQL instance grants FILE or similarly powerful privileges.
Exploit preconditions
- Attack surface: Web application interface for creating/editing and viewing SuiteCRM reports (AOR_Reports module).
- Required access: Authenticated SuiteCRM account with permission to create or modify reports and to execute/view them later.
- Trigger point: Execution or viewing of a crafted report, which causes the previously stored
field_functionvalue to be concatenated into a SQL SELECT statement. - Why exploitation is possible: User-controlled input is persisted directly into the
aor_fieldstable and later used to dynamically build SQL queries without parameterization or server-side validation, enabling second-order SQL injection.
Why this happens
The root cause is the direct use of unvalidated, user-supplied data to construct SQL queries, matching CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection').
When a report is created or edited, the field_function parameter from POST data is stored as-is in the database. During report execution, this value is concatenated into a SELECT query string to define how fields are processed. Because no parameter binding, escaping, or whitelist validation is applied to field_function, an attacker can craft values that break out of the intended expression context and inject arbitrary SQL fragments.
This is a classic second-order injection pattern: the malicious payload is first stored and only becomes active when the application later reuses it in a security-sensitive context, making it harder to detect with naive input filtering.
Potential impact
- Extraction of arbitrary database data, including:
- User records and associated personal information
- Authentication-related data such as password hashes
- API keys, tokens, and configuration values stored in the database
- Enumeration or modification of other tables, depending on database privileges.
- On MySQL with FILE privilege:
- Writing attacker-controlled files to the server filesystem via SELECT INTO OUTFILE.
- Potential remote code execution by placing executable scripts or modifying application-related files.
- Use of stolen secrets to pivot into other internal systems or third-party integrations.
- Regulatory or contractual non-compliance due to exposure of customer or business-sensitive information.
General mitigation guidance
Long-term mitigation focuses on eliminating ad-hoc SQL string construction and enforcing strict control over dynamic query components:
- Replace string concatenation with parameterized queries or query builder abstractions, ensuring that user-controlled values never directly form part of SQL syntax.
- Treat
field_functionand similar "expression-like" fields as untrusted; apply allowlists of permitted functions and operators, or represent selectable functions as predefined identifiers rather than free-form text. - Introduce server-side validation and normalization for report configuration fields, rejecting or neutralizing any content that does not match an expected pattern or schema.
- Reduce database privileges for the application user, avoiding FILE and other high-risk privileges where not strictly necessary.
- Apply the principle of least privilege to SuiteCRM roles so that report creation/editing permissions are limited to trusted users.
- Consider implementing a centralized query construction layer that enforces consistent escaping and parameterization, rather than building SQL directly within feature modules.
How teams detect issues like this
Effective detection will typically combine code-centric and behavior-centric approaches:
- Static analysis: Configure SAST rules to flag:
- Direct concatenation of variables (especially values read from the database) into SQL strings.
- Dynamic query construction that bypasses parameterized APIs or ORM query builders.
- Use of "expression" or "function" fields that feed directly into SQL without pattern checks.
- Code review signals:
- Any feature that stores user input and later reuses it in queries, report builders, or filters.
- Custom reporting or analytics modules that allow users to define calculated fields or functions.
- Database access code that constructs SELECT, UPDATE, or DELETE statements from multiple uncontrolled sources.
- Runtime monitoring:
- Database activity monitoring (DAM) to detect anomalous queries, such as those referencing unexpected tables, metadata tables, or file-related operations like SELECT INTO OUTFILE.
- Application logs that capture executed report definitions and associated SQL templates for correlation and forensic analysis.
- Automated governance:
- CI/CD policies that block deploying code with flagged SQL concatenation patterns.
- Periodic security assessments focusing on reporting/configuration modules that support user-defined expressions.

