Details
---
Impacted API Endpoint
POST /api/sqlCollection:execute
- Authentication: Required (
adminrole) - ACL Snippet registered in
plugin.ts:
this.app.acl.registerSnippet({
name: `pm.data-source-manager.collection-sql`,
actions: ['sqlCollection:*'], // includes :execute
});
- The
adminrole includes this snippet by default.
---
Recommended Fixes
Fix 1 (Immediate): Extend the blacklist with system catalog tables
const dangerKeywords = [
// ... existing entries ...
// ADD: PostgreSQL system catalog tables with sensitive data
'pg_shadow',
'pg_authid',
'pg_auth_members',
'pg_stat_activity',
'pg_roles',
// Note: information_schema should also be restricted for non-DBA roles
];
Fix 2 (Recommended): Replace blacklist with schema allowlist
Instead of blocking dangerous keywords, only allow queries against user-defined collection tables:
// Allowlist approach: extract table names from AST and verify against known collections
const allowedTables = await db.getCollectionNames(); // tables created by NocoBase users
const referencedTables = extractTableNames(parsedSQL);
if (!referencedTables.every(t => allowedTables.includes(t))) {
throw new Error('Query references tables outside the allowed scope');
}
Fix 3 (Defense-in-depth): Use a read-only, restricted DB user
The application's DB connection should use a PostgreSQL user that:
- Does not have
SELECTprivilege onpg_shadoworpg_authid - Only has access to the application's own schema (
nocobaseschema)
This ensures that even if the blacklist is bypassed, the DB user cannot access system catalogs.
---
Environment
| Field | Value |
|-------|-------|
| NocoBase version | 2.0.59-full |
| Database | PostgreSQL 16.14 |
| Deployment | Docker (nocobase/nocobase:2.0.59-full) |
| Vulnerable file | plugin-collection-sql/src/server/utils.ts — checkSQL() |
| Vulnerable endpoint | POST /api/sqlCollection:execute |
| Auth required | Admin role (pm.data-source-manager.collection-sql snippet) |
---
Timeline
| Date | Event |
|------|-------|
| 2026-05-29 | Vulnerability discovered via whitebox source code audit of utils.ts |
| 2026-05-29 | Exploit verified on live Docker instance — pg_shadow and users.password dumped |
| 2026-05-29 | Report submitted to maintainers |
---
Script and video PoC:
poc_vul2_sqli.py
https://github.com/user-attachments/assets/6e4e7a3d-e005-4ff8-ab9a-e44ae1365732