Skip to content

Missing CORS Policy in Apollo GraphQL Server

Description

The Apollo GraphQL server lacks a CORS policy. By default, the batteries-included apollo-server package serves the Access-Control-Allow-Origin HTTP header with the wildcard value (*).

Examples

Insecure Code

js
new ApolloServer({})

Secure Code

js
new ApolloServer({ cors: { origin: '*' } })

Remediation

Add a CORS policy to the Apollo GraphQL server by including the 'cors' option when creating a new ApolloServer instance, e.g., 'new ApolloServer({ cors: { origin: '*' } })'.

Rule Details

FieldValue
IDCODE-0276
CategoryWeb
SeverityMEDIUM
CWECWE-942
ConfidenceHIGH
ImpactLOW
LikelihoodLOW
ExploitabilityMODERATE
Tagscors, apollo-server
OWASPN/A

References