/

CVE-2026-33504

Severity:

HIGH RISK

(7.2)

SQL Injection in Ory Hydra Admin APIs

CVE-2026-33504

Analyzed

Vulnerability type

Category:

SQL Injection

CWE:

CWE-89

Impact:

Arbitrary SQL Query Execution

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 Ory Hydra's admin APIs (listOAuth2Clients, listOAuth2ConsentSessions, and listTrustedOAuth2JwtGrantIssuers) allows attackers who know the pagination secret to forge pagination tokens that inject arbitrary SQL into backend queries.

When these admin endpoints are exposed directly or indirectly, and the pagination or system secret is known, crafted tokens can be used to manipulate database queries and potentially compromise stored OAuth2 and OpenID Connect data.

Affected context

This vulnerability affects deployments of Ory Hydra where:

  • The admin APIs listOAuth2Clients, listOAuth2ConsentSessions, or listTrustedOAuth2JwtGrantIssuers are reachable (directly or via intermediary services), and
  • Pagination tokens are accepted and processed for listing results, and
  • The encryption key for these tokens (secrets.pagination, or secrets.system as a fallback) is either predictable, reused across environments, shared with other components, or otherwise known to an attacker.

In such configurations, forged pagination tokens become an input channel into the SQL layer backing these admin list operations.

Exploit preconditions

  • Attack surface: Ory Hydra admin APIs:
  • GET /admin/clients
  • GET /admin/oauth2/auth/sessions/consent
  • GET /admin/trust/grants/jwt
  • Required access:
  • Network access to a service that can call these admin endpoints (e.g., direct admin API exposure, admin panel, proxy, or internal service delegating pagination tokens).
  • Knowledge of the encryption secret used for pagination tokens (secrets.pagination, or secrets.system when pagination secret is unset).
  • Trigger point:
  • Submission of a crafted pagination token as a request parameter to one of the affected admin APIs.
  • Why exploitation is possible:
  • The pagination implementation embeds unvalidated token contents into SQL queries in a manner that allows attacker-controlled data to influence query structure.
  • The design assumes that possession of the encryption secret implies trustworthiness, but when the secret is known or leaked, pagination tokens become a manipulable channel for SQL injection.

Why this happens

The core issue is the combination of:

  • Treating encrypted pagination tokens as trusted internal data due to their cryptographic protection, and
  • Building SQL statements in a way that lets token-derived values affect the query structure rather than being strictly bound as typed parameters.

Once an attacker knows the token encryption secret, they can generate syntactically correct tokens whose decrypted content includes malicious SQL fragments. Because the application's pagination logic does not strictly separate query structure from data, these fragments are incorporated into the executed SQL. This maps to CWE-89: SQL Injection, where untrusted data is incorporated into SQL commands without proper neutralization or strict parameterization, even though the data is wrapped in a cryptographic layer.

Potential impact

  • Reading, modifying, or deleting OAuth2 client metadata stored in the database
  • Tampering with consent session records, potentially altering or invalidating existing user consents
  • Manipulating trusted JWT grant issuers, impacting token validation and trust relationships
  • Escalating further into the backing database, including pivoting to other tables depending on schema and permissions
  • Denial of service against Hydra by issuing expensive or malformed SQL queries

General mitigation guidance

Effective mitigation focuses on both query construction safety and secret handling:

  • Enforce strict parameterization: Ensure that all pagination-related values, including offsets, cursors, and sort keys, are bound as parameters rather than concatenated into SQL strings. Avoid dynamic query fragments derived from token content wherever possible.
  • Constrain pagination data: Represent pagination state using simple, strongly-typed primitives (e.g., numeric offsets, UUIDs, or opaque cursor IDs) that map directly to columns, and validate them against a strict schema before use.
  • Treat encrypted tokens as untrusted: Even if data is encrypted or signed, handle it as potentially attacker-controlled unless derived entirely within a trusted boundary. Re-validate and sanitize token contents after decryption.
  • Harden secret management:
  • Use cryptographically strong, random values for secrets.pagination that are unique per environment.
  • Avoid reusing secrets.system as a general-purpose secret; restrict its scope and rotate secrets on suspicion of exposure.
  • Limit who and what components can access these secrets, following least privilege.
  • Limit admin API exposure: Place admin endpoints behind strong authentication, authorization, and network controls (e.g., dedicated admin networks, service-to-service auth) so that only trusted operators or services can call them.

How teams detect issues like this

Organizations can approach detection on several layers:

  • Static analysis and code review:
  • Flag locations where SQL queries are built from concatenated strings or where decrypted token contents influence query fragments.
  • Look for pagination logic that decodes or decrypts tokens and then injects their fields directly into ORDER BY, WHERE, or LIMIT/OFFSET clauses.
  • Verify that all database access patterns, especially in admin handlers, use prepared statements or query builders with strict parameter binding.
  • Configuration and policy checks:
  • Automatically scan Hydra configuration for weak, default, or reused secrets, especially secrets.pagination and secrets.system.
  • Enforce internal policies requiring unique, random secrets per environment and disallowing shared secrets across multiple services.
  • Runtime monitoring:
  • Monitor database logs for anomalous or unusually complex queries originating from admin list endpoints, particularly those containing unexpected SQL keywords or patterns in pagination-related parameters.
  • Implement application-level logging around pagination token parsing and validation to detect malformed or suspicious tokens.
  • Automated tooling:
  • Integrate security scanners or linters into CI pipelines to enforce safe query construction practices.
  • Use API gateways or WAFs with rules to detect and block obviously malicious SQL patterns in parameters, while recognizing that encrypted tokens may limit their visibility.

Sources

SourceLink
github.comgithub.com/ory/hydra/security/advisories/GHSA-r9w3-57w2-gch2

Frequently asked

questions

It can be, but only if the affected admin APIs are reachable (directly or indirectly) from the attacker's network location and the attacker also knows the pagination or system secret. In many deployments, admin APIs are intended to be internal-only, which reduces but does not eliminate the risk if network boundaries are weak or misconfigured.

The attacker must be able to send requests that carry pagination tokens to one of the vulnerable admin endpoints, and they must know the secret used to encrypt or sign those tokens (secrets.pagination or secrets.system). Without both conditions, crafting effective malicious tokens is significantly harder.

The most robust fix is to ensure that decrypted or parsed token contents are never allowed to change SQL query structure. All database access should use parameterized queries or ORM-style builders where token-derived values are treated purely as data and validated against a strict schema before use, combined with strong, compartmentalized secrets.

Design pagination and cursor mechanisms so that they encode only minimal, typed identifiers (such as IDs or offsets) and treat all token data as untrusted input, even when encrypted. Combine this with secure secret management practices, strict access control for admin APIs, and development standards that forbid dynamic SQL construction based on user-controllable values.

Find out what's already
exploitable in your codebase.