AUTHENTICATION AND AUTHORIZATION BYPASSES
Fundamental Concepts
Authentication: This is the process of verifying a client's identity.
Authorization: This process determines what actions and data a client is allowed to access after their identity is verified.
GraphQL's Role: GraphQL itself doesn't have built-in authentication or authorization mechanisms; these are left to the developers to implement. This variability in implementation introduces potential vulnerabilities.
In-Band vs. Out-of-Band Controls
In-band Authentication and Authorization: These controls are implemented directly within the GraphQL API.
This approach increases the attack surface, making the API more vulnerable to direct attacks.
When authentication and authorization mechanisms are part of the GraphQL schema, they are more likely to be targeted and potentially bypassed.
Out-of-band Authentication and Authorization: These delegate the security functions to external systems, which can be a more secure approach.

Common Authentication Approaches
HTTP Basic Authentication: This method sends credentials in the header of a client request.
It is straightforward but can be insecure if not implemented over HTTPS.
OAuth 2.0 with JSON Web Tokens (JWT): A common approach allowing third-party applications to obtain temporary access to a GraphQL API.
JWTs are vulnerable if not implemented securely.
A common vulnerability is the
alg(algorithm) header parameter being set tonone, bypassing signature verification.
Other Methods:
Libraries such as GraphQL Modules and GraphQL Shield can be used to implement authorization logic within the schema.
Custom schema directives (e.g.,
@auth,@protect, or@hasRole) can enforce authorization rules at the schema level.
@auth
requires
String
@protect
role
String
@hasRole
role
String
Some APIs use IP-based allow lists for authorization, but these lack granularity.
Detecting the Authentication Layer
Canary Queries: Sending specific test queries can reveal how the API responds, indicating the presence of authentication mechanisms.
Analyzing Error Messages: Error messages can provide clues about the authentication process.
Identifying Mutations: Look for mutations like
login,signup,register,createUser, orcreateAccountthat hint at an authentication setup.
Common GraphQL Authentication Errors
Authentication credentials are missing. Authorization header is required and must contain a value.
OAuth 2.0 Bearer with JSON Web Token
Not Authorised!
GraphQL Shield
Not logged in Auth required API key is required
GraphQL Modules
Invalid token! Invalid role!
graphql-directive-auth
Exploiting Authentication Controls
Brute-Forcing Passwords:
Query batching can be used to bypass rate-limiting by combining multiple login attempts in a single request.
Tools like CrackQL can automate this process.
Bypassing Allow-Listed Operation Names: Attackers can bypass allow lists of operation names by spoofing or changing the operation name.
JWT Forgery: If JWT signatures are not correctly verified, attackers can forge valid tokens.

Exploiting Authorization Controls
Authorization Testing:
It's essential to identify all possible paths to a given object type, using tools like
graphql-path-enum. This allows an attacker to understand the relationships within the schema and find authorization vulnerabilities.
Field stuffing techniques can be used to attempt access to unauthorized fields.
CrackQL can be used to automate field and argument brute-forcing.
Inconsistent Protection: Developers might protect some queries but not others, offering different paths to the same data. For example,
pastesmight be protected, but notpasteorreadAndBurn.
Last updated
Was this helpful?