Ory Kratos SQL Injection Vulnerability in ListCourierMessages API
A SQL injection vulnerability exists in the ListCourierMessages Admin API of Ory Kratos versions prior to 26.2.0 due to flaws in its pagination implementation, allowing attackers to craft malicious tokens if the pagination secret is known or the default secret is used.
Ory Kratos, an identity, user management, and authentication system for cloud services, is vulnerable to SQL injection in versions prior to 26.2.0. The vulnerability resides within the ListCourierMessages Admin API and stems from flaws in its pagination implementation. The pagination tokens are encrypted using a secret configured in secrets.pagination. Attackers who obtain this secret can forge malicious tokens, leading to SQL injection attacks. Critically, if this configuration value remains unset, Kratos defaults to a publicly known pagination encryption secret. This allows attackers to manually generate valid malicious pagination tokens for vulnerable installations. Defenders should immediately configure a custom value for secrets.pagination using a cryptographically secure random secret and upgrade Kratos to version 26.2.0 or later.
Attack Chain
- Attacker identifies an Ory Kratos instance running a version prior to 26.2.0.
- Attacker checks the Kratos configuration to determine if
secrets.paginationis set. - If
secrets.paginationis not set, the attacker leverages the publicly known default pagination encryption secret. - The attacker crafts a malicious pagination token containing SQL injection payloads. This token exploits the vulnerable pagination logic in the
ListCourierMessagesAPI. - Attacker sends a request to the
/admin/courier/messagesendpoint with the crafted pagination token in thepage_tokenparameter. - The Kratos application processes the malicious token, leading to the execution of arbitrary SQL queries against the underlying database.
- The SQL injection allows the attacker to potentially read, modify, or delete sensitive data within the Kratos database, including user credentials, configuration settings, or other confidential information.
- The attacker may use the compromised data for further attacks, such as account takeover or privilege escalation.
Impact
Successful exploitation of this SQL injection vulnerability can lead to complete compromise of the Ory Kratos instance. This can result in unauthorized access to user accounts, disclosure of sensitive information, and potential data manipulation or deletion. The severity is high due to the potential for significant data breach and service disruption impacting all users managed by the compromised Kratos instance. The number of victims depends on the size and user base of the affected Ory Kratos deployment.
Recommendation
- Immediately configure a custom value for
secrets.paginationby generating a cryptographically secure random secret within your Ory Kratos configuration (reference: Overview section). - Upgrade Ory Kratos to version 26.2.0 or later to patch the SQL injection vulnerability (reference: Overview section).
- Monitor web server logs for suspicious requests to the
/admin/courier/messagesendpoint containing unusually long or malformedpage_tokenparameters (create a custom rule based on this behavior). - Implement a Web Application Firewall (WAF) rule to block requests with suspicious SQL syntax in the
page_tokenparameter targeting the/admin/courier/messagesendpoint.
Detection coverage 2
Ory Kratos Suspicious ListCourierMessages Request
mediumDetects requests to the ListCourierMessages API with unusually long page_token parameters, potentially indicative of SQL injection attempts.
Ory Kratos Potential SQL Injection in page_token
highDetects potential SQL injection attempts in the page_token parameter of the ListCourierMessages API based on common SQL injection syntax.
Detection queries are kept inside the platform. Get full rules →