fix(AppFramework): Allow requests with OCS-APIRequest header to pass CSRF checks #46760
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Minimal fix extracted from #43699.
OCS APIs use the custom header to prevent CSRF attacks as described in https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html#employing-custom-request-headers-for-ajaxapi:
While it is possible for clients to obtain CSRF tokens, it is a lot easier sending the custom header and not maintaining any state.
Using the same method for non-OCS endpoints is safe and simply allows using endpoints that require CSRF protection at the moment.
Usually external clients do not need to send the CSRF token as the cookie check will skip the token check, but if the client needs to send cookies because it also has to call APIs that are session aware (e.g. Talk room join/leave) or it runs in a browser, where the cookies are sent automatically, this measure is necessary. The existing CORS protection will prevent hijacks as it will requests with the header.
Ideally the two CSRF protections would be aligned and merged into a single implementation as there is no reason to have separate implementations of this protection, but this can be done in the future.
Checklist