Summary
WeKnora's Agent service exposes a database query tool that relies on LLM-driven controls to constrain what queries can be executed, but the backend performs insufficient validation of the generated SQL.
By using prompt-based bypass techniques, an attacker can evade these soft restrictions and cause the system to run unintended queries against the target server and database, potentially disclosing sensitive information.
Affected context
The vulnerability occurs when WeKnora is deployed with the Agent service enabled and the database query tool exposed to users or semi-trusted callers. In this mode, WeKnora delegates query shaping and restriction largely to an LLM prompt layer, but the backend does not robustly enforce or validate which SQL statements are ultimately executed. Environments where the Agent can reach production or sensitive databases, and where users can influence natural-language instructions or tool invocations, are particularly exposed.
Exploit preconditions
- Attack surface: The WeKnora Agent service's database query tool, typically accessed via API endpoints, web frontends, or integrated chat-style interfaces.
- Required access: Ability to interact with the Agent service and issue natural-language instructions or tool calls (e.g., any authenticated or exposed user role that can invoke the database query tool).
- Trigger point: Submitting crafted prompts or instructions that steer the LLM into generating queries beyond intended policy constraints.
- Why exploitation is possible: The backend trusts the LLM's adherence to query restrictions and does not perform strong, server-side validation or enforcement of allowed SQL patterns, allowing prompt-based bypasses of policy to be executed directly against the database.
Why this happens
The core issue is a reliance on an LLM and prompt-level policies to constrain database access, without strong, backend-side validation of the final SQL that is executed. This maps to CWE-89: Improper Neutralization of Special Elements used in an SQL Command (SQL Injection), generalized here to improper control over dynamically generated SQL.
Instead of enforcing a strict, programmatic allowlist or query-building abstraction, the system permits natural-language instructions to flow through the LLM into relatively unconstrained SQL. Because the backend does not robustly parse, normalize, and enforce allowed query shapes, attackers can craft prompts that cause the model to generate sensitive or broader queries than intended, effectively bypassing logical query restrictions and exposing data.
Potential impact
- Unauthorized reading of sensitive tables, records, or metadata from the target database
- Exposure of user data, configuration details, or operational secrets stored in the database
- Enumeration of database schema and structure that could aid further attacks
- Potential pivoting to other application components that rely on the compromised database
- Increased risk of privacy violations and regulatory non-compliance due to data leakage
General mitigation guidance
Effective mitigation focuses on enforcing strong, backend-side control over database access rather than relying on LLM behavior alone:
- Introduce a strict server-side authorization and policy layer for database operations, independent of prompts or LLM outputs.
- Use parameterized queries and vetted query builders that limit which tables, columns, and operations are allowed.
- Implement allowlist-based query templates or stored procedures, and restrict the Agent to selecting among these rather than generating free-form SQL.
- Apply role-based database permissions so the Agent operates with least-privilege, limiting accessible data even if prompts are bypassed.
- Add robust validation, parsing, and normalization of any SQL produced by the LLM, rejecting queries that exceed predefined safe patterns or access scopes.
- Reduce the scope of accessible databases or views to pre-filtered, denormalized datasets intended for analytical or read-only use.
How teams detect issues like this
Detection generally centers on identifying anomalous or overly broad database activity caused by the Agent and spotting weak controls at the code level:
- Static analysis and code review
- Look for code paths where LLM outputs are used directly to construct or execute SQL without strict validation or parameterization.
- Flag dynamic SQL execution APIs that ingest unconstrained strings from the Agent's tool layer.
- Review policy and middleware layers to ensure they enforce, rather than merely suggest, allowed query shapes.
- Runtime and logging analysis
- Enable detailed database query logging for connections used by the Agent, and alert on:
- Access to sensitive tables or columns outside expected patterns.
- Use of high-risk SQL operations (e.g., broad SELECTs, joins across restricted domains).
- Monitor for unusual query volume or schema enumeration activity originating from the Agent's database credentials.
- Security policy enforcement
- Use automated checks in CI/CD to require that any new Agent tools interfacing with databases pass strict validation and authorization tests.
- Periodically exercise the Agent with test prompts designed to probe policy boundaries, and flag any successful bypasses for remediation.

