This is an automated email from the ASF dual-hosted git repository. mraible pushed a commit to branch check-salt-sent-with-upload-errors in repository https://gitbox.apache.org/repos/asf/roller.git
commit be0ad4ec98d00650f7991653b5c96eeae365c7f4 Author: Matt Raible <[email protected]> AuthorDate: Tue Nov 17 19:48:17 2026 -0700 Check a salt that was read from an upload with parse errors An upload action with multipart parse errors skipped the salt check even when the salt had been read, and left that salt in the cache. Now the check is skipped only when no salt could be read; otherwise the salt is validated and consumed as for any other multipart post. --- .../ui/struts2/util/ValidateSaltInterceptor.java | 6 ++- .../struts2/util/ValidateSaltInterceptorTest.java | 46 +++++++++++++++++++++- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/util/ValidateSaltInterceptor.java b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/util/ValidateSaltInterceptor.java index 759e54ca0..ea8022f81 100644 --- a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/util/ValidateSaltInterceptor.java +++ b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/util/ValidateSaltInterceptor.java @@ -71,10 +71,12 @@ public class ValidateSaltInterceptor extends AbstractInterceptor implements Stru // parse errors from the upload interceptor, and its workflow returns // the input page before the action method runs, so it can say what // went wrong. Struts gives the errors only to upload actions, so - // every other action still needs a valid salt. + // every other action still needs a valid salt, and so does an + // upload whose salt was read despite the errors. if (request instanceof MultiPartRequestWrapper && ((MultiPartRequestWrapper) request).hasErrors() - && invocation.getAction() instanceof UploadedFilesAware) { + && invocation.getAction() instanceof UploadedFilesAware + && request.getParameter("salt") == null) { return invocation.invoke(); } diff --git a/app/src/test/java/org/apache/roller/weblogger/ui/struts2/util/ValidateSaltInterceptorTest.java b/app/src/test/java/org/apache/roller/weblogger/ui/struts2/util/ValidateSaltInterceptorTest.java index befa0a6fc..3e491c95d 100644 --- a/app/src/test/java/org/apache/roller/weblogger/ui/struts2/util/ValidateSaltInterceptorTest.java +++ b/app/src/test/java/org/apache/roller/weblogger/ui/struts2/util/ValidateSaltInterceptorTest.java @@ -133,10 +133,54 @@ public class ValidateSaltInterceptorTest { assertEquals("input", interceptor.intercept(invocation)); - verify(multipartRequest, never()).getParameter("salt"); verify(invocation).invoke(); } + @Test + public void testSaltReadDespiteMultipartParsingErrorsIsConsumed() throws Exception { + try (MockedStatic<RollerSession> mockedRollerSession = mockStatic(RollerSession.class); + MockedStatic<SaltCache> mockedSaltCache = mockStatic(SaltCache.class)) { + mockedRollerSession.when(() -> RollerSession.getRollerSession(multipartRequest)).thenReturn(rollerSession); + mockedSaltCache.when(SaltCache::getInstance).thenReturn(saltCache); + when(context.get(StrutsStatics.HTTP_REQUEST)).thenReturn(multipartRequest); + when(multipartRequest.getMethod()).thenReturn("POST"); + when(multipartRequest.getContentType()).thenReturn( + "multipart/form-data; boundary=abc123"); + when(multipartRequest.hasErrors()).thenReturn(true); + when(multipartRequest.getParameter("salt")).thenReturn("validSalt"); + when(rollerSession.getAuthenticatedUser()).thenReturn(new TestUser("userId")); + when(saltCache.get("validSalt")).thenReturn("userId"); + when(invocation.getAction()).thenReturn(mock(UploadedFilesAware.class)); + when(invocation.invoke()).thenReturn("input"); + + assertEquals("input", interceptor.intercept(invocation)); + + verify(saltCache).remove("validSalt"); + verify(invocation).invoke(); + } + } + + @Test + public void testInvalidSaltReadDespiteMultipartParsingErrorsIsRejected() throws Exception { + try (MockedStatic<RollerSession> mockedRollerSession = mockStatic(RollerSession.class); + MockedStatic<SaltCache> mockedSaltCache = mockStatic(SaltCache.class)) { + mockedRollerSession.when(() -> RollerSession.getRollerSession(multipartRequest)).thenReturn(rollerSession); + mockedSaltCache.when(SaltCache::getInstance).thenReturn(saltCache); + when(context.get(StrutsStatics.HTTP_REQUEST)).thenReturn(multipartRequest); + when(multipartRequest.getMethod()).thenReturn("POST"); + when(multipartRequest.getContentType()).thenReturn( + "multipart/form-data; boundary=abc123"); + when(multipartRequest.hasErrors()).thenReturn(true); + when(multipartRequest.getParameter("salt")).thenReturn("usedSalt"); + when(saltCache.get("usedSalt")).thenReturn(null); + when(invocation.getAction()).thenReturn(mock(UploadedFilesAware.class)); + + assertThrows(ServletException.class, () -> interceptor.intercept(invocation)); + + verify(invocation, never()).invoke(); + } + } + @Test public void testMultipartParsingErrorsDontSkipTheSaltForOtherActions() throws Exception { try (MockedStatic<RollerSession> mockedRollerSession = mockStatic(RollerSession.class);
