silverstripe / silverstripe-graphql

Serves Silverstripe data as GraphQL representations
BSD 3-Clause "New" or "Revised" License
52 stars 61 forks source link

Unable to disable CSRF Middleware #574

Closed mkekit closed 6 months ago

mkekit commented 6 months ago

Module version(s) affected

5.1.3

Description

Unfortunately i'm not able to disable the CSRF protection as mentioned in the documentation. Here's the contents of my config under app/_config/graphql.yml:

---
Name: app-graphql
Only:
  classexists: 'SilverStripe\GraphQL\Schema\Schema'
After:
  - graphqlconfig
---
SilverStripe\GraphQL\Auth\Handler:
  authenticators:
    - class: SilverStripe\GraphQL\Auth\BasicAuthAuthenticator
      priority: 100

SilverStripe\GraphQL\Schema\Schema:
  schemas:
    default:
      src:
        - app/_graphql

SilverStripe\Core\Injector\Injector:
  SilverStripe\GraphQL\QueryHandler\QueryHandlerInterface.default:
    class: SilverStripe\GraphQL\QueryHandler\QueryHandler
    properties:
      Middlewares:
        csrf: false

Which leads to the following error:

"errors": [
        {
            "message": "Mutations must provide a CSRF token in the X-CSRF-TOKEN header",
            "code": 0,
            "file": "/var/www/html/vendor/silverstripe/graphql/src/Middleware/CSRFMiddleware.php",
            "line": 26
       }
]

What i've missed here?

Thanks in advance!

How to reproduce

Possible Solution

No response

Additional Context

No response

Validations

mkekit commented 6 months ago

Hello, I found a solution for the problem/behavior. After adding 'graphql-middlewares' additionally as 'After' in my graphql.yml config, everything works now. Perhaps this should also be added to the documentation?

Here's the updated configuration:

---
Name: app-graphql
Only:
  classexists: 'SilverStripe\GraphQL\Schema\Schema'
After:
  - graphqlconfig
  - 'graphql-middlewares'
---
...