Summary
NocoBase versions prior to 2.0.39 contain a SQL injection pathway where dangerous SQL keyword validation is skipped on the sqlCollection:update endpoint.
An attacker with collection management permissions can create a benign SQL collection, then update it with arbitrary SQL that bypasses validation and execute it through normal queries, potentially exfiltrating sensitive data or performing other unauthorized database operations.
Affected context
This vulnerability affects NocoBase deployments that expose SQL collections to users with collection management capabilities.
It specifically manifests when:
- SQL collections can be created and updated via the API or admin UI
- The
sqlCollection:updateendpoint is accessible to users who are not fully trusted with direct database access - Application logic relies on keyword-based checks (e.g.,
checkSQL()) to block dangerous SQL, rather than enforcing strict query construction patterns
In such environments, the missing validation on updates becomes a covert path for running arbitrary SQL through an otherwise controlled feature.
Exploit preconditions
- Attack surface: NocoBase API/UI endpoints handling SQL collections, particularly
sqlCollection:update. - Required access: Valid account with permissions to manage collections (create, update, and query SQL collections).
- Trigger point: Updating an existing SQL collection with malicious SQL after its initial creation passed validation and then invoking queries against that collection.
- Why exploitation is possible: The
checkSQL()validation that filters known dangerous SQL constructs is applied tocollections:createandsqlCollection:executebut omitted fromsqlCollection:update, allowing malicious SQL to be introduced post-creation and executed through normal collection operations.
Why this happens
The core issue is inconsistent validation of SQL inputs across related endpoints, mapping to CWE-89: Improper Neutralization of Special Elements used in an SQL Command (SQL Injection) and CWE-284: Improper Access Control.
NocoBase relies on a checkSQL() function to block dangerous keywords for SQL collections, but:
- The validation is correctly applied when a collection is created and when certain SQL executions occur.
- The same protective logic is not enforced when updating the SQL definition of an existing collection.
This creates an authorization and validation gap: users with collection management rights can inject arbitrary SQL during an update operation, bypassing the intended safeguards and effectively gaining direct SQL execution capabilities via the application's abstraction layer.
Potential impact
- Unauthorized reading of sensitive data from arbitrary tables the database user can access
- Modification or deletion of data, including business-critical records
- Escalation of impact by abusing database functions, stored procedures, or linked databases
- Circumvention of application-level access controls by querying data outside of allowed scopes
- Potential tampering with application configuration or audit logs stored in the database
General mitigation guidance
Effective mitigation focuses on eliminating ad hoc SQL injection channels and aligning authorization with data access capabilities:
- Ensure that all endpoints that accept SQL or SQL-like input share a common, centralized validation path so changes to validation cannot be bypassed on specific operations.
- Avoid relying solely on keyword-based blocking; consider secure query construction strategies such as parameterization or restricted, template-based query building where raw SQL is not directly editable.
- Restrict SQL collection management permissions to tightly controlled, trusted roles; treat them as equivalent to granting direct database access.
- Introduce schema-level or view-based access controls that constrain what the application's database role can read or modify, limiting blast radius if arbitrary SQL is injected.
- Apply defense-in-depth with least-privilege database accounts, minimizing the capabilities of the role used by NocoBase to execute SQL collections.
How teams detect issues like this
Detection can combine code-level and behavioral monitoring approaches:
- Use static analysis and code review checklists to verify that input validation and SQL filtering logic is consistently applied across all create, update, and execute endpoints for SQL collections.
- Search the codebase for direct SQL execution paths (e.g., raw query calls) and confirm that they pass through centralized validation or query builders, without special-case exceptions.
- Implement logging and monitoring for SQL collections that:
- Track changes to collection definitions, especially updates that significantly alter or expand SQL content.
- Flag the use of high-risk SQL functions, cross-database links, or broad data access patterns in collection definitions.
- Employ automated security testing or API fuzzing tools that attempt to introduce risky SQL constructs during both creation and update operations, verifying that responses and stored definitions are properly sanitized.

