/

CVE-2026-33503

Severity:

HIGH RISK

(7.2)

SQL Injection in Ory Kratos Admin Courier Messages API

CVE-2026-33503

Analyzed

Vulnerability type

Category:

SQL Injection

CWE:

CWE-89

Impact:

Data Exposure and Database Manipulation via SQL Injection

Severity:

HIGH RISK

(7.2)

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

A SQL injection vulnerability in the ListCourierMessages Admin API of Ory Kratos allows attackers to inject arbitrary SQL through crafted pagination tokens.

When the pagination secret is known or left at its default value, an attacker can forge valid tokens that manipulate database queries, potentially exposing or altering sensitive data.

Affected context

This vulnerability affects Ory Kratos deployments that expose the ListCourierMessages Admin API and rely on encrypted pagination tokens for listing courier messages.

Risk is highest when:

  • The secrets.pagination configuration is unset, causing use of a publicly known default secret, or
  • The configured secret has been leaked, guessed, or is shared across environments.

In such cases, an attacker able to call the Admin API and craft their own pagination tokens can influence the SQL used to retrieve paginated results.

Exploit preconditions

  • Attack surface: Ory Kratos Admin API endpoint for listing courier messages (ListCourierMessages).
  • Required access: Ability to reach and interact with the Admin API; practical exploitation may depend on how strictly access to the admin interface is controlled.
  • Knowledge requirements:
  • The value of secrets.pagination, or
  • Reliance on the default pagination secret (which is publicly known).
  • Trigger point: Submission of a crafted pagination token that is accepted as valid and used in SQL query construction for paginated results.
  • Why exploitation is possible: The pagination implementation embeds pagination state in an encrypted token and later incorporates decoded values into SQL queries without robust sanitization or parameterization. When the encryption key is predictable or known, attackers can generate arbitrary tokens that control those values and inject SQL.

Why this happens

The underlying issue maps to CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection').

The pagination feature uses an encrypted token to transport state (such as cursors or offsets) between requests. During query construction, values recovered from this token are incorporated into SQL clauses in a way that does not fully separate data from command structure (for example, constructing SQL fragments from token-derived values instead of binding them as parameters).

As long as the encryption key is secret and unpredictable, attackers cannot easily forge arbitrary states. However, when secrets.pagination is left at a publicly known default, or otherwise exposed, adversaries can generate their own tokens that embed SQL meta-characters and query fragments. This turns the lack of proper neutralization and strict parameterization into an exploitable SQL injection condition.

Potential impact

  • Retrieval of courier message records beyond what would normally be visible to the caller.
  • Exposure of sensitive metadata related to user communications or verification flows.
  • Modification or deletion of records in the backing database, depending on database permissions.
  • Escalation to broader data compromise if the database user used by Kratos has extensive privileges.
  • Potential pivoting into other schema areas if the injection point is flexible enough and the DB account is over-privileged.

General mitigation guidance

Long-term mitigation focuses on both secure query construction and robust secret management:

  • Ensure that any values derived from pagination tokens are incorporated into database queries exclusively through parameterized statements and strongly typed query APIs, not via string concatenation or dynamic SQL assembly.
  • Treat pagination state as untrusted input even when encrypted, applying the same validation and normalization as for other client-supplied data.
  • Use strong, unique, cryptographically secure random values for secrets.pagination, and avoid shipping or deploying with any default or shared secret value.
  • Enforce least privilege on the database account used by Ory Kratos so that, even if query behavior is influenced, the scope of possible damage is reduced.
  • Regularly rotate sensitive configuration secrets such as pagination keys, especially after suspected leaks or environment cloning.

How teams detect issues like this

Effective detection approaches typically combine code, configuration, and runtime monitoring:

  • Static analysis and code review:
  • Flag any query-building code that uses values from pagination tokens or other opaque client-controlled blobs without strict parameterization.
  • Look for dynamic SQL fragments (e.g., ORDER BY, WHERE clauses) constructed with string concatenation or templating.
  • Configuration review:
  • Automatically scan Ory Kratos deployments for unset or default secrets.pagination values as part of security posture checks.
  • Incorporate policy-as-code rules that fail CI/CD pipelines when default secrets are used.
  • Runtime monitoring:
  • Enable database logging (e.g., slow query logs or full audit logs) and alert on anomalous SQL patterns, such as unexpected operators, concatenations, or multi-statement queries originating from the ListCourierMessages code path.
  • Use web application firewalls or API gateways with SQL injection detection rules to inspect pagination token usage, while being mindful of encryption and privacy considerations.
  • Automated tooling:
  • Employ SAST/DAST tools configured with rules for SQL injection and misconfigured secrets, ensuring that they understand common pagination and cursor patterns.

Sources

SourceLink
github.comgithub.com/ory/kratos/security/advisories/GHSA-hgx2-28f8-6g2r

Frequently asked

questions

Yes, it can be remotely exploitable against any deployment where an attacker can reach the Ory Kratos Admin API endpoint for listing courier messages and where the pagination secret is known or left at the default.

The attacker needs network access to the Admin API and effective knowledge of the pagination encryption secret. If secrets.pagination is not set and the default secret is used, that knowledge requirement is essentially removed because the default is publicly known.

The safest pattern combines two measures: treat pagination data as untrusted input and ensure strict use of parameterized SQL (or ORM query builders that avoid raw SQL), and configure a unique, cryptographically strong value for secrets.pagination so pagination tokens cannot be forged even if the token format is understood.

Adopt a design rule that encrypted or signed tokens do not justify relaxing input validation or query safety: any data derived from clients must be validated and bound as parameters, not embedded into SQL. Complement this with a secret-management strategy that forbids default secrets, enforces secret uniqueness and rotation, and integrates configuration checks into CI/CD and deployment pipelines.

Find out what's already
exploitable in your codebase.