/

CVE-2026-40285

Severity:

HIGH RISK

(8.8)

SQL Injection in WeGIA UsuarioDAO

CVE-2026-40285

Deferred

Vulnerability type

Category:

SQL Injection

CWE:

CWE-89, CWE-302, CWE-473

Impact:

Authenticated SQL Injection with Privilege Impersonation

Severity:

HIGH RISK

(8.8)

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

WeGIA versions prior to 3.6.10 contain a SQL injection vulnerability in dao/memorando/UsuarioDAO.php, where an attacker-controlled POST parameter is used to overwrite the session user identity and is then interpolated directly into a SQL query.

Under these conditions, any authenticated user can execute database queries as an arbitrary identity, potentially exposing or manipulating data across tenant or user boundaries.

Affected context

This vulnerability occurs in WeGIA deployments where:

  • The affected versions prior to 3.6.10 are in use
  • The DespachoControle::verificarDespacho() flow is reachable to authenticated users
  • Request data (including cpf_usuario) is used to overwrite server-side state via extract($_REQUEST)
  • UsuarioDAO.php builds SQL statements by concatenating the resulting identity value into raw SQL

In such environments, authenticated users can influence both the effective identity and the SQL executed on the underlying database.

Exploit preconditions

  • Attack surface: HTTP endpoints that invoke DespachoControle::verificarDespacho() and eventually UsuarioDAO.php.
  • Required access: Valid authenticated user account with permission to reach the impacted controller/action.
  • Trigger point: Submission of a crafted POST request where cpf_usuario (and related parameters) are set to attacker-chosen values.
  • Why exploitation is possible:
  • The application uses extract($_REQUEST) to populate scope variables from user input, overwriting the session-backed identity.
  • The overwritten identity is then interpolated into SQL without parameterization or proper escaping.
  • As a result, attacker-controlled data becomes part of the SQL syntax, enabling injection and impersonation.

Why this happens

The core issue is the unsafe combination of:

  • Blindly importing request variables into the local scope using extract($_REQUEST), which allows user input to overwrite trusted state such as the session user identity (related to CWE-473: Incorrect Initialization of Variables and CWE-302: Authentication Bypass by Assumed-Immutable Data).
  • Constructing SQL statements via string concatenation rather than using prepared statements or bound parameters (CWE-89: SQL Injection).

Together, these patterns break the trust boundary between authenticated session state and incoming request data, allowing an attacker to redefine who they are in the application and inject that value into raw SQL queries. This is a classic case of untrusted input flowing directly into a database command without contextual encoding or parameterization.

Potential impact

  • Impersonation of arbitrary users or roles at the application level through manipulated identity values.
  • Unauthorized reading of sensitive records that should be restricted to specific users or profiles.
  • Unauthorized modification or deletion of data associated with other users or entities.
  • Escalation of privileges if higher-privileged identities can be impersonated via injected identifiers.
  • Potential pivot to broader database compromise depending on query context and database configuration.

General mitigation guidance

Effective mitigation focuses on separating trust boundaries and enforcing safe query construction patterns:

  • Eliminate variable extraction from request scope:
  • Avoid using APIs like extract($_REQUEST) that implicitly overwrite internal variables from user input.
  • Explicitly map and validate each input field to dedicated local variables with clear naming and scope.
  • Protect session-derived identity:
  • Treat session user identifiers as immutable for the duration of a request and never refresh them from request parameters.
  • Enforce a strict rule that any identity or authorization attribute must originate solely from authenticated session state or server-side storage.
  • Use parameterized queries and ORM features:
  • Replace manual SQL string concatenation with prepared statements or ORM query builders that separate query structure from data.
  • Ensure all dynamic values, including identifiers, are passed as bound parameters rather than interpolated into SQL.
  • Validate and constrain identifiers:
  • Apply strict validation to identifier fields (e.g., cpf_usuario), such as format checks, type constraints, and whitelist-based validation.
  • Reject or sanitize input that does not conform to expected patterns before it reaches the data access layer.
  • Apply least privilege in the database:
  • Use application-level database accounts with the minimum required privileges to limit impact if injection occurs.
  • Segregate roles so that compromised paths cannot easily access administrative tables or perform schema changes.

How teams detect issues like this

Detection typically combines code-level analysis with targeted review of risky patterns:

  • Static analysis for SQL injection patterns:
  • Configure SAST tools to flag dynamic SQL construction that concatenates $ variables directly into SQL strings.
  • Add custom rules to detect extract($_REQUEST), extract($_GET), and extract($_POST) usages, especially in controllers and authentication-related code paths.
  • Code review focus areas:
  • Examine controllers and DAOs for any use of request parameters to derive user identity or authorization context.
  • Look for places where session variables can be overwritten or are not clearly separated from request-derived data.
  • Verify that all database access uses parameterized queries / prepared statements and that no raw interpolation is performed.
  • Policy enforcement in CI/CD:
  • Introduce coding standards that ban dangerous functions (e.g., extract() on superglobals) and enforce them via linters or pre-commit hooks.
  • Require security-focused code review for changes that touch authentication, session handling, or data access layers.
  • Runtime monitoring (where applicable):
  • Monitor for anomalous query patterns, such as unexpected predicates or frequent switching of user identifiers within a single session.
  • Use database logging and WAF signatures tuned to detect common SQL injection indicators while avoiding false positives.

Sources

SourceLink
github.comgithub.com/LabRedesCefetRJ/WeGIA/security/advisories/GHSA-666r-v2m7-xgp9

Frequently asked

questions

Yes, but only through authenticated endpoints. Any user who can log in and reach the affected controller can send crafted HTTP requests to exploit the issue over the network.

No elevated privileges are strictly required beyond basic authentication. A standard authenticated account is sufficient, provided it can access the vulnerable functionality.

The most robust fix is to stop using extract($_REQUEST) (or similar variable-import patterns), keep session-based identity strictly server-side, and refactor all affected queries to use parameterized statements or ORM abstractions that prevent injection.

Adopt secure coding guidelines that prohibit trusting request data for identity or authorization, enforce parameterized queries for all database interactions, and integrate static analysis plus security-focused code review into the development lifecycle to catch dangerous patterns early.

Find out what's already
exploitable in your codebase.