GraphQL authentication
How to configure GraphQL authentication for Snyk API and Web targets
Configure authentication to scan an API using a GraphQL schema.
If your GraphQL API requires authentication, you can configure Snyk API & Web to run authenticated requests and scan the API endpoints.
After adding an API target, configure authentication before starting the scan. This is especially important when you select the introspection option for your schema, because best practice is to allow introspection only for authenticated requests.
GraphQL Introspection enabled is considered a Low Severity vulnerability. When enabled, restrict access to your GraphQL API using authentication.
Authentication methods
The authentication scenarios described in Configure OpenAPI authentication work the same way for your GraphQL API:
Authenticate with an API token in the request header: Using
application/jsonorapplication/x-www-form-urlencodedmedia typesAuthenticate with a static header or cookie
Authenticate with a fixed API key in a request parameter
Use application/graphql media type
GraphQL also supports application/graphql as the authentication media type. GraphQL servers support this format.
When using application/graphql as the authentication media type, the request body contains only the raw GraphQL query or mutation string.
Configure authentication
Navigate to the Targets page and click the gear icon to access the target settings.
Select the Authentication tab and locate the API TARGET AUTHENTICATION section.

Configure the authentication:
AUTHENTICATION MEDIA TYPE: Select
application/graphql.LOGIN URL: Enter the authentication URL.
AUTHENTICATION PAYLOAD: Enter the GraphQL mutation to send in the body of the POST request to the login URL.
Click Fetch to authenticate. The TOKEN SELECTOR field populates with fields from the authentication response. If authentication fails, Snyk displays an error.
In the TOKEN SELECTOR, choose the field that contains the authentication token.
In PLACE TOKEN IN, choose where to place the token in API requests (usually header, but cookie is also available).
In FIELD NAME, enter the name of the field in the header or cookie that holds the token.
(Optional) Set a VALUE PREFIX for the token value.
This is often needed for JWTs. For example, if your API requires a header like
Authorization: JWT <token>, configure:FIELD NAME:
AuthorizationVALUE PREFIX:
JWT
Click Save and enable.
You can turn this authentication on or off anytime using the Off/On toggle button, or delete the configuration using the Delete button.
To test for Broken Object Level Authorization (BOLA) vulnerabilities, you can add an additional user for authorization testing. Visit Set up your target for testing BOLA vulnerabilities for details.
Related content
Last updated
Was this helpful?

