-
Notifications
You must be signed in to change notification settings - Fork 104
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
Security Filter ignores configured matchers when deciding on a rule #710
Comments
Indeed, there is a flaw here, only the path is taken into account. This should be fixed. As I said, I'm not fluent in Scala. A pull request is welcome here. Thanks |
I'm also not fluent in Scala. Has the Play-Pac4j integration active maintainers? If not, I can close this issue (and we may look into rewriting the SecurityFilter in Java). |
I'm the main maintainer and there are also occasional contributors. But unfortunately, I'm not fluent in Scala either. Rewriting the filter in Java is a great idea (as filters can be used both in Java and Scala), it would ease its maintenance. Keep the issue open if you intend to do so. |
I just came across this issue trying to set up a security filter. I can look into this. I know Scala. |
Sure. Your help will be appreciated. |
I'd guess noone is actually using the matchers config since it doesn't work. But how can/should the semantics change? I'm a little afraid of having it fall-through to the next match if the matchers don't match, since that could change behavior of current users. The docs aren't explicit on what happens with a non-matching matchers, but falling through feels like the intent. |
Ah, I see. The matchers do work. If the matcher fails, the security rules do not apply. ie. if my config is like
and I send a Unfortunately, SecureAction doesn't tell me if the request succeeded because of matchers or auth. Someone could be using matchers successfully right now. I don't see a way to change this behavior without potentially changing the semantics of someone's security config. However, I would really like some way to select rules based on matchers. My needs are similar to the google groups post. I have RESTful endpoints that should require different authorization for POST vs GET, but both must be authenticated. To do this safely, I think we would have to add another property (eg. Does that make sense or am I missing something? I'm more familiar with Scala and Play than pac4j. |
I think we should be able to define the same URL several times with different configurations. Like: {
"/test" = {
authorizers = "testRole"
matchers = "post"
},
"/test" = {
authorizers = "testSomethingElse"
matchers = "get"
}
} |
So we would have it evaluate all configs with the same regex, and fail at the first failure, and pass if all succeed? |
I think so. All should succeed. |
I cant share our workaround, but we basically have our own Filter in Java and dont use the Scala SecurityFilter any more. We made up a new attribute "methods" (instead of "matchers") and that is a string value of possibly comma separated http methods (e.g. "post,put"). We then found this behavior logical for us:
So this would mean for a config like: {
Lastly we optimized the regex usage. The original Scala SecurityFilter does in "findRule(..)" this: "pathNormalized.matches(rule.pathRegex)" .. and this is basically "String.matches(..)" which compiles the regex pattern on every invocation ad-hoc again. So we cache the Pattern object on creation and our variant of "findRule" then re-uses the Java Pattern objects. |
I just cut the releases and the new versions 12.0.1-PLAYx.y should be available in the Maven central repo soon. |
Hello,
its basically the same issue from here: https://groups.google.com/g/pac4j-users/c/vCZ9-YItIUg .When the security filter config for pac4j defines two rules that would match the same request, but uses "matchers" (e.g. HttpMethodMatcher, one POST, one GET) to define a more specific rule matching behavior, the current org.pac4j.play.filters.SecurityFilter ignores this in its "apply" method.
The logic in "findRule" does only apply regex matching on the path and is not taking any matchers into account. So the matchers are evaluated later when the chosen endpoint is executed - but to my understanding of the docs they should also be relevant in choosing the right rule.
(see https://github.com/pac4j/play-pac4j/blob/master/shared/src/main/scala/org/pac4j/play/filters/SecurityFilter.scala , method "private def findRule(..)"
Thanks a lot,
Joachim
The text was updated successfully, but these errors were encountered: