mraible commented on code in PR #167:
URL: https://github.com/apache/roller/pull/167#discussion_r3891439006


##########
app/src/main/java/org/apache/roller/weblogger/ui/struts2/util/ValidateSaltInterceptor.java:
##########
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.roller.weblogger.ui.struts2.util;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.roller.weblogger.ui.core.filters.SaltValidator;
+import org.apache.struts2.StrutsStatics;
+
+import com.opensymphony.xwork2.ActionContext;
+import com.opensymphony.xwork2.ActionInvocation;
+import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
+
+/**
+ * Validates salts after Struts has parsed a multipart form request.
+ */
+public class ValidateSaltInterceptor extends AbstractInterceptor implements 
StrutsStatics {
+
+    private static final long serialVersionUID = 2446434402795510394L;
+    private static final Log log = 
LogFactory.getLog(ValidateSaltInterceptor.class);
+
+    @Override
+    public String intercept(ActionInvocation invocation) throws Exception {
+        ActionContext context = invocation.getInvocationContext();
+        HttpServletRequest request = (HttpServletRequest) 
context.get(HTTP_REQUEST);
+
+        if (SaltValidator.isMultipartFormPost(request)

Review Comment:
   This runs again on every chained invocation of the same request. 
`bookmarksImport!save` is multipart and has `<result name="success" 
type="chain">bookmarks</result>`, so the second pass finds the salt already 
removed from `SaltCache` and throws `Security Violation` after the OPML import 
has been flushed. Simplest fix: after a successful `consumeSubmittedSalt`, set 
a request attribute (e.g. `request.setAttribute("salt.validated", 
Boolean.TRUE)`) and skip validation when it's present. Good candidate for a 
`ValidateSaltInterceptorTest` case.
   
   Related: when Struts can't parse the multipart body (over 
`struts.multipart.maxSize`), `MultiPartRequestWrapper` has no fields, 
`getParameter("salt")` is `null` and this throws a 500 instead of letting the 
`fileUpload` interceptor's size error reach the form as it does today. Checking 
`((MultiPartRequestWrapper) request).hasErrors()` first would keep that UX.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to