Strawberry GraphQL is a popular Python library for designing GraphQL APIs, favored by developers for its type checking, its use of modern language features, and its flexibility. However, a type confusion vulnerability was recently discovered in the library, specifically affecting versions .182. to .256.. This vulnerability impacts multiple ORM (Object Relational Mapping) integrations including Django, SQLAlchemy, and Pydantic, and can lead to information disclosure and potential privilege escalation. The vulnerability has been fixed in version .257..

Vulnerability Details

The type confusion vulnerability exists in Strawberry GraphQL's relay integration and occurs when multiple GraphQL types are mapped to the same underlying model while using the relay node interface. When querying for a specific type using the global node field (for example, FruitType:some-id), the resolver may incorrectly return an instance of a different type mapped to the same model (for example, SpecialFruitType). This can lead to sensitive information being exposed if the alternate type has confidential fields, and potential privilege escalation if the alternate type contains data meant for limited access.

Exploit Details

To better understand the vulnerability, let's consider the following code snippet from a vulnerable application:

import strawberry
from strawberry.relay import Node

# Common model underlying both FruitType and SpecialFruitType
class Fruit:
    def __init__(self, id: str, name: str, color: str):
        self.id = id
        self.name = name
        self.color = color

@strawberry.type
class FruitType(Node):
    id: strawberry.ID
    name: str

@strawberry.type
class SpecialFruitType(Node):
    id: strawberry.ID
    name: str
    color: str

# Resolver for both types using the common Fruit model
@strawberry.resolver(cls=Node, name="resolve_id")
def resolve_id(model: Fruit) -> Union[FruitType, SpecialFruitType]:
    if model.color == "red":
        return SpecialFruitType(model)
    return FruitType(model)

schema = strawberry.Schema(query=FruitType)

In the code above, FruitType and SpecialFruitType are two GraphQL types mapped to the same underlying Fruit model. The resolver function resolve_id returns an instance of SpecialFruitType if the color attribute is "red" and an instance of FruitType otherwise.

Now, imagine an attacker knowing that a specific fruit has id = "42" and wants to obtain its color attribute (which is confidential). They can send the following GraphQL query:

{
  node(id: "SpecialFruitType:42") {
    ... on SpecialFruitType {
      name
      color
    }
  }
}

The query specifically requests a SpecialFruitType object. However, due to the type confusion vulnerability, the server may return an object of type FruitType with the same id – disclosing the confidential color attribute in the process.

The vulnerability has been reported and documented in several places

1. Strawberry GraphQL GitHub Repository Issue
2. CVE-2025-22151 – NIST National Vulnerability Database
3. Strawberry GraphQL .257. Release Notes

Solution and Mitigation

The developers of Strawberry GraphQL have addressed the vulnerability in version .257.. If you are using a vulnerable version of Strawberry GraphQL, you should update to version .257. immediately. Make sure to check the release notes mentioned above for additional information on possible breaking changes and other updates.

Conclusion

This case underscores the importance of staying up-to-date with the latest security patches in open-source libraries. Developers using Strawberry GraphQL should update their projects to the latest version to mitigate the risk of information disclosure and privilege escalation. Additionally, always refer to the aforementioned resources to keep yourself informed about potential vulnerabilities and their corresponding fixes.

Timeline

Published on: 01/09/2025 19:15:20 UTC