Summary
EverShop's category update and deletion handlers build SQL statements by concatenating path values derived from the url_key field, which originates from database data.
If an attacker succeeds in storing a malicious string in url_key, later event processing will embed that value into raw SQL and execute it, resulting in a second-order SQL injection even when the immediate HTTP request appears safe.
Affected context
This vulnerability appears in EverShop's category management workflow, specifically in the logic that reacts to category update and deletion events.
The problem occurs when values derived from the url_key column (e.g., path or request_path) are taken from the database and interpolated directly into SQL strings.
Deployments that allow user-controlled or partially trusted data to populate url_key—either via admin interfaces, import pipelines, custom integrations, or plugin modules—are at particular risk, since that data can later be reused unsafely inside dynamic SQL statements.
Exploit preconditions
- Attack surface: Application workflows that create or modify category
url_keyvalues, and subsequent category update / delete events. - Required access: Ability to influence data that ends up in the
url_keyfield (e.g., compromised admin account, malicious integration, or any feature that lets untrusted input populate category identifiers). - Trigger point: Execution of category update or deletion handlers that read the stored
url_key, derivepath/request_path, and construct SQL queries via string concatenation before callingexecute(). - Why exploitation is possible: The code treats database-resident values as inherently safe and interpolates them directly into SQL, bypassing parameterization and proper escaping. Because the malicious payload is stored and only executed later, usual request-time filters or WAF rules may not detect the exploit.
Why this happens
The underlying bug is the use of dynamic SQL construction with string concatenation, where values derived from url_key are inserted directly into SQL text.
This maps to CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection').
In this case, the injection is second-order: the attacker first stores crafted SQL meta-characters and fragments into the database; later, when event handlers construct new SQL statements using those stored values, the database interprets them as part of the command rather than as data.
The insecure pattern is assuming that data retrieved from internal storage is trusted and can be safely embedded into SQL without parameterization or validation.
Potential impact
- Execution of attacker-controlled SQL against the application database
- Reading or exfiltrating sensitive customer, order, or product data
- Modifying or deleting catalog entries, orders, or user accounts
- Creating backdoor administrative accounts or altering permissions
- Tampering with transactional data, leading to financial fraud or inventory corruption
- Potential pivoting to underlying infrastructure if the database has extended capabilities (e.g., file system access, command execution)
General mitigation guidance
Effective mitigation focuses on treating all data—whether from HTTP requests or from the database—as untrusted when building SQL.
Recommended defensive patterns include:
- Using parameterized queries or query builders/ORM methods that clearly separate SQL structure from data, including for values that originate from the database itself.
- Centralizing data access logic so that ad hoc string-concatenated SQL is discouraged or forbidden in application code and extensions.
- Applying strict validation and normalization on fields like
url_key, ensuring they follow a constrained format (e.g., slug / path-safe characters only) before storing them. - Implementing a clear distinction between identifiers and data, using whitelisting or mapping when identifiers must influence query structure.
- Running the database with least-privilege accounts, limiting the damage that injected queries can cause, such as preventing schema changes or cross-database access.
These patterns help ensure that even if a field is compromised at one point in time, it cannot later be reinterpreted as executable SQL.
How teams detect issues like this
Identifying this class of issue typically involves combining code-level and behavioral analysis:
- Static analysis: Configure SAST or linters to flag any usage of raw SQL string concatenation, especially where parts of the query are derived from variables, including values read from the database or request-dependent fields.
- Code review: Pay attention to event handlers, hooks, and background jobs that read stored fields like
url_keyand then build SQL statements. Look for patterns where those fields controlWHEREclauses, paths, or other query fragments. - Testing: Develop security tests that:
- Store crafted values in
url_keythrough legitimate workflows or test harnesses. - Trigger category update and delete operations to verify whether the stored values can alter the resulting SQL behavior.
- Runtime monitoring: Enable database query logging or use a database firewall to detect anomalous patterns, such as unexpected concatenation of path-like values with SQL keywords or repeated query structure changes tied to specific records.
Automated code review and policy checks in CI/CD can enforce safer data access patterns before code reaches production.

