I have installed the barryvdh/laravel-cors package in my Laravel 5.6 app, and added the relevant lines to my middeware groups in app\Http\Kernel.php
, and published the config file as per the instructions.
I have disabled CSRF checks for my api routes in VerifyCsrfToken.php
with
protected $except = [
'api'
];
I have set the config file as below:
'supportsCredentials' => false,
'allowedOrigins' => ['https://developer.mozilla.org'],
'allowedHeaders' => ['Content-Type', 'X-Requested-With'],
'allowedMethods' => ['GET', 'POST', 'PUT', 'DELETE']
'exposedHeaders' => [],
'maxAge' => 0,
...and I have have run a test POST
request in Postman using "Origin: https://developer.mozilla.org" in the header.
It's working- fine. And if I change that Origin key to anything other than https://developer.mozilla.org it throws the "Not allowed in CORS policy." error. Which is what I'd expect, as per the config- fine.
BUT if I change the config line to
'allowedMethods' => ['GET']
(ie. allow only GET requests), and run the same POST request in Postman... it still works.
Why? Why doesn't it respect the limitation imposed in the config for allowedMethods?