The vulnerability (CVE-2024-57190) in Erxes <1.6.1 allows an attacker to bypass authentication by providing a User HTTP header. This header was improperly trusted by the application to determine the user's identity.
The analysis of the patch 4ed2ca797241d2ba0c9083feeadd9755c1310ce8 reveals two key areas of modification:
-
Header Stripping in Middleware:
- The
userMiddleware function in packages/gateway/src/middlewares/userMiddleware.ts was modified to explicitly delete the req.headers['user']. This indicates that, prior to the patch, this middleware did not sanitize this header, allowing it to be processed or passed through, leading to the authentication bypass.
- Additionally, a new, unnamed middleware was added at the entry point in
packages/gateway/src/index.ts to also delete this header. This is a broader fix ensuring the header is removed early in the request lifecycle.
-
Defensive Check in GraphQL Resolver:
- The
currentUser GraphQL resolver in packages/core/src/data/resolvers/queries/users.ts was modified to add a type check for user._id before using it. This suggests that this resolver could receive a user object (derived from the malicious header) with an improperly structured _id, and previously, it would attempt to use this potentially unsafe data directly.
The root cause is the failure to treat the User HTTP header as untrusted input. The userMiddleware is identified as a vulnerable function because it was a key component in the request handling chain that should have addressed this header but didn't. The currentUser resolver is identified as vulnerable because it consumed the user context that could be tainted by this header, leading to unauthorized data access.
During exploitation, an attacker would send a request with a crafted User header. The userMiddleware (in its vulnerable state) would fail to remove or validate this header. Subsequently, when a GraphQL query like currentUser is executed, the resolver would operate based on the fraudulent user identity provided by the attacker, leading to an incorrect access control scenario.