Commit faae2d5
authored
Update XsrfMiddleware.php (#777)
As described here: #776 (comment), I couldn't get the XsrfMiddleware to work.
Debugging extensively, I found two issues:
1) My front-end (Angular / httpClient) wasn't able to detect the XSRF-TOKEN Cookie, because its "path" value was not "/". Because of that, it did not send the X-XSRF-TOKEN Header. Setting the Cookie "path" value to "/" via XsrfMiddleware/getToken solved this problem.
2) When sending X-XSRF-TOKEN: 9aead2ceb0e150e1 in the Header, $request->getHeader($headerName) returns an Array ( [0] => 9aead2ceb0e150e1 ) - at least in my test cases. So "$token != $request->getHeader($headerName)" was always false. Changing the condition to "$token != $request->getHeader($headerName)[0]" solved this problem.
Tested with Mozilla Firefox 86.0.1 and Google Chrome Version 89.0.4389.72 (both on Linux).
Of course, I don't know if these changes have any unwanted side effects or will work in all environments.1 parent 6d96185 commit faae2d5
1 file changed
+2
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
| 23 | + | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| |||
0 commit comments