/

CVE-2026-22687

Severity:

HIGH RISK

(8.1)

SQL Injection in WeKnora Agent Database Query Tool

CVE-2026-22687

Analyzed

Vulnerability type

Category:

SQL Injection

CWE:

CWE-89

Impact:

Unauthorized Data Access via SQL Injection

Severity:

HIGH RISK

(8.1)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

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.

Sources

SourceLink
github.comgithub.com/Tencent/WeKnora/commit/da55707022c252dd2c20f8e18145b2d899ee06a1
github.comgithub.com/Tencent/WeKnora/security/advisories/GHSA-pcwc-3fw3-8cqv

Frequently asked

questions

Yes, if the WeKnora Agent service is exposed over a network (e.g., via web UI, API, or chat interface) and a remote user can interact with the database query tool. Exploitation does not require local access to the server, only the ability to send crafted instructions to the Agent.

The attacker must have whatever level of access is required to interact with the Agent's database query capability. In many deployments this may be any authenticated user, or even anonymous users if the Agent is exposed without strict authentication. The vulnerability concerns how that permitted access can be escalated to broader data retrieval.

The most robust fix is to decouple data access control from the LLM by enforcing strict, backend-side authorization and query validation. This usually means constraining the Agent to parameterized, allowlisted queries or stored procedures, validating any generated SQL against a defined policy, and ensuring the database credentials used by the Agent have least-privilege access.

Treat LLMs as untrusted code generators: never rely solely on prompts or model behavior for security boundaries. Instead, implement hard controls such as allowlisted tools, strict schema-aware validation, role-based permissions, and safe abstractions that the LLM cannot bypass. Regularly test for prompt injection and policy bypass, and integrate security review into design and code review for any new LLM tool integrations.

Find out what's already
exploitable in your codebase.