Security: Patch RCE via Terminology Poisoning and Add Auth Guard#960
Security: Patch RCE via Terminology Poisoning and Add Auth Guard#960jackieya wants to merge 2 commits intodataease:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR hardens the platform against an RCE vector by blocking PostgreSQL COPY statements in the “read-only SQL” execution path and restricting bulk terminology uploads to workspace admins.
Changes:
- Block
sqlglot-parsedCOPYstatements by addingexp.Copyto the write-operation blacklist incheck_sql_read(). - Add an authorization guard (
@require_permissions) to the terminology Excel upload endpoint.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| backend/apps/terminology/api/terminology.py | Adds a permissions decorator to restrict /uploadExcel terminology imports. |
| backend/apps/db/db.py | Extends semantic SQL filtering to treat COPY as a disallowed write operation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| @require_permissions(permission=SqlbotPermission(role=['ws_admin'])) | ||
| @system_log(LogConfig(operation_type=OperationType.IMPORT, module=OperationModules.TERMINOLOGY)) |
There was a problem hiding this comment.
Decorator order means permission-denied requests won't be captured by @system_log. With the current order, require_permissions(...) runs before system_log(...), so if require_permissions raises (e.g., non-admin), the logging decorator never executes and the attempted import isn't audited. Consider swapping the decorators so @system_log(...) is above @require_permissions(...) (i.e., system_log(require_permissions(upload_excel))).
| @require_permissions(permission=SqlbotPermission(role=['ws_admin'])) | |
| @system_log(LogConfig(operation_type=OperationType.IMPORT, module=OperationModules.TERMINOLOGY)) | |
| @system_log(LogConfig(operation_type=OperationType.IMPORT, module=OperationModules.TERMINOLOGY)) | |
| @require_permissions(permission=SqlbotPermission(role=['ws_admin'])) |
Summary
Fixed a Stored Prompt Injection vulnerability in terminology management that leads to Remote Code Execution (RCE) and hardened the upload API's access control.
Problem
The terminology management module allowed any authenticated user to upload Excel files with unsanitized
descriptionfields. These descriptions were directly spliced into the LLM's system prompt during inference.An attacker could craft a terminology description that hijacks the LLM's reasoning logic, inducing it to output a PostgreSQL
COPY ... TO PROGRAMstatement. Since the core SQL execution path lacked semantic filtering for theCOPYcommand, this resulted in arbitrary command execution on the host server or database server.Fix
Implemented a two-layer defense mechanism to close this attack vector:
Semantic SQL Filtering (Architectural Guard):
Modified
backend/apps/db/db.pyto addexp.Copyto thewrite_typesblacklist within thecheck_sql_read()function. This leveragessqlglotto proactively intercept and blockCOPYcommands at the semantic level:API Authorization Hardening:
Applied the
@require_permissionsdecorator to theuploadExcelendpoint inbackend/apps/terminology/api/terminology.pyto ensure that only administrators can perform bulk terminology updates:Testing
COPY ... TO PROGRAMpayloads are now correctly identified and blocked, raising aValueErroras expected.upload_excelAPI rejects requests from non-admin users with appropriate authentication errors.Disclosure Notes
The detailed vulnerability report, PoC script, and exploitation demonstration have been submitted to the project maintainers via email for responsible disclosure.