Symptom
“CSRF token validation failed” error occurs when executing POST/PATCH OData call via external consumers.
Environment
SAP Cloud for Customer
Reproducing the Issue
- Go to Administrator work center.
- Select General Settings view.
- Select OData API Monitor under System Administration.
- Select the 403 error entry and select View Response Payload.
Here it's possible to find the error “CSRF token validation failed”.
Cause
Since OData is a stateless protocol, it's required to do cookie handling in order to make a successful modifying call. Otherwise, the CSRF token will be considered invalid, as the second call will be based on a different session.
Resolution
The implementation should avoid relying on specific cookie names or sequences. However, customers should ensure that they process all cookies they receive in accordance with the cookie specification
Currently, the XSRF cookie can be either sap-XSRF_<SID>_<client> or SAP_SESSIONID_<SID>_<CLIENT> but this can change as well any time.
An XSRF check is a simple compare of a XSRF header towards a XSRF cookie.
See Also
Keywords
ODATA; CSRF Token; External Consumers; Cookie , KBA , AP-RC-ODF , OData framework (C4C Only) , How To