on 2024 Nov 08 2:00 PM
Hello Community,
The app contains a FileUploader element. The related backend oData service has CSRF protection enabled. To enable file upload, there is a controller extension for the FileUploader where the CSRF token is fetched and explicitly added (x-csrf-token) to the POST request header. It works correctly from SAP BAS with "Preview application".
The app is now deployed to Cloud Foundry, where it is added to a SAP Build Work Zone standard edition page. The upolad from the Build Work Zone site throws the error 403, and this is found in the approuter error log:
POST request to /sap/opu/odata/sap/Z<....> completed with status 403 The request contains an invalid x-csrf-token
I can se in the browser debugger that the request does contain the x-csrf-token parameter with a plausible value. That part looks identical as when testing from SAP BAS where the token is accepted.
I have found note 3495019 "403 error when the AppRouter generates a CSRF Token" which seems relevant. Except I am pretty sure the CSRF protection is already disabled in the xs-app.json. Here it is:
{
"welcomeFile": "/index.html",
"authenticationMethod": "route",
"routes": [
{
"source": "^/sap/(.*)$",
"target": "/sap/$1",
"destination": "<name of my Cloud Connector destination>",
"authenticationType": "xsuaa",
"csrfProtection": false
},
{
"source": "^/resources/(.*)$",
"target": "/resources/$1",
"authenticationType": "none",
"destination": "ui5"
},
{
"source": "^/test-resources/(.*)$",
"target": "/test-resources/$1",
"authenticationType": "none",
"destination": "ui5"
},
{
"source": "^(.*)$",
"target": "$1",
"service": "html5-apps-repo-rt",
"authenticationType": "xsuaa"
}
]
}
I did find number of similar questions, most notably:
but no solved ones, or possibly I do not understand the recommendations and need more guidance.
Please advise what to do - thank you in advance!
Request clarification before answering.
Hi!
Just a heads up - as I am also on my way having a similar issue, I found out the managed approuter does not allow / support the deactivation of `x-csrf-token` - Check out this chapter on SAP Help: https://help.sap.com/docs/cloud-portal-service/sap-cloud-portal-service-on-cloud-foundry/configure-a... (bottom):
The managed application router (HTML5 Applications Runtime) enables CSRF protection for any HTTP method that is not GET or HEAD and the route is not public.
Looks like, we've to live with that fact. However, I am having the same issue, running into a "403 - (Fortbidden)" Issue, by trying to POST something to a CPI endpoint.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @dr_vup, thank you for commenting. My interpretation of note 3495019 (403 error when the AppRouter generates a CSRF Token) was that the CSRF protection on the approuter can be disabled.
Have you tried the xs-app.json setting recommended in the note ("csrfProtection": false) ? Did it make a difference for your issue?
User | Count |
---|---|
70 | |
21 | |
9 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.