-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Auto Validate AntiForgery Token for HTTP API Requests #5728
Conversation
Today I have the same issue after upgrade ABP 3.0.5 to ABP 3.3.2.
|
ABP changed something lately, but adding AntiForgery token supposed to be working out of the box, if request is set from a trusted source. I was able to resolve this for published site once I've changed to relative paths for my endpoints which front-end accesses (environment.ts settings) - there is some bug in github showing ABP source code and explaining why it needs to be set this way now:
But now I see it is still broken for localhost, since localhost endpoints differ by ports, not path names. It is not working when I am running Angular app via https. It does work for http. Probably there are still some other nuances, I will have to investigate this. |
I have now taken the abp framework api live, I am sending a request to the api from local with the angular application, but I cannot log in, I get an http 400 error, I do not know if I will experience this situation when I take the angular application live ? Unfortunately, I could not understand what I should do about the subject. Can you help me? |
hi @eemogz Please create a new issue and share the steps. Thanks. |
@maliming did @eemogz create a new issue? Is my issue related to this issue? I have /api in the environment apis url. and our auth server is /auth. (unlike @eemogz we only have the issue when we go live, not locally) Below are the details with a video showing what is going on. The first save request causes a redirect to 400 error, subsequent requests are accepted. Is this a bug that need to be fixed by abp team, or is there something we should try to do to resolve the issue? |
While AspNet Core automatically validates anti forgery token and handles the CSRF problem, it does nothing for the API Controllers by default.
If you use AutoValidateAntiforgeryTokenAttribute you solve the problem. But then you have another problem: No client can consume your APIs without sending antiforgery tokens. This is a problem when your client is a non-browser client and typically don't need to an antiforgery system at all.
I had discussed that with the AspNet team before. However there is no clear built-in solution. We had implemented a system for the ASP.NET Boilerplate before. So, I am implementing a similar system for the ABP Framework too. The purpose is to protect all APIs with zero config and also allows non-browser clients to consume your APIs without dealing this problem.
I will document it & explain the configuration options.