-
Notifications
You must be signed in to change notification settings - Fork 21
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
Can't get CSRF protection to work on CXF #27
Comments
Yes, you are correct. The method should actually be processed by
Could you please check if the interceptor registration works by confirming that this code gets executed: There is also some special handling for CXF here: But my guess is that this CXF workaround isn't the cause of your issues. My only other guess is that the name binding isn't working as expected for some reason. I ran into issues regarding the name binding before, so this is just a wild guess, but it may be possible. |
I can confirm that DefaultConfigProvider.java#L45 is being hit. Also, inside |
Thanks for confirming. Looks like we need to do some more debugging to solve this. Unfortunately there are a few weird issues with CXF like #168 for example. I'll try to setup some test environment with plain Tomcat + CXF + Ozark to see if I can find the root cause for this. Of course any kind of help is welcome! |
Yesterday I've tried to debug OpenLiberty itself - to no avail. I was just about to resort to plan B, which is exactly what you've proposed. I'm far from an expert in CXF, but I'll see what I can find... |
Ok, great! Any kind of help is welcome. My current guess is that the name binding |
Just to make sure... does it work in other JAX-RS implementations? I've found RESTful Java with JAX-RS 2.0 (Second Edition), that says:
If that was true, I'd expect that other JAX-RS implementations also suffer from this. In this particular case, the controller method isn't reading Java objects directly from the HTTP message body. |
It is definitely working on Glassfish and AFAIK also on Wildfly. My interpretation of this spec requirement is that the reader is needed because you are actually using |
Well, of course I hoped that it would work in other JAX-RS implementations :-). The document I referred to isn't a specification, so I don't know it's status. I interpreted it as "when a message body is read to a POJO" - like when a JSON structure is sent and the controller method has a method argument of a corresponding Java structure. I'll try a bit more debugging when/how these interceptors are invoked in CXF in the coming days. |
Thanks for the clarification. Well, actually it may be possible that different JAX-RS implementations handle The exact wording in the JAX-RS spec is:
It would be interesting to know how CXF handles this requirement. Also, it may be worth a try to add a parameter of type |
Bingo! Adding an By the way, paragraph 3.3.2.1 of the JAX-RS 2.1 spec suggests that a
I did a quick search in the CXF issue tracker, but can't find anything related to this issue. What would be the way to go here? File an issue with CXF and see if they agree upon our interpretation of the spec at this point? |
Something similar seems to happen on Wildfly. See #38. |
We might have fixed this in #39, but there are still some issues with CSRF-Validation and CXF. I'll look into it. |
Things got better with the mentioned changes, but the example Maarten provided still doesn't work. The CSRF-Validation-Exception get's thrown and is handled by the ExceptionMapper, but the form renders nonetheless. It looks to me like CXF doesn't bail out on the exception, but continues to pass the request to the ViewableWriter. This ends up in the strange situation where you get the view you requested, but with a 403 status code. @chkal do we have any known issues with the exception mappers in OpenLiberty? |
@gtudan To be honest, I'm focusing on Glassfish and Wildfly for now, as there were too many issues with CXF in the past. So TomEE and Liberty are second proprity for me at the moment. But the behavior you are describing is really weird. IMO the ViewableWriter should not be executed in this case. |
So the good news is that the CSRF-Validation works on CXF on-par with the other implementations. Sadly we seem to have an issue with csrf-validation in combination with the @CsrfProtected
@POST
@Path("/configure")
// @View("redirect:/hello") - replace this
public String configure(@FormParam("locale") final String locale) {
return "redirect:/hello"; // with this
} @mthmulders: If its okay with you I would like to close the issue in favor of the more detailed #91. |
I'm totally fine with that, thanks for verifying though. |
Thursday Sep 06, 2018 at 19:07 GMT
Originally opened as mvc-spec/ozark#202
Setup:
I'm trying to get CSRF protection to work on my controller. It looks like this:
If I read the spec correctly, the default for
javax.mvc.security.CsrfProtection
isEXPLICIT
, saying that any method annotated with@CsrfProtected
is to be protected.I have a page that submits an HTML form to this controller method using POST, and it lacks the CSRF token parameter. I would expect the form submission to be rejected, but my controller method is hit.
Browsing through Ozark source code, I expect it is the responsibility of the
CsrfValidateInterceptor
class to perform this check. Using the debugger, I can see it is being instantiated, but the breakpoint inaroundReadFrom(...)
is never hit.Again, reproduction repo is https://github.com/mthmulders/openliberty-mvc. Any clues?
The text was updated successfully, but these errors were encountered: