Summary
Ory Keto's GetRelationships API is vulnerable to SQL injection when pagination tokens can be forged using a known or default encryption secret.
If an attacker can submit arbitrary pagination tokens and knows (or benefits from) the default secrets.pagination key, they may be able to execute crafted SQL queries against the backing database.
Affected context
This vulnerability affects Ory Keto deployments where:
- The GetRelationships API is reachable, either directly or through another exposed service.
- Pagination is used and the API accepts raw pagination tokens from the client.
- The
secrets.paginationconfiguration value is left unset (causing use of a publicly documented default) or is otherwise known to the attacker.
In such environments, pagination tokens effectively become a controllable input into the SQL query builder, allowing crafted tokens to alter database queries.
Exploit preconditions
- Attack surface: Network-exposed GetRelationships API endpoint, directly or via proxy/gateway.
- Required access: Ability to send requests containing custom pagination tokens to the vulnerable API route.
- Configuration state:
secrets.paginationis not configured (default secret is in use) or has been disclosed/guessed by the attacker. - Trigger point: Server-side pagination handling that decrypts the token and uses its contents to build SQL queries without adequate sanitization or parameterization.
- Why exploitation is possible: The pagination token, once decrypted with a known key, is treated as trusted query metadata and interpolated into SQL logic, leading to CWE-89 SQL injection.
Why this happens
The underlying issue is a combination of insecure default cryptographic configuration and unsafe handling of data derived from pagination tokens.
Pagination state is encrypted using a secret that, when left at its hard-coded default or otherwise exposed, allows attackers to forge arbitrary token contents.
These token contents are then used in SQL query construction in a way that does not consistently enforce parameterization or strict validation of allowable values.
This aligns with CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection'), where attacker-controlled data influences SQL statements.
Potential impact
- Execution of crafted SQL queries against the authorization data store.
- Unauthorized reading of relationship or permission data beyond intended scopes.
- Manipulation or deletion of relationship records, potentially altering access control decisions.
- Indirect escalation of privileges in applications that rely on Keto's authorization data.
- Denial of service due to expensive or destructive queries.
General mitigation guidance
Effective mitigation focuses on both strengthening the trust boundary around pagination tokens and hardening query construction:
- Configure a unique, cryptographically strong
secrets.paginationvalue for each environment, generated from a secure random source. - Treat all data derived from pagination tokens as untrusted and restrict it to a narrowly defined schema (e.g., numeric offsets, fixed sort keys).
- Ensure all database interactions use parameterized queries or query builders that separate data from SQL structure.
- Implement input normalization and allowlists for pagination parameters (such as permitted columns or directions), rather than filtering out bad characters.
- Isolate the database user used by Keto with least-privilege permissions tailored to the expected read/write operations.
- Apply secure-by-default configuration baselines that fail closed when secrets are missing, avoiding fallback to public or static keys.
How teams detect issues like this
Organizations can detect and monitor for this class of vulnerability using:
- Static analysis rules that flag construction of SQL statements from decrypted or decoded user inputs, including pagination or cursor tokens.
- Security-focused code review checklists that highlight:
- Use of default secrets or hard-coded keys.
- Any string concatenation or dynamic SQL logic that incorporates pagination-related fields.
- Configuration auditing to detect deployments where
secrets.paginationis unset, identical across environments, or too short/weak. - Runtime monitoring of database logs for anomalous queries originating from Keto, such as unusual WHERE clauses, UNION/OR patterns, or unexpected query shapes.
- Automated CI/CD checks (e.g., policy as code) that prevent deploying with default or missing secrets and enforce parameterized query patterns.

