This is an automated email from the ASF dual-hosted git repository.

mraible pushed a commit to branch no-salt-for-static-files-6.1.x
in repository https://gitbox.apache.org/repos/asf/roller.git

commit 11b22019850256a48a61f9b4c03d1e9772e65683
Author: Matt Raible <[email protected]>
AuthorDate: Tue Nov 17 11:33:02 2026 -0700

    Don't start a session for Roller UI stylesheets, scripts and images
    
    LoadSaltFilter started a session and put a form salt in the cache for every 
request under /roller-ui, including the static files in /roller-ui/styles, 
/roller-ui/scripts and /roller-ui/images. It now passes those straight through.
---
 .../weblogger/ui/core/filters/LoadSaltFilter.java  | 21 +++++++++++++
 .../ui/core/filters/LoadSaltFilterTest.java        | 35 ++++++++++++++++++++++
 2 files changed, 56 insertions(+)

diff --git 
a/app/src/main/java/org/apache/roller/weblogger/ui/core/filters/LoadSaltFilter.java
 
b/app/src/main/java/org/apache/roller/weblogger/ui/core/filters/LoadSaltFilter.java
index 8a1c830fa..0552f6f93 100644
--- 
a/app/src/main/java/org/apache/roller/weblogger/ui/core/filters/LoadSaltFilter.java
+++ 
b/app/src/main/java/org/apache/roller/weblogger/ui/core/filters/LoadSaltFilter.java
@@ -32,11 +32,18 @@ import 
org.apache.roller.weblogger.ui.rendering.util.cache.SaltCache;
  */
 public class LoadSaltFilter implements Filter {
 
+    /** Roller UI static files, which never hold a form. */
+    static final String[] STATIC_PATHS = {"/roller-ui/styles/", 
"/roller-ui/scripts/", "/roller-ui/images/"};
+
     @Override
     public void doFilter(ServletRequest request, ServletResponse response, 
FilterChain chain)
         throws IOException, ServletException {
 
         HttpServletRequest httpReq = (HttpServletRequest) request;
+        if (isStaticFile(httpReq)) {
+            chain.doFilter(request, response);
+            return;
+        }
         httpReq.getSession(true);
         RollerSession rollerSession = RollerSession.getRollerSession(httpReq);
         if (rollerSession != null) {
@@ -50,6 +57,20 @@ public class LoadSaltFilter implements Filter {
         chain.doFilter(request, response);
     }
  
+    /** Stylesheets, scripts and images get no session and no salt. */
+    static boolean isStaticFile(HttpServletRequest request) {
+        String path = request.getServletPath();
+        if (path == null) {
+            return false;
+        }
+        for (String prefix : STATIC_PATHS) {
+            if (path.startsWith(prefix)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
     @Override
     public void init(FilterConfig filterConfig) throws ServletException {
     }
diff --git 
a/app/src/test/java/org/apache/roller/weblogger/ui/core/filters/LoadSaltFilterTest.java
 
b/app/src/test/java/org/apache/roller/weblogger/ui/core/filters/LoadSaltFilterTest.java
index 2087a005b..2ae319b27 100644
--- 
a/app/src/test/java/org/apache/roller/weblogger/ui/core/filters/LoadSaltFilterTest.java
+++ 
b/app/src/test/java/org/apache/roller/weblogger/ui/core/filters/LoadSaltFilterTest.java
@@ -109,6 +109,41 @@ public class LoadSaltFilterTest {
         }
     }
 
+    @Test
+    void staticFilesGetNoSessionAndNoSalt() throws Exception {
+        try (MockedStatic<SaltCache> mockedSaltCache = 
mockStatic(SaltCache.class)) {
+            mockedSaltCache.when(SaltCache::getInstance).thenReturn(saltCache);
+            for (String path : new String[] {"/roller-ui/styles/roller.css", 
"/roller-ui/scripts/date-fields.js",
+                    "/roller-ui/images/feather.svg"}) {
+                when(request.getServletPath()).thenReturn(path);
+                filter.doFilter(request, response, chain);
+            }
+
+            verify(request, never()).getSession(true);
+            verify(request, never()).getSession();
+            verify(request, never()).setAttribute(eq("salt"), anyString());
+            verify(saltCache, never()).put(anyString(), anyString());
+            verify(chain, times(3)).doFilter(request, response);
+        }
+    }
+
+    @Test
+    void otherRollerUiPathsStillGetASalt() throws Exception {
+        try (MockedStatic<RollerSession> mockedRollerSession = 
mockStatic(RollerSession.class);
+             MockedStatic<SaltCache> mockedSaltCache = 
mockStatic(SaltCache.class)) {
+            mockedRollerSession.when(() -> 
RollerSession.getRollerSession(request)).thenReturn(rollerSession);
+            mockedSaltCache.when(SaltCache::getInstance).thenReturn(saltCache);
+            when(rollerSession.getAuthenticatedUser()).thenReturn(new 
TestUser("userId"));
+            // A path that only starts with the same letters is not a static 
file path.
+            
when(request.getServletPath()).thenReturn("/roller-ui/styles-settings.rol");
+
+            filter.doFilter(request, response, chain);
+
+            verify(request).getSession(true);
+            verify(request).setAttribute(eq("salt"), anyString());
+        }
+    }
+
     private static class TestUser extends User {
         private final String id;
 

Reply via email to