/

CVE-2026-27953

Severity:

HIGH RISK

(7.1)

Input Validation Bypass in ormar FastAPI Models

CVE-2026-27953

Analyzed

Vulnerability type

Category:

Input Validation Bypass

CWE:

CWE-20, CWE-915

Impact:

Authorization and Data Integrity Compromise

Severity:

HIGH RISK

(7.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

ormar versions 0.23.0 and below allow clients to bypass Pydantic-based field validation by injecting special internal control flags ("__pk_only__": true and __excluded__) into JSON request bodies.

When ormar models are used directly as FastAPI request body parameters, an unauthenticated attacker can persist unvalidated data to the database and selectively nullify sensitive fields, undermining authorization and business logic checks.

Affected context

This vulnerability appears in Python applications that:

  • Use ormar ≤ 0.23.0 as an async ORM
  • Follow the canonical FastAPI integration pattern from ormar's documentation
  • Bind ormar.Model subclasses directly as FastAPI request body models (e.g., async def create(item: MyModel):)
  • Rely on Pydantic/ormar field validation and model constraints to enforce correctness and security

In these contexts, internal control fields intended for ORM-internal behavior are exposed to the external JSON API surface and treated as trusted input during model construction.

Exploit preconditions

  • Attack surface: HTTP/JSON API endpoints that:
  • Accept ormar model instances directly as request bodies
  • Persist ormar models to the database based on the incoming payload
  • Required access:
  • Network access to the API (no authentication is required if the endpoint itself is publicly accessible)
  • Trigger point:
  • Submission of crafted JSON payloads containing:
  • "__pk_only__": true to bypass full validation
  • __excluded__ (typically as a list or structure) to exclude or nullify fields during model construction
  • Why exploitation is possible:
  • ormar exposes internal constructor flags through the same mechanism used to deserialize user-controlled JSON
  • Pydantic/ormar treat these flags as configuration rather than untrusted data, causing normal field validation and required-field checks to be bypassed or selectively disabled
  • Application code often assumes that any constructed model instance is fully validated, and thus may not perform additional checks before persisting to the database or making authorization decisions

Why this happens

The core issue aligns with CWE-20: Improper Input Validation and CWE-915: Improperly Controlled Modification of Dynamically-Determined Object Attributes.

ormar's model constructor accepts special internal parameters such as __pk_only__ and __excluded__ that influence how fields are processed and validated. When ormar models are used directly as request body schemas, these internal fields become user-controllable via JSON, without being filtered, namespaced, or protected. As a result:

  • "__pk_only__": true can instruct the constructor to treat the payload as a primary-key-only instance, skipping full field validation.
  • __excluded__ allows callers to mark arbitrary fields as excluded, effectively nullifying or preventing those fields from being processed or enforced.

This reflects an insecure pattern where framework-internal control knobs share the same namespace as user input and are not treated as untrusted data. The model construction pipeline assumes that these flags are supplied by trusted code paths, not by external clients, creating a validation and business-logic gap at the ORM boundary.

Potential impact

  • Bypass of all field-level validation and constraints for affected models
  • Persistence of malformed, incomplete, or policy-violating data directly to the database
  • Nullification or forced omission of security-relevant fields (e.g., email, role, is_admin, is_active)
  • Privilege escalation by manipulating or clearing authorization-related attributes on user or session records
  • Circumvention of business rules that depend on validated state (e.g., required consents, status flags, or quotas)
  • Data integrity corruption that can cascade into reporting errors, billing issues, or misrouted workflows

General mitigation guidance

Effective mitigation centers on isolating internal control metadata from untrusted client input and tightening validation boundaries:

  • Decouple transport and persistence models:
  • Use dedicated Pydantic schemas or DTOs for request bodies, separate from ormar Model classes.
  • Map validated input objects to ormar models in application code, rather than constructing ormar models directly from user JSON.
  • Filter or block internal control fields:
  • Ensure that request parsing layers discard or reject any fields that start with special prefixes (e.g., __), or that are known internal parameters.
  • Enforce strict schema definitions for input models, so unexpected fields cause validation failures instead of being silently accepted.
  • Treat model construction as a trust boundary:
  • Do not assume ORM or framework constructors will safely sanitize or ignore dangerous parameters.
  • Perform explicit validation of critical fields (identity, role, status, ownership) even after model creation, especially before persistence or authorization decisions.
  • Reduce privilege of API endpoints:
  • Limit which roles or authentication states can call endpoints that create or modify high-impact models (e.g., user accounts, permissions, financial records).
  • Avoid endpoints that allow arbitrary updates to sensitive fields; prefer explicit, narrowly scoped update operations.
  • Adopt secure-by-default patterns:
  • Favor conservative constructor interfaces that do not expose internal flags to external callers.
  • Establish coding guidelines that prohibit using persistence models directly as external request schemas in web APIs.

How teams detect issues like this

Organizations can identify this and similar issues by combining static analysis, code review patterns, and policy checks:

  • Static analysis and pattern scanning:
  • Flag FastAPI endpoints where:
  • Parameters are typed directly as ormar.Model subclasses for Body inputs.
  • Request models share the same type as database models in route signatures.
  • Search for references to internal parameters like __pk_only__ and __excluded__ in application code paths that process user input.
  • Code review signals:
  • Examine any controller or router where:
  • Incoming request data is passed directly to ormar (or other ORM) constructors without an intermediate validation schema.
  • Validation is assumed to be "handled by the ORM" instead of explicit Pydantic schemas or service-level checks.
  • Question API designs where hidden or underscored fields might be reachable from external clients.
  • Policy and CI enforcement:
  • Introduce architectural rules that:
  • Forbid the use of database entities as public API request/response models.
  • Require separate "input models" and "persistence models," enforced by code reviews and automated checks.
  • Integrate linters or SAST tools that understand FastAPI/ormar patterns and can flag dangerous model usage.
  • Runtime monitoring:
  • Instrument logging at the validation and persistence boundaries to capture unexpected fields in request payloads.
  • Monitor for anomalous changes to critical fields (e.g., roles or statuses changing outside expected workflows).

Sources

SourceLink
github.comgithub.com/ormar-orm/ormar/blob/master/examples/fastapi_quick_start.py#L55
github.comgithub.com/ormar-orm/ormar/blob/master/ormar/fields/foreign_key.py#L41
github.comgithub.com/ormar-orm/ormar/blob/master/ormar/models/helpers/pydantic.py#L108
github.comgithub.com/ormar-orm/ormar/blob/master/ormar/models/model.py#L89
github.comgithub.com/ormar-orm/ormar/blob/master/ormar/models/newbasemodel.py#L128
github.comgithub.com/ormar-orm/ormar/blob/master/ormar/models/newbasemodel.py#L292
github.comgithub.com/ormar-orm/ormar/commit/7f22aa21a7614b993970345b392dabb0ccde0ab3
github.comgithub.com/ormar-orm/ormar/releases/tag/0.23.1
github.comgithub.com/ormar-orm/ormar/security/advisories/GHSA-f964-whrq-44h8

Frequently asked

questions

Yes. If an application exposes HTTP endpoints that accept ormar models as JSON request bodies, a remote attacker who can send crafted requests to those endpoints can attempt to exploit the issue over the network.

Not necessarily. If affected endpoints are publicly accessible and do not enforce authentication, any unauthenticated user can send payloads including __pk_only__ or __excluded__. If access is restricted, the vulnerability is limited to authenticated users who can reach those routes.

The most robust pattern is to stop using ormar Model classes directly as API request schemas. Instead, define separate Pydantic request models, validate all incoming data against those, and then explicitly construct ormar models from validated fields. This design prevents internal ORM flags from being supplied by clients.

Treat ORM or persistence-layer types as internal implementation details and avoid exposing them at API boundaries. Use strict, explicit schemas for all external inputs, reject unknown or reserved fields, and ensure that any internal control knobs or magic parameters are kept out of user-controllable namespaces. Regular security reviews of framework integration patterns (especially examples copied from documentation) also help catch such issues early.

Find out what's already
exploitable in your codebase.