spring-projects / spring-projects/spring-security-samples
`HiddenHttpMethodFilter` configuration in the `hello-mvc-security` example project?
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.8k
- Forks
- 797
- Avg merge
- 3m
- Merged PRs (30d)
- 5
Description
Inquiry about the HiddenHttpMethodFilter configuration in the hello-mvc-security example project
Hello,
In the hello-mvc-security example project, to use the HiddenHttpMethodFilter correctly, wouldn’t it be better to place this filter before the Spring Security Filter?
public class SecurityWebApplicationInitializer extends AbstractSecurityWebApplicationInitializer {
...
// ✨ I am inquiring whether additional configuration is necessary?”
@Override
protected void beforeSpringSecurityFilterChain(ServletContext servletContext) {
FilterRegistration.Dynamic encodingFilter =
servletContext.addFilter("hiddenHttpMethodFilter", new HiddenHttpMethodFilter());
encodingFilter.addMappingForUrlPatterns(
null, false, "/*");
}
}
If the HiddenHttpMethodFilter is not placed before the security filter, there have been times when setting up requestMatchers() resulted in unintended behavior.
For example, after setting the hidden input below in the form…
...
<input type="hidden" name="_method" value="DELETE"/>
...
If the requestMatchers() configuration is set up as follows…
...
.requestMatchers(HttpMethod.DELETE, "/targetUrl/*")
.hasAuthority("ADMIN")
...
There were times when it didn't work as I intended.
When I requested deletion with "USER" permission, it was deleted.
Even so, since there are no web pages in the hello-mvc-security example project that utilize the HiddenHttpMethodFilter, it seems that it might be okay to remove the HiddenHttpMethodFilter.
Inquiry Summary
- Wouldn’t it be better to remove the
HiddenHttpMethodFilterconfiguration from the security settings of thehello-mvc-securityexample project? - If not removed, shouldn’t the
HiddenHttpMethodFilterbe positioned before theSpringSecurityFilterChain?
Thank you. Have a great day. 👍
Contributor guide
No contributing guide indexed for this repository
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.
Research direction
Start with servlet/java-configuration/hello-mvc-security/src/main/java/example/MvcWebApplicationInitializer.java and trace registration order for HiddenHttpMethodFilter relative to the Spring Security filter chain. Reproduce the shown DELETE requestMatchers scenario, then determine whether the example should remove the filter or register it before security; done means the example configuration behaves consistently with its authorization rules.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- security
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 32/100