-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Add CrossSite Request Forgery prevention filter #27726
Conversation
@sberyozkin @geoand Hm, when exactly is the |
@mkouba I see, sure, Georgios, can you clarify please when RESTEasy Reactive does it ? |
Yeah, I've just realized the same is the case with another reactive filter config: https://github.com/quarkusio/quarkus/blob/main/extensions/oidc-client-reactive-filter/runtime/src/main/java/io/quarkus/oidc/client/reactive/filter/runtime/OidcClientReactiveFilterConfig.java |
@sberyozkin have you tried using field injection? |
@geoand I haven't as injecting all the properties is not great (8 properties are there right now but can grow) |
I mean injecting the config object (like you are doing now), but instead of using constructor injection, using field injection |
Oops :-), sure, I'll try shortly |
@geoand, @mkouba, Injecting it as a field makes no difference, here is a stack trace:
It looks like the reactive filters can not have a Runtime Init config at this stage which is not a PR blocker, and it should be looked at in a follow enhancement request, do you agree ? What about the 2nd problem (re |
|
@geoand So if you look at the description of the 2nd problem - it does not work if I set as an instance variable. I think I'll go ahead and open 2 issues as I believe there is nothing that can be done at this PR level to address either of the issues. Can you please review the reactive code etc ? |
This comment has been minimized.
This comment has been minimized.
Sorry, I have too many bugs to look into currently, so this will have to wait. |
To be honest, I don't think the implementation of |
@geoand I can ask someone else to review if you are busy, np.
I have the tests passing and I do not understand your comment - the implementation seems sound to me. I'm OK with reworking it as |
...untime/src/main/java/io/quarkus/csrf/reactive/runtime/CsrfRequestResponseReactiveFilter.java
Outdated
Show resolved
Hide resolved
Nevermind my comment about |
8369168
to
03b29ae
Compare
@geoand I've added But I've also just seen @mkouba's suggestion - so I can give it a quick try thanks |
03b29ae
to
6a935e8
Compare
I've squashed the last commit so that if Martin's suggestion works I can keep it as a separate commit to review |
Now I'm really happy with the way I can handle the runtime config in the filter :-), @geoand does it look OK to you ? |
I'll have a look tomorrow |
This comment has been minimized.
This comment has been minimized.
...untime/src/main/java/io/quarkus/csrf/reactive/runtime/CsrfRequestResponseReactiveFilter.java
Outdated
Show resolved
Hide resolved
f1e6d95
to
79d159e
Compare
I think it would be best to squash the commits |
This comment has been minimized.
This comment has been minimized.
Sure |
Though I'd like to add one more config option, for the CSRF cookie optionally not to be created per every new GET request - there is an assumption there an HTML form will be returned for every one but in real applications it won't be the case, will do all tomorrow, thanks |
I've just noticed a perf improvement suggestion from @mkouba as well, the config should be accessed via a local var, will take care of it as well |
79d159e
to
618b8d5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I updated the code to use a local variable to access the config instance, and added 2 more config properties, one allowing to avoid creating the cookies for all the requests (this one is also checked in the test), and one allowing to pass through non-url-form-encoded POSTs as a complex application may have all sort of interactions with the outside world, and POST JSONs should not be really blocked if a resource method exists, in the latter case the CORS filter + XHTMLRequest may be handling the CSRF risks separately... I think it is probably all for now, it can be tricky to implement such a feature covering all the variations from the very start, but we'll have a good enough base... |
Failing Jobs - Building 618b8d5
Full information is available in the Build summary check run. Failures⚙️ JVM Tests - JDK 11 Windows #- Failing: extensions/smallrye-graphql/deployment
! Skipped: extensions/smallrye-graphql-client/deployment integration-tests/hibernate-orm-graphql-panache integration-tests/smallrye-graphql and 1 more 📦 extensions/smallrye-graphql/deployment✖
|
Looks like a window build has just died, have been waiting for it for all day to finish :-) |
I'll just go ahead and merge to give it a couple of days to settle, as I'm off tomorrow as well :-) |
Wait a minute: this should also support multipart forms! #28379 |
Fixes #8399.
This PR is based on the ideas shown by @kekbur in the code shared at #8399 but with some modifications:
preMatching
(implicitly non-blocking) server request filterRoutingContext
's way of checking the form fields is used and theInputStream
is recreatedHowever I've not managed to resolve 2 problems yet which might be related:
CsrfReactiveConfig
runtime init - the test is failing if it is runtime init saying thatCsrfReactiveConfig
has not been initialized at the time ofCsrfRequestResponseReactiveFilter
's construction (CsrfReactiveConfig
is injected into theCsrfRequestResponseReactiveFilter
constructor). I tried initializing the filter it at the runtime init time - by injecting an empty recorder which did not really help...non-static
SecureRandom
field inCsrfRequestResponseReactiveFilter
- the native test buid is failing in this case - looks like RESTEasy Reactive filters are kept in astatic
field inRESTEasy Reactive
? So a newSecureRandom
is created directly in the request filter method implementation right now - not a big problem as the token creation should not happen often but I wonder if it can be optimized@geoand @mkouba Can you please review and advise on resolving these 2 issues ?