Contents
Is CSRF possible with Bearer Token?
The Bearer Authentication is a good way to prevent CSRF, as there is no way for an attacker to know the value of a valid token of an authenticated user. In absence of a token, they may rely on cookies for authentication which will make the web application vulnerable to CSRF.
Is Bearer Token same as OAuth?
Bearer Tokens are the predominant type of access token used with OAuth 2.0. To get an access token you send the Authentication server this bearer token along with your client id. This way the server knows that the application using the bearer token is the same application that the bearer token was created for.
Do I need CSRF for API?
An API pretty much precludes CSRF, because its entire purpose is generally to allow 3rd-party entities to access and manipulate data on your site (the “cross-site” in CSRF). So, yes, I think as a rule any API view should be CSRF exempt.
Why is X-Csrf-Token request header missing when using bearer authentication?
Moved this issue to Simple Oauth issue queue to solve it within its codebase. If Simple Oauth is not enabled, Bearer header makes no sense. Implementing approach suggested by hchonov: decorating a CsrfRequestHeaderAccessCheck from within simple_oauth module, and skipping csrf token check within this decorator.
How to add Authorization header with Bearer Token?
Just add Authorization header with any bearer token (without having enabled simple_oauth at all), and CSRF token check will be cancelled. As I would see the solution, we would need to know not only that the user is authenticated, but which method was used for authentication.
Do you need CSRF protection for Bearer tokens?
If you only use authentication via Bearer tokens and not via cookies, then there is no concern of CSRF vulnerability, and no extra steps are required for security. It’s Incorrect to say that “as long as authentication happens in the header and not by cookies that you don’t have to worry about csrf-protection.”.
How does CSRF occur in a web page?
CSRF occurs because a request to a HTTP end point automatically includes cookies (as it should) plus required headers as described by the server and doesn’t require a user to physically do something. They simply visit a web page with the CSRF vector on.