spring-projects / spring-projects/spring-security
UrlMapping with identical matcher applied in wrong order
@jzheaux is already working on this.
Since Nov 4, 2020.
- Dominant language
- Java
- Stars
- 9.6k
- Forks
- 6.3k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 52
Description
Summary
The docs for authorizeRequests state:
There are multiple children to the http.authorizeRequests() method each matcher is considered in the order they were declared.
However, if two matchers are declared with the exact same pattern, the second one defined actually "wins" instead of the first one.
This appears to be caused by converting a List to a Map. In AbstractConfigAttributeRequestMatcherRegistry in the createRequestMap function:
for (UrlMapping mapping : getUrlMappings()) {
RequestMatcher matcher = mapping.getRequestMatcher();
Collection<ConfigAttribute> configAttrs = mapping.getConfigAttrs();
requestMap.put(matcher, configAttrs);
}
Just changing put to putIfAbsent in the last line of the for loop should resolve this issue.
Actual Behavior
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("A").denyAll()
.antMatchers("A").permitAll();
The "denyAll" is ignored and any URL matching "A" will be permitted.
Expected Behavior
I would expect URLs matching "A" to be denied since that was defined first.
Version
4.2.3-RELEASE
but appears to be the same in the latest code
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.