Summary
RuoYi v4.8.2 contains a SQL injection vulnerability in the /tool/gen/createTable endpoint of the code generation module.
An authenticated attacker with administrative privileges can craft malicious input that manipulates backend SQL queries, potentially exposing sensitive database information and other data.
Affected context
The vulnerability occurs in RuoYi deployments using the code generation feature exposed via the /tool/gen/createTable endpoint.
It manifests when user-supplied parameters from the admin interface are directly embedded into SQL statements without robust validation or parameterization.
This risk is present in environments where administrative accounts are used to define or generate database-backed entities and the application trusts these inputs as safe.
Exploit preconditions
- Attack surface: HTTP interface of the RuoYi admin backend, specifically the
/tool/gen/createTableendpoint. - Required access: Valid, authenticated account with administrative-level permissions to access the code generation module.
- Trigger point: Submission of crafted parameters (e.g., table names or related metadata) that are used to construct SQL queries.
- Why exploitation is possible: The server-side logic constructs SQL dynamically using attacker-influenced values without consistent parameter binding, escaping, or whitelist-based validation, allowing injected SQL fragments to be executed by the database.
Why this happens
This issue stems from constructing SQL statements using concatenated strings that incorporate user-controllable input from the code generation interface.
Rather than using prepared statements or strict, validated mappings to known-safe identifiers, the implementation allows arbitrary values from the request to flow into SQL.
This pattern aligns with CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection'), where the database interprets attacker-controlled input as part of the SQL syntax rather than as data.
Potential impact
- Access to sensitive database records that the attacker's account would not normally be able to query.
- Enumeration of database schema, including table names, columns, and relationships.
- Modification or deletion of data in arbitrary tables, potentially causing integrity loss.
- Bypass of application-level authorization by issuing direct SQL queries.
- Potential pivot to other systems via stored credentials or secrets in the database.
General mitigation guidance
Mitigation typically focuses on eliminating dynamic SQL that incorporates untrusted input and constraining what the code generation module can do.
Common defensive patterns include:
- Using parameterized queries or prepared statements for all database access, including metadata and code generation routines.
- Restricting inputs to well-defined, whitelist-validated identifiers (e.g., limiting table names to known schema entries or strict patterns).
- Separating code generation metadata from raw SQL construction, with a dedicated, vetted mapping layer between user input and database objects.
- Applying least-privilege to the database account used by the code generation module so that it cannot read or modify unrelated tables.
- Implementing centralized input validation for administrative forms, ensuring consistent filtering and canonicalization of all database-related parameters.
How teams detect issues like this
Effective detection often combines code-level and runtime observations:
- Static analysis rules that flag string-based SQL construction where request parameters or admin form fields are concatenated into queries.
- Code review checklists that treat dynamic SQL and code generation utilities as high-risk, requiring explicit justification for any non-parameterized queries.
- Application security testing (SAST/DAST) focused on admin-only endpoints, including the
/tool/gen/createTablepath, to identify injection sinks that may be missed in user-facing interfaces. - Database monitoring and alerting for anomalous queries originating from the application, such as unexpected schema enumeration or access to non-core tables.
Automated security testing tools can be integrated into CI/CD to enforce these checks for every change affecting data-access layers and code generation modules.

