You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
During a normal workflow the handler mapping is retrieved after the multipartRequest is parsed. DispatcherServlet.doDispatch
DispatcherServlet.doDispatch(..) {
// ...processedRequest = checkMultipart(request); // if true, wraps request with MultipartHttpServletRequestmultipartRequestParsed = (processedRequest != request);
// Determine handler for the current request.mappedHandler = getHandler(processedRequest);
// Creates GrailsParameterMap for first time with GrailsParameterMap because originalParams is null
}
for (Entry<String, List<MultipartFile>> entry : fileMap.entrySet()) {
List<MultipartFile> value = entry.getValue();
if(value.size() == 1) {
requestMap.put(entry.getKey(), value.get(0));
}
else {
requestMap.put(entry.getKey(), value);
}
}
}
updateNestedKeys(requestMap);
}
But with SpringSecurity getHandler is called first in HandlerMappingIntrospector which results in originalParams being not null and MultiFileMap not being set.
It does not happen with the Spring Security Core plugin because it does not use HandlerMappingIntrospector
--
Note: this same problem could occur in any Filter or code that calls GrailsWebRequest.getParams() prior to the DispatcherServlet invoking checkMultipart(request).
It seems like others have attempted workarounds by calling WebUtils.clearGrailsWebRequest() which IMO is a little hacky.
Debugging this I also noticed inefficiencies such as how GrailsControllerUrlMappings.matchAll works. It appears StandardServletMultipartResolver.resolveMultipart is invoked multiple times during the same request.
MultPartRequests do not process correctly when using Spring Security (without plugin)
Replication instructions
just include the spring-boot-starter on any app that process uploads
implementation "org.springframework.boot:spring-boot-starter-security"
and notice that
params.file
does not bind.Description
During a normal workflow the handler mapping is retrieved after the multipartRequest is parsed.
DispatcherServlet.doDispatch
grails-core/grails-web-common/src/main/groovy/org/grails/web/servlet/mvc/GrailsWebRequest.java
Lines 243 to 265 in 6f9d173
grails-core/grails-web-common/src/main/groovy/grails/web/servlet/mvc/GrailsParameterMap.java
Lines 82 to 116 in 6f9d173
But with SpringSecurity getHandler is called first in HandlerMappingIntrospector which results in originalParams being not null and MultiFileMap not being set.
HandlerMappingIntrospector.getMatchableHandlerMapping
This is because standard Spring Security uses the RequestMatcherDelegatingAuthorizationManager which uses the HandlerMappingIntrospector.
It does not happen with the Spring Security Core plugin because it does not use HandlerMappingIntrospector
--
Note: this same problem could occur in any Filter or code that calls
GrailsWebRequest.getParams()
prior to the DispatcherServlet invokingcheckMultipart(request)
.It seems like others have attempted workarounds by calling
WebUtils.clearGrailsWebRequest()
which IMO is a little hacky.Debugging this I also noticed inefficiencies such as how
GrailsControllerUrlMappings.matchAll
works. It appears StandardServletMultipartResolver.resolveMultipart is invoked multiple times during the same request.#13841
The text was updated successfully, but these errors were encountered: