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

snoopdave pushed a commit to branch roller-6.1.x
in repository https://gitbox.apache.org/repos/asf/roller.git


The following commit(s) were added to refs/heads/roller-6.1.x by this push:
     new c7a12d0b0 Send weblog update pings without an XML-RPC client (#236)
c7a12d0b0 is described below

commit c7a12d0b013bee8b9655759aae5b53b31c453c1a
Author: David M. Johnson <[email protected]>
AuthorDate: Sat Nov 7 15:17:22 2026 -0500

    Send weblog update pings without an XML-RPC client (#236)
    
    * Send weblog update pings without an XML-RPC client
    
    Roller now builds the weblogUpdates.ping request and reads the response
    itself, parsing it with the project's hardened XML parser (SecureXmlParsers)
    and reading only the flerror and message fields the protocol defines. Adds
    connection and read timeouts and a 1 MiB cap on the response. Removes the
    now-unused xmlrpc-client dependency; xmlrpc-common/server remain for the
    inbound XML-RPC servlet. Adds WeblogUpdatePingerTest.
    
    * Treat non-2xx ping responses and non-HTTP targets as failures
    
    A non-2xx HTTP status from a ping target is now surfaced as an IOException
    instead of being read and parsed as a (successful, empty) ping result, so a
    failing target is treated as failed and retried, as the previous client did.
    A ping target URL that is not HTTP(S) now yields an IOException instead of 
an
    uncaught ClassCastException. Adds tests for both via a loopback HTTP server;
    makes exchange() package-private for the tests.
    
    * Load the Pings action's ping target only by id
    
    The ping target that Ping Now, enable and disable work on now always
    comes from the stored ping targets. Add a test that binds request
    parameters through Struts.
    
    * Load editor action targets only by id, never from request parameters
    
    The editor and ping-target actions load the domain object they work on
    (ping target, category, entry, media directory, template, folder) from
    the weblog, by id, in myPrepare. Make those setters non-public and clear
    the field before the lookup, so a request parameter cannot supply a
    different object.
    
    Also set the authenticated user and the action weblog in
    UIActionInterceptor unconditionally, so a value bound from a request
    parameter is always overwritten from the session and the weblog handle.
    
    Add binding tests for the action targets and for the interceptor.
    
    * Let same-package tests set the entry on EntryRemove
---
 CHANGES.md                                         |   6 +
 app/pom.xml                                        |   6 -
 .../business/pings/WeblogUpdatePinger.java         | 284 +++++++++++++++++++--
 .../weblogger/ui/struts2/admin/PingTargets.java    |   5 +-
 .../weblogger/ui/struts2/editor/Bookmarks.java     |   2 +-
 .../ui/struts2/editor/CategoryRemove.java          |   4 +-
 .../weblogger/ui/struts2/editor/EntryEdit.java     |   3 +-
 .../weblogger/ui/struts2/editor/EntryRemove.java   |   6 +-
 .../weblogger/ui/struts2/editor/MediaFileAdd.java  |   4 +-
 .../weblogger/ui/struts2/editor/MediaFileEdit.java |   5 +-
 .../ui/struts2/editor/MediaFileImageChooser.java   |   4 +-
 .../weblogger/ui/struts2/editor/MediaFileView.java |   5 +-
 .../roller/weblogger/ui/struts2/editor/Pings.java  |   5 +-
 .../ui/struts2/editor/StylesheetEdit.java          |   2 +-
 .../weblogger/ui/struts2/editor/TemplateEdit.java  |   2 +-
 .../ui/struts2/util/UIActionInterceptor.java       |  17 +-
 .../business/pings/WeblogUpdatePingerTest.java     | 224 ++++++++++++++++
 .../editor/EditorActionTargetBindingTest.java      | 117 +++++++++
 .../ui/struts2/editor/PingsTargetBindingTest.java  | 107 ++++++++
 .../ui/struts2/util/UIActionInterceptorTest.java   |  78 ++++++
 20 files changed, 832 insertions(+), 54 deletions(-)

diff --git a/CHANGES.md b/CHANGES.md
index 17fe9ab67..ae054e20d 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -25,6 +25,12 @@
     
 ### Behaviour changes worth reading before upgrading
 
+- **Weblog update pings no longer use the XML-RPC client library.** Roller
+  builds the `weblogUpdates.ping` request and reads the response itself, with a
+  connection timeout, a read timeout and a 1 MB cap on the response, and reads
+  only the `flerror` and `message` fields the protocol defines. Ping behaviour
+  is otherwise unchanged.
+
 - **AtomPub honours `webservices.enableAtomPub` on every request.** While the
   setting is off, every AtomPub URL answers 404, not only the service document.
 - **AtomPub entry bodies default to a 1 MiB limit.** A larger entry is refused
diff --git a/app/pom.xml b/app/pom.xml
index 59e10851b..cb54682e5 100644
--- a/app/pom.xml
+++ b/app/pom.xml
@@ -388,12 +388,6 @@ limitations under the License.
             <version>${xmlrpc-version}</version>
         </dependency>
 
-        <dependency>
-            <groupId>org.apache.xmlrpc</groupId>
-            <artifactId>xmlrpc-client</artifactId>
-            <version>${xmlrpc-version}</version>
-        </dependency>
-
         <dependency>
             <groupId>org.apache.xmlrpc</groupId>
             <artifactId>xmlrpc-server</artifactId>
diff --git 
a/app/src/main/java/org/apache/roller/weblogger/business/pings/WeblogUpdatePinger.java
 
b/app/src/main/java/org/apache/roller/weblogger/business/pings/WeblogUpdatePinger.java
index 49d0e22f9..98919792a 100644
--- 
a/app/src/main/java/org/apache/roller/weblogger/business/pings/WeblogUpdatePinger.java
+++ 
b/app/src/main/java/org/apache/roller/weblogger/business/pings/WeblogUpdatePinger.java
@@ -23,15 +23,27 @@ import org.apache.commons.logging.LogFactory;
 import org.apache.roller.weblogger.config.PingConfig;
 import org.apache.roller.weblogger.pojos.PingTarget;
 import org.apache.roller.weblogger.pojos.Weblog;
+import org.apache.roller.weblogger.util.SecureXmlParsers;
 import org.apache.xmlrpc.XmlRpcException;
-import org.apache.xmlrpc.client.XmlRpcClient;
-import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
+import org.xml.sax.Attributes;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
 
+import javax.xml.parsers.SAXParser;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.net.URLConnection;
 import java.net.UnknownHostException;
+import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -39,11 +51,16 @@ import java.util.Set;
 /**
  * Utility for sending a weblog update ping.
  *
- * This implements the <code>WeblogUpdates.ping<code> XML-RPC call described at
- * <a href="http://www.xmlrpc.com/weblogsCom";>www.xmlrpc.com</a>
- * as well as some variants required to interoperate with certain
- * buggy but popular ping targets.
+ * <p>This implements the <code>weblogUpdates.ping</code> XML-RPC call 
described
+ * at <a href="http://www.xmlrpc.com/weblogsCom";>www.xmlrpc.com</a>, as well as
+ * some variants required to interoperate with certain buggy but popular ping
+ * targets.
  *
+ * <p>Roller builds the request and reads the response itself rather than 
through
+ * an XML-RPC client library. The response is parsed with {@link 
SecureXmlParsers},
+ * which refuses document type declarations and resolves nothing the document
+ * names, and only the <code>flerror</code> and <code>message</code> fields the
+ * protocol defines are read; any other content is ignored.
  *
  * @author <a href="mailto:[email protected]";>Anil Gangolli</a>
  * @author llavandowska (for code refactored from the now-defunct 
<code>RollerXmlRpcClient</code>)
@@ -51,6 +68,17 @@ import java.util.Set;
 public final class WeblogUpdatePinger {
     public static final Log LOGGER = 
LogFactory.getLog(WeblogUpdatePinger.class);
 
+    private static final String PING_METHOD_NAME = "weblogUpdates.ping";
+
+    /** How long to wait to open a connection to a ping target, in 
milliseconds. */
+    private static final int CONNECT_TIMEOUT_MS = 15000;
+
+    /** How long to wait for a ping target's response, in milliseconds. */
+    private static final int READ_TIMEOUT_MS = 30000;
+
+    /** Upper bound on the response we will read from a ping target, in bytes. 
*/
+    private static final int MAX_RESPONSE_BYTES = 1024 * 1024;
+
     /**
      * Conveys a ping result.
      */
@@ -96,7 +124,7 @@ public final class WeblogUpdatePinger {
      * @param website            the website that changed (from which the ping 
originates)
      * @return the result message string sent by the server.
      * @throws IOException if an IOException occurs during the ping
-     * @throws XmlRpcException if the XML RPC client throws one
+     * @throws XmlRpcException if the ping target reports a fault
      */
     public static PingResult sendPing(PingTarget pingTarget, Weblog website) 
throws IOException, XmlRpcException {
         String websiteUrl = website.getAbsoluteURL();
@@ -114,12 +142,9 @@ public final class WeblogUpdatePinger {
             LOGGER.debug("Executing ping to '" + pingTargetUrl + "' for 
website '" + websiteUrl + "' (" + website.getName() + ")" + 
(variantOptions.isEmpty() ? "" : " with variant options " + variantOptions));
         }
 
-        // Send the ping.
-        XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
-        config.setServerURL(new URL(pingTargetUrl));
-        XmlRpcClient client = new XmlRpcClient();
-        client.setConfig(config);
-        PingResult pingResult = 
parseResult(client.execute("weblogUpdates.ping", params.toArray()));
+        // Send the ping and read the response.
+        byte[] response = exchange(pingTargetUrl, buildRequest(params));
+        PingResult pingResult = parseResponse(response);
 
         if (LOGGER.isDebugEnabled()) {
             LOGGER.debug("Ping result is: " + pingResult);
@@ -127,29 +152,236 @@ public final class WeblogUpdatePinger {
         return pingResult;
     }
 
-    private static PingResult parseResult(Object obj) {
-        // Deal with the fact that some buggy ping targets may not respond 
with the proper struct type.
-        if (obj == null) {
-            return new PingResult(null,null);
+    /**
+     * Build the XML-RPC <code>weblogUpdates.ping</code> request body for the
+     * given string parameters.
+     */
+    static String buildRequest(List<String> params) {
+        StringBuilder sb = new StringBuilder(256);
+        sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
+        
sb.append("<methodCall><methodName>").append(PING_METHOD_NAME).append("</methodName>");
+        sb.append("<params>");
+        for (String param : params) {
+            sb.append("<param><value><string>");
+            xmlEscape(sb, param);
+            sb.append("</string></value></param>");
+        }
+        sb.append("</params></methodCall>");
+        return sb.toString();
+    }
+
+    /**
+     * POST the request body to the ping target and return the response bytes,
+     * capped at {@link #MAX_RESPONSE_BYTES}.
+     */
+    static byte[] exchange(String pingTargetUrl, String requestBody) throws 
IOException {
+        URL url = new URL(pingTargetUrl);
+        URLConnection connection = url.openConnection();
+        if (!(connection instanceof HttpURLConnection)) {
+            // Ping targets are HTTP(S) XML-RPC endpoints. Refuse anything else
+            // (for example file: or ftp:) with an IOException rather than 
failing
+            // with a ClassCastException that callers do not handle.
+            throw new IOException("Ping target URL is not an HTTP URL: " + 
pingTargetUrl);
         }
+        HttpURLConnection conn = (HttpURLConnection) connection;
         try {
-            // normal case: response is a struct (represented as a Map) with 
Boolean flerror and String fields.
-            Map<?, ?> result = (Map<?, ?>) obj;
-            return new PingResult((Boolean) result.get("flerror"), (String) 
result.get("message"));
-        } catch (Exception ex) {
-            // exception case:  The caller responded with an unexpected type, 
though parsed at the basic XML RPC level.
-            // This effectively assumes flerror = false, and sets message = 
obj.toString();
+            conn.setRequestMethod("POST");
+            conn.setConnectTimeout(CONNECT_TIMEOUT_MS);
+            conn.setReadTimeout(READ_TIMEOUT_MS);
+            conn.setDoOutput(true);
+            conn.setRequestProperty("Content-Type", "text/xml; charset=UTF-8");
+            conn.setRequestProperty("User-Agent", "Apache Roller");
+
+            byte[] body = requestBody.getBytes(StandardCharsets.UTF_8);
+            conn.setFixedLengthStreamingMode(body.length);
+            try (OutputStream out = conn.getOutputStream()) {
+                out.write(body);
+            }
+
+            int status = conn.getResponseCode();
+            if (status < 200 || status >= 300) {
+                // A non-2xx status is a transport-level failure, not a ping
+                // result. Surface it so the ping is treated as failed (and
+                // retried by the queue processor), as the old client did.
+                throw new IOException("Ping target returned HTTP status " + 
status);
+            }
+            return readCapped(conn.getInputStream());
+        } finally {
+            conn.disconnect();
+        }
+    }
+
+    /** Read at most {@link #MAX_RESPONSE_BYTES} bytes from the stream. */
+    private static byte[] readCapped(InputStream in) throws IOException {
+        if (in == null) {
+            return new byte[0];
+        }
+        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+        byte[] chunk = new byte[8192];
+        int total = 0;
+        int read;
+        while ((read = in.read(chunk)) != -1) {
+            total += read;
+            if (total > MAX_RESPONSE_BYTES) {
+                throw new IOException("Ping target response exceeded " + 
MAX_RESPONSE_BYTES + " bytes");
+            }
+            buffer.write(chunk, 0, read);
+        }
+        return buffer.toByteArray();
+    }
+
+    /**
+     * Parse an XML-RPC ping response. Only <code>flerror</code> and
+     * <code>message</code> are read from a normal response; a fault is turned
+     * into an {@link XmlRpcException}.
+     *
+     * @throws XmlRpcException if the response is a fault
+     */
+    static PingResult parseResponse(byte[] response) throws IOException, 
XmlRpcException {
+        if (response == null || response.length == 0) {
+            return new PingResult(null, null);
+        }
+        PingResponseHandler handler = new PingResponseHandler();
+        try {
+            SAXParser parser = 
SecureXmlParsers.newSAXParserFactory().newSAXParser();
+            parser.parse(new InputSource(new ByteArrayInputStream(response)), 
handler);
+        } catch (SAXException | javax.xml.parsers.ParserConfigurationException 
ex) {
+            // The target responded with something that is not a well-formed, 
safe
+            // XML-RPC response. Treat it as a non-error transmission, 
mirroring the
+            // prior lenient handling of buggy targets, without exposing the 
body.
             if (LOGGER.isDebugEnabled()) {
-                LOGGER.debug("Invalid ping result of type: " + 
obj.getClass().getName() + "; proceeding with stand-in representative.");
+                LOGGER.debug("Could not parse ping response as XML-RPC; 
proceeding.", ex);
+            }
+            return new PingResult(null, null);
+        }
+
+        if (handler.isFault()) {
+            throw new XmlRpcException(handler.getFaultCode(), 
handler.getFaultString());
+        }
+        return new PingResult(handler.getFlerror(), handler.getMessage());
+    }
+
+    private static void xmlEscape(StringBuilder sb, String value) {
+        if (value == null) {
+            return;
+        }
+        for (int i = 0; i < value.length(); i++) {
+            char c = value.charAt(i);
+            switch (c) {
+                case '&': sb.append("&amp;"); break;
+                case '<': sb.append("&lt;"); break;
+                case '>': sb.append("&gt;"); break;
+                case '"': sb.append("&quot;"); break;
+                case '\'': sb.append("&apos;"); break;
+                default: sb.append(c);
+            }
+        }
+    }
+
+    /**
+     * Collects just the fields Roller needs from an XML-RPC ping response.
+     * Scalar values, including any {@code <base64>}, are read only as text.
+     */
+    private static final class PingResponseHandler extends DefaultHandler {
+        private final StringBuilder text = new StringBuilder();
+        private final Map<String, String> members = new HashMap<>();
+        private boolean inFault;
+        private boolean inStruct;
+        private String memberName;
+        private String scalar;
+
+        @Override
+        public void startElement(String uri, String localName, String qName, 
Attributes attributes) {
+            text.setLength(0);
+            if ("fault".equals(qName)) {
+                inFault = true;
+            } else if ("struct".equals(qName)) {
+                inStruct = true;
+            } else if ("member".equals(qName)) {
+                memberName = null;
+                scalar = null;
             }
-            return new PingResult(null,obj.toString());
+        }
+
+        @Override
+        public void characters(char[] ch, int start, int length) {
+            text.append(ch, start, length);
+        }
+
+        @Override
+        public void endElement(String uri, String localName, String qName) {
+            switch (qName) {
+                case "name":
+                    memberName = text.toString().trim();
+                    break;
+                case "string":
+                case "boolean":
+                case "int":
+                case "i4":
+                case "double":
+                case "dateTime.iso8601":
+                case "base64":
+                    // Record the raw text only; base64 is not decoded.
+                    scalar = text.toString();
+                    break;
+                case "value":
+                    if (scalar == null) {
+                        // An XML-RPC <value> with no type child is a string.
+                        scalar = text.toString();
+                    }
+                    break;
+                case "member":
+                    if (memberName != null && inStruct) {
+                        members.put(memberName, scalar != null ? scalar : "");
+                    }
+                    scalar = null;
+                    break;
+                case "struct":
+                    inStruct = false;
+                    break;
+                default:
+                    break;
+            }
+        }
+
+        boolean isFault() {
+            return inFault;
+        }
+
+        int getFaultCode() {
+            String code = members.get("faultCode");
+            if (code != null) {
+                try {
+                    return Integer.parseInt(code.trim());
+                } catch (NumberFormatException ignored) {
+                    // fall through to default
+                }
+            }
+            return 0;
+        }
+
+        String getFaultString() {
+            return members.get("faultString");
+        }
+
+        Boolean getFlerror() {
+            String value = members.get("flerror");
+            if (value == null) {
+                return null;
+            }
+            value = value.trim();
+            return "1".equals(value) || "true".equalsIgnoreCase(value);
+        }
+
+        String getMessage() {
+            return members.get("message");
         }
     }
 
     /**
      * Decide if the given exception appears to warrant later retrial attempts.
      *
-     * @param ex an exception thrown by the <coce>sendPing</code> operation
+     * @param ex an exception thrown by the <code>sendPing</code> operation
      * @return true if the error warrants retrial
      */
     public static boolean shouldRetry(Exception ex) {
diff --git 
a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/admin/PingTargets.java
 
b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/admin/PingTargets.java
index ff36eb3b7..363e7c549 100644
--- 
a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/admin/PingTargets.java
+++ 
b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/admin/PingTargets.java
@@ -77,6 +77,9 @@ public class PingTargets extends UIAction {
         // load list of ping targets
         loadPingTargets();
 
+        // The ping target always comes from the stored targets, by id.
+        pingTarget = null;
+
         // load specified ping target if possible
         if(!StringUtils.isEmpty(getPingTargetId())) {
             try {
@@ -195,7 +198,7 @@ public class PingTargets extends UIAction {
         return pingTarget;
     }
 
-    public void setPingTarget(PingTarget pingTarget) {
+    private void setPingTarget(PingTarget pingTarget) {
         this.pingTarget = pingTarget;
     }
 
diff --git 
a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/Bookmarks.java
 
b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/Bookmarks.java
index df499162e..d1ef2399f 100644
--- 
a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/Bookmarks.java
+++ 
b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/Bookmarks.java
@@ -301,7 +301,7 @@ public class Bookmarks extends UIAction {
         return folder;
     }
 
-    public void setFolder(WeblogBookmarkFolder folder) {
+    private void setFolder(WeblogBookmarkFolder folder) {
         this.folder = folder;
         if ( folder != null ) {
             this.folderId = folder.getId();
diff --git 
a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/CategoryRemove.java
 
b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/CategoryRemove.java
index 0dbd8dc68..ad3cb711f 100644
--- 
a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/CategoryRemove.java
+++ 
b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/CategoryRemove.java
@@ -72,6 +72,8 @@ public class CategoryRemove extends UIAction {
     public void myPrepare() {
         try {
             WeblogEntryManager wmgr = 
WebloggerFactory.getWeblogger().getWeblogEntryManager();
+            // The category always comes from the weblog, by id.
+            category = null;
             if(!StringUtils.isEmpty(getRemoveId())) {
                 setCategory(wmgr.getWeblogCategory(getActionWeblog(), 
getRemoveId()));
             }
@@ -159,7 +161,7 @@ public class CategoryRemove extends UIAction {
         return category;
     }
 
-    public void setCategory(WeblogCategory category) {
+    private void setCategory(WeblogCategory category) {
         this.category = category;
     }
 
diff --git 
a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/EntryEdit.java
 
b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/EntryEdit.java
index 1c9ece2e8..57b1a7f51 100644
--- 
a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/EntryEdit.java
+++ 
b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/EntryEdit.java
@@ -625,7 +625,8 @@ public final class EntryEdit extends UIAction {
         return entry;
     }
 
-    public void setEntry(WeblogEntry entry) {
+    // package-private: set by the action only, never bound from a request
+    void setEntry(WeblogEntry entry) {
         this.entry = entry;
     }
 
diff --git 
a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/EntryRemove.java
 
b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/EntryRemove.java
index 85471e030..80bf288bf 100644
--- 
a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/EntryRemove.java
+++ 
b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/EntryRemove.java
@@ -55,7 +55,8 @@ public class EntryRemove extends UIAction {
 
     @Override
     public void myPrepare() {
-        setRemoveEntry(null);
+        // The entry always comes from the weblog, by id.
+        removeEntry = null;
         if (getRemoveId() != null) {
             try {
                 WeblogEntryManager wmgr = WebloggerFactory.getWeblogger()
@@ -143,7 +144,8 @@ public class EntryRemove extends UIAction {
         return removeEntry;
     }
 
-    public void setRemoveEntry(WeblogEntry removeEntry) {
+    // package-private: set by the action only, never bound from a request
+    void setRemoveEntry(WeblogEntry removeEntry) {
         this.removeEntry = removeEntry;
     }
 
diff --git 
a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileAdd.java
 
b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileAdd.java
index 9c9fdfcf0..f0aeee6ed 100644
--- 
a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileAdd.java
+++ 
b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileAdd.java
@@ -82,6 +82,8 @@ public class MediaFileAdd extends MediaFileBase {
         try {
             MediaFileManager mgr = WebloggerFactory.getWeblogger()
                     .getMediaFileManager();
+            // The directory always comes from the weblog, by id or name.
+            directory = null;
             if (!StringUtils.isEmpty(bean.getDirectoryId())) {
                 setDirectory(mgr.getMediaFileDirectory(getActionWeblog(), 
bean.getDirectoryId()));
 
@@ -260,7 +262,7 @@ public class MediaFileAdd extends MediaFileBase {
         return directory;
     }
 
-    public void setDirectory(MediaFileDirectory directory) {
+    private void setDirectory(MediaFileDirectory directory) {
         this.directory = directory;
     }
 
diff --git 
a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileEdit.java
 
b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileEdit.java
index 789ba2a6d..76afc4ceb 100644
--- 
a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileEdit.java
+++ 
b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileEdit.java
@@ -69,6 +69,8 @@ public class MediaFileEdit extends MediaFileBase {
         refreshAllDirectories();
         try {
             MediaFileManager mgr = 
WebloggerFactory.getWeblogger().getMediaFileManager();
+            // The directory always comes from the weblog, by id.
+            directory = null;
             if (!StringUtils.isEmpty(bean.getDirectoryId())) {
                 setDirectory(mgr.getMediaFileDirectory(getActionWeblog(), 
bean.getDirectoryId()));
             }
@@ -187,7 +189,8 @@ public class MediaFileEdit extends MediaFileBase {
         return directory;
     }
 
-    public void setDirectory(MediaFileDirectory directory) {
+    // package-private: set by the action only, never bound from a request
+    void setDirectory(MediaFileDirectory directory) {
         this.directory = directory;
     }
 
diff --git 
a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileImageChooser.java
 
b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileImageChooser.java
index c16f0a78e..a80e01b50 100644
--- 
a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileImageChooser.java
+++ 
b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileImageChooser.java
@@ -62,6 +62,8 @@ public class MediaFileImageChooser extends MediaFileBase {
     @Override
     public void myPrepare() {
         refreshAllDirectories();
+        // The current directory is set from the weblog, by id.
+        currentDirectory = null;
     }
 
     @Override
@@ -196,7 +198,7 @@ public class MediaFileImageChooser extends MediaFileBase {
      * @param currentDirectory
      *            the currentDirectory to set
      */
-    public void setCurrentDirectory(MediaFileDirectory currentDirectory) {
+    private void setCurrentDirectory(MediaFileDirectory currentDirectory) {
         this.currentDirectory = currentDirectory;
     }
 
diff --git 
a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileView.java
 
b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileView.java
index 32b83dc34..7f3dfc212 100644
--- 
a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileView.java
+++ 
b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/MediaFileView.java
@@ -125,6 +125,9 @@ public class MediaFileView extends MediaFileBase {
         }
 
         refreshAllDirectories();
+
+        // The current directory is set by view(), from the weblog, by id.
+        currentDirectory = null;
     }
 
     /**
@@ -400,7 +403,7 @@ public class MediaFileView extends MediaFileBase {
         return currentDirectory;
     }
 
-    public void setCurrentDirectory(MediaFileDirectory currentDirectory) {
+    private void setCurrentDirectory(MediaFileDirectory currentDirectory) {
         this.currentDirectory = currentDirectory;
     }
 
diff --git 
a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/Pings.java 
b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/Pings.java
index f2c07e16a..d6ea88678 100644
--- a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/Pings.java
+++ b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/Pings.java
@@ -80,6 +80,9 @@ public class Pings extends UIAction {
         
         PingTargetManager pingTargetMgr = 
WebloggerFactory.getWeblogger().getPingTargetManager();
         
+        // The ping target always comes from the stored ping targets, by id.
+        pingTarget = null;
+        
         // load selected ping target, if possible
         if(getPingTargetId() != null) {
             try {
@@ -250,7 +253,7 @@ public class Pings extends UIAction {
         return pingTarget;
     }
 
-    public void setPingTarget(PingTarget pingTarget) {
+    private void setPingTarget(PingTarget pingTarget) {
         this.pingTarget = pingTarget;
     }
 
diff --git 
a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/StylesheetEdit.java
 
b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/StylesheetEdit.java
index cb50e00bd..049d28a58 100644
--- 
a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/StylesheetEdit.java
+++ 
b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/StylesheetEdit.java
@@ -366,7 +366,7 @@ public class StylesheetEdit extends UIAction {
      * Sets the template.
      * @param template the new template
      */
-    public void setTemplate(WeblogTemplate template) {
+    private void setTemplate(WeblogTemplate template) {
         this.template = template;
     }
 
diff --git 
a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/TemplateEdit.java
 
b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/TemplateEdit.java
index a1f95cebb..fea372e0d 100644
--- 
a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/TemplateEdit.java
+++ 
b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/TemplateEdit.java
@@ -196,7 +196,7 @@ public class TemplateEdit extends UIAction {
         return template;
     }
 
-    public void setTemplate(WeblogTemplate template) {
+    private void setTemplate(WeblogTemplate template) {
         this.template = template;
     }
 }
\ No newline at end of file
diff --git 
a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/util/UIActionInterceptor.java
 
b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/util/UIActionInterceptor.java
index 08b65f4bb..9eb500957 100644
--- 
a/app/src/main/java/org/apache/roller/weblogger/ui/struts2/util/UIActionInterceptor.java
+++ 
b/app/src/main/java/org/apache/roller/weblogger/ui/struts2/util/UIActionInterceptor.java
@@ -63,27 +63,26 @@ public class UIActionInterceptor extends 
MethodFilterInterceptor implements
 
             UIAction theAction = (UIAction) action;
 
-            // extract the authenticated user and set it
+            // Set the authenticated user from the session. Always overwrite,
+            // so a value bound from request parameters cannot survive.
             RollerSession rses = RollerSession.getRollerSession(request);
-            if (rses != null) {
-                theAction.setAuthenticatedUser(rses.getAuthenticatedUser());
-            }
+            theAction.setAuthenticatedUser(rses != null ? 
rses.getAuthenticatedUser() : null);
 
-            // extract the work weblog and set it
+            // Set the action weblog by looking up the weblog handle. Always
+            // overwrite (to null when no weblog resolves), so a value bound
+            // from request parameters cannot survive.
+            Weblog weblog = null;
             String weblogHandle = theAction.getWeblog();
             if (!StringUtils.isEmpty(weblogHandle)) {
-                Weblog weblog = null;
                 try {
                     weblog = WebloggerFactory.getWeblogger().getWeblogManager()
                             .getWeblogByHandle(weblogHandle);
-                    if (weblog != null) {
-                        theAction.setActionWeblog(weblog);
-                    }
                 } catch (Exception e) {
                     log.error("Error looking up action weblog - "
                             + weblogHandle, e);
                 }
             }
+            theAction.setActionWeblog(weblog);
         }
 
         return invocation.invoke();
diff --git 
a/app/src/test/java/org/apache/roller/weblogger/business/pings/WeblogUpdatePingerTest.java
 
b/app/src/test/java/org/apache/roller/weblogger/business/pings/WeblogUpdatePingerTest.java
new file mode 100644
index 000000000..1f037e786
--- /dev/null
+++ 
b/app/src/test/java/org/apache/roller/weblogger/business/pings/WeblogUpdatePingerTest.java
@@ -0,0 +1,224 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  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.business.pings;
+
+import com.sun.net.httpserver.HttpServer;
+import 
org.apache.roller.weblogger.business.pings.WeblogUpdatePinger.PingResult;
+import org.apache.xmlrpc.XmlRpcException;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
+import java.io.Serializable;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.Base64;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Tests for {@link WeblogUpdatePinger}, covering how it builds the
+ * {@code weblogUpdates.ping} request and reads the response.
+ *
+ * <p>The response reader extracts only the {@code flerror} and {@code message}
+ * fields the protocol defines, reads every scalar as text, ignores response
+ * content it does not use, and refuses document type declarations.
+ */
+public class WeblogUpdatePingerTest {
+
+    /** Set true if {@link Probe} is ever reconstructed from bytes. */
+    private static volatile boolean probeReconstructed;
+
+    @BeforeEach
+    public void reset() {
+        probeReconstructed = false;
+    }
+
+    /** A serializable object whose reconstruction from bytes is observable. */
+    static final class Probe implements Serializable {
+        private static final long serialVersionUID = 1L;
+
+        private void readObject(ObjectInputStream in) throws 
java.io.IOException, ClassNotFoundException {
+            in.defaultReadObject();
+            probeReconstructed = true;
+        }
+    }
+
+    private static byte[] serialize(Serializable object) throws Exception {
+        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
+        try (ObjectOutputStream out = new ObjectOutputStream(bytes)) {
+            out.writeObject(object);
+        }
+        return bytes.toByteArray();
+    }
+
+    @Test
+    public void readsFlerrorAndMessageFromNormalResponse() throws Exception {
+        String response = "<?xml version=\"1.0\"?>"
+                + "<methodResponse><params><param><value><struct>"
+                + 
"<member><name>flerror</name><value><boolean>0</boolean></value></member>"
+                + "<member><name>message</name><value><string>Thanks for the 
ping.</string></value></member>"
+                + "</struct></value></param></params></methodResponse>";
+
+        PingResult result = 
WeblogUpdatePinger.parseResponse(response.getBytes(StandardCharsets.UTF_8));
+        assertFalse(result.isError());
+        assertEquals("Thanks for the ping.", result.getMessage());
+    }
+
+    @Test
+    public void readsErrorFlagFromResponse() throws Exception {
+        String response = "<?xml version=\"1.0\"?>"
+                + "<methodResponse><params><param><value><struct>"
+                + 
"<member><name>flerror</name><value><boolean>1</boolean></value></member>"
+                + "<member><name>message</name><value><string>Unknown 
blog.</string></value></member>"
+                + "</struct></value></param></params></methodResponse>";
+
+        PingResult result = 
WeblogUpdatePinger.parseResponse(response.getBytes(StandardCharsets.UTF_8));
+        assertTrue(result.isError());
+        assertEquals("Unknown blog.", result.getMessage());
+    }
+
+    @Test
+    public void faultResponseBecomesException() throws Exception {
+        String response = "<?xml version=\"1.0\"?>"
+                + "<methodResponse><fault><value><struct>"
+                + 
"<member><name>faultCode</name><value><int>4</int></value></member>"
+                + 
"<member><name>faultString</name><value><string>boom</string></value></member>"
+                + "</struct></value></fault></methodResponse>";
+
+        XmlRpcException thrown = assertThrows(XmlRpcException.class,
+                () -> 
WeblogUpdatePinger.parseResponse(response.getBytes(StandardCharsets.UTF_8)));
+        assertEquals(4, thrown.code);
+        assertEquals("boom", thrown.getMessage());
+    }
+
+    @Test
+    public void controlProbeIsReconstructedByAnObjectStream() throws Exception 
{
+        // Control: reading the probe through an ObjectInputStream 
reconstructs it.
+        byte[] serialized = serialize(new Probe());
+        try (ObjectInputStream in = new ObjectInputStream(new 
ByteArrayInputStream(serialized))) {
+            in.readObject();
+        }
+        assertTrue(probeReconstructed);
+    }
+
+    @Test
+    public void base64ResponseMemberIsReadAsTextOnly() throws Exception {
+        // A base64 member is read as text; the reader does not turn it into 
an object.
+        String embedded = Base64.getEncoder().encodeToString(serialize(new 
Probe()));
+        String response = "<?xml version=\"1.0\"?>"
+                + "<methodResponse><fault><value><struct>"
+                + 
"<member><name>faultCode</name><value><int>4</int></value></member>"
+                + 
"<member><name>faultString</name><value><string>boom</string></value></member>"
+                + "<member><name>payload</name><value><base64>" + embedded + 
"</base64></value></member>"
+                + "</struct></value></fault></methodResponse>";
+
+        assertThrows(XmlRpcException.class,
+                () -> 
WeblogUpdatePinger.parseResponse(response.getBytes(StandardCharsets.UTF_8)));
+        assertFalse(probeReconstructed, "a base64 response member must be read 
as text, not reconstructed");
+    }
+
+    @Test
+    public void doctypeInResponseIsRefused() {
+        // A response that declares a DTD is refused, and nothing it names is 
resolved.
+        String response = "<?xml version=\"1.0\"?>"
+                + "<!DOCTYPE methodResponse [<!ENTITY x \"y\">]>"
+                + "<methodResponse><params><param><value><struct>"
+                + 
"<member><name>flerror</name><value><boolean>0</boolean></value></member>"
+                + 
"<member><name>message</name><value><string>&x;</string></value></member>"
+                + "</struct></value></param></params></methodResponse>";
+
+        PingResult result = parse(response);
+        assertFalse(result.isError());
+    }
+
+    @Test
+    public void buildsWellFormedEscapedRequest() {
+        String request = WeblogUpdatePinger.buildRequest(Arrays.asList("A & B 
<blog>", "http://example.test/";));
+        
assertTrue(request.contains("<methodName>weblogUpdates.ping</methodName>"));
+        assertTrue(request.contains("A &amp; B &lt;blog&gt;"), "parameters 
must be XML-escaped");
+        assertTrue(request.contains("<string>http://example.test/</string>"));
+        assertFalse(request.contains("<blog>"), "raw markup must not leak into 
the request");
+    }
+
+    @Test
+    public void nonSuccessHttpStatusThrows() throws Exception {
+        // A non-2xx response is a transport failure, not a successful ping.
+        HttpServer server = startServer(500, "<html>error</html>");
+        try {
+            String url = "http://127.0.0.1:"; + server.getAddress().getPort() + 
"/";
+            assertThrows(IOException.class, () -> 
WeblogUpdatePinger.exchange(url, "<methodCall/>"));
+        } finally {
+            server.stop(0);
+        }
+    }
+
+    @Test
+    public void successHttpStatusReturnsBody() throws Exception {
+        String body = "<?xml version=\"1.0\"?><methodResponse><params><param>"
+                + 
"<value><string>ok</string></value></param></params></methodResponse>";
+        HttpServer server = startServer(200, body);
+        try {
+            String url = "http://127.0.0.1:"; + server.getAddress().getPort() + 
"/";
+            byte[] bytes = WeblogUpdatePinger.exchange(url, "<methodCall/>");
+            assertEquals(body, new String(bytes, StandardCharsets.UTF_8));
+        } finally {
+            server.stop(0);
+        }
+    }
+
+    @Test
+    public void nonHttpTargetThrowsIoException() {
+        // A file:/ftp: target must not escape as a ClassCastException.
+        assertThrows(IOException.class,
+                () -> WeblogUpdatePinger.exchange("file:///no/such/file", 
"<methodCall/>"));
+    }
+
+    private static HttpServer startServer(int status, String body) throws 
IOException {
+        HttpServer server = HttpServer.create(new 
InetSocketAddress(InetAddress.getLoopbackAddress(), 0), 0);
+        server.createContext("/", exchange -> {
+            exchange.getRequestBody().readAllBytes();
+            byte[] out = body.getBytes(StandardCharsets.UTF_8);
+            exchange.sendResponseHeaders(status, out.length);
+            try (OutputStream os = exchange.getResponseBody()) {
+                os.write(out);
+            }
+        });
+        server.start();
+        return server;
+    }
+
+    private static PingResult parse(String response) {
+        try {
+            return 
WeblogUpdatePinger.parseResponse(response.getBytes(StandardCharsets.UTF_8));
+        } catch (Exception ex) {
+            throw new AssertionError("parsing should not throw for this 
response", ex);
+        }
+    }
+}
diff --git 
a/app/src/test/java/org/apache/roller/weblogger/ui/struts2/editor/EditorActionTargetBindingTest.java
 
b/app/src/test/java/org/apache/roller/weblogger/ui/struts2/editor/EditorActionTargetBindingTest.java
new file mode 100644
index 000000000..bb58838f7
--- /dev/null
+++ 
b/app/src/test/java/org/apache/roller/weblogger/ui/struts2/editor/EditorActionTargetBindingTest.java
@@ -0,0 +1,117 @@
+/*
+ * 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.
+ */
+package org.apache.roller.weblogger.ui.struts2.editor;
+
+import java.util.function.Function;
+import java.util.function.Supplier;
+
+import com.opensymphony.xwork2.config.ConfigurationManager;
+import com.opensymphony.xwork2.config.providers.XWorkConfigurationProvider;
+import com.opensymphony.xwork2.inject.Container;
+import com.opensymphony.xwork2.util.ValueStack;
+import com.opensymphony.xwork2.util.ValueStackFactory;
+import com.opensymphony.xwork2.util.reflection.ReflectionContextState;
+import org.apache.roller.weblogger.ui.struts2.admin.PingTargets;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.DynamicTest;
+import org.junit.jupiter.api.TestFactory;
+import org.junit.jupiter.api.function.Executable;
+
+import java.util.Arrays;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+/**
+ * No editor or ping-target action lets a request parameter create the domain
+ * object it works on. Those objects are loaded only by the action, from the
+ * weblog, by id.
+ */
+class EditorActionTargetBindingTest {
+
+    private ValueStack stack;
+
+    @BeforeEach
+    void setUp() {
+        ConfigurationManager configurationManager = new 
ConfigurationManager("xwork");
+        configurationManager.addContainerProvider(new 
XWorkConfigurationProvider());
+        Container container = 
configurationManager.getConfiguration().getContainer();
+        stack = 
container.getInstance(ValueStackFactory.class).createValueStack();
+    }
+
+    private void tryBind(Object action, String name, String value) {
+        stack.push(action);
+        ReflectionContextState.setCreatingNullObjects(stack.getContext(), 
true);
+        ReflectionContextState.setDenyMethodExecution(stack.getContext(), 
true);
+        try {
+            stack.setParameter(name, value);
+        } catch (RuntimeException expectedForUnwritableProperty) {
+            // A non-bindable property may raise; that is the point.
+        } finally {
+            ReflectionContextState.setCreatingNullObjects(stack.getContext(), 
false);
+            stack.pop();
+        }
+    }
+
+    private static class Case {
+        final String label;
+        final Supplier<Object> make;
+        final String param;
+        final Function<Object, Object> read;
+        Case(String label, Supplier<Object> make, String param, 
Function<Object, Object> read) {
+            this.label = label; this.make = make; this.param = param; 
this.read = read;
+        }
+    }
+
+    private List<Case> cases() {
+        return Arrays.asList(
+            new Case("Pings.pingTarget", Pings::new, "pingTarget.pingUrl",
+                a -> ((Pings) a).getPingTarget()),
+            new Case("PingTargets.pingTarget", PingTargets::new, 
"pingTarget.pingUrl",
+                a -> ((PingTargets) a).getPingTarget()),
+            new Case("CategoryRemove.category", CategoryRemove::new, 
"category.name",
+                a -> ((CategoryRemove) a).getCategory()),
+            new Case("EntryRemove.removeEntry", EntryRemove::new, 
"removeEntry.anchor",
+                a -> ((EntryRemove) a).getRemoveEntry()),
+            new Case("EntryEdit.entry", EntryEdit::new, "entry.anchor",
+                a -> ((EntryEdit) a).getEntry()),
+            new Case("MediaFileEdit.directory", MediaFileEdit::new, 
"directory.name",
+                a -> ((MediaFileEdit) a).getDirectory()),
+            new Case("MediaFileAdd.directory", MediaFileAdd::new, 
"directory.name",
+                a -> ((MediaFileAdd) a).getDirectory()),
+            new Case("MediaFileView.currentDirectory", MediaFileView::new, 
"currentDirectory.name",
+                a -> ((MediaFileView) a).getCurrentDirectory()),
+            new Case("MediaFileImageChooser.currentDirectory", 
MediaFileImageChooser::new, "currentDirectory.name",
+                a -> ((MediaFileImageChooser) a).getCurrentDirectory()),
+            new Case("StylesheetEdit.template", StylesheetEdit::new, 
"template.name",
+                a -> ((StylesheetEdit) a).getTemplate()),
+            new Case("TemplateEdit.template", TemplateEdit::new, 
"template.name",
+                a -> ((TemplateEdit) a).getTemplate()),
+            new Case("Bookmarks.folder", Bookmarks::new, "folder.name",
+                a -> ((Bookmarks) a).getFolder())
+        );
+    }
+
+    @TestFactory
+    Iterable<DynamicTest> requestCannotCreateTheTargetObject() {
+        return cases().stream().map(c -> DynamicTest.dynamicTest(c.label, 
(Executable) () -> {
+            Object action = c.make.get();
+            tryBind(action, c.param, "http://attacker.example/";);
+            assertNull(c.read.apply(action), c.label + " must stay null after 
a bind attempt");
+        })).collect(java.util.stream.Collectors.toList());
+    }
+}
diff --git 
a/app/src/test/java/org/apache/roller/weblogger/ui/struts2/editor/PingsTargetBindingTest.java
 
b/app/src/test/java/org/apache/roller/weblogger/ui/struts2/editor/PingsTargetBindingTest.java
new file mode 100644
index 000000000..edfda4901
--- /dev/null
+++ 
b/app/src/test/java/org/apache/roller/weblogger/ui/struts2/editor/PingsTargetBindingTest.java
@@ -0,0 +1,107 @@
+/*
+ * 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.
+ */
+package org.apache.roller.weblogger.ui.struts2.editor;
+
+import java.util.Collections;
+
+import com.opensymphony.xwork2.config.ConfigurationManager;
+import com.opensymphony.xwork2.config.providers.XWorkConfigurationProvider;
+import com.opensymphony.xwork2.inject.Container;
+import com.opensymphony.xwork2.util.ValueStackFactory;
+import com.opensymphony.xwork2.util.ValueStack;
+import com.opensymphony.xwork2.util.reflection.ReflectionContextState;
+import org.apache.roller.weblogger.business.WebloggerFactory;
+import org.apache.roller.weblogger.business.Weblogger;
+import org.apache.roller.weblogger.business.pings.PingTargetManager;
+import org.apache.roller.weblogger.pojos.PingTarget;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.MockedStatic;
+
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.mockStatic;
+import static org.mockito.Mockito.when;
+
+/**
+ * The ping target that the Pings action works on must be one of the stored
+ * ping targets, selected by id.
+ */
+class PingsTargetBindingTest {
+
+    private MockedStatic<WebloggerFactory> factory;
+    private PingTargetManager pingTargets;
+    private ValueStack stack;
+
+    @BeforeEach
+    void setUp() throws Exception {
+        factory = mockStatic(WebloggerFactory.class);
+        pingTargets = mock(PingTargetManager.class);
+        
when(pingTargets.getCommonPingTargets()).thenReturn(Collections.emptyList());
+        Weblogger weblogger = mock(Weblogger.class);
+        when(weblogger.getPingTargetManager()).thenReturn(pingTargets);
+        factory.when(WebloggerFactory::getWeblogger).thenReturn(weblogger);
+
+        ConfigurationManager configurationManager = new 
ConfigurationManager("xwork");
+        configurationManager.addContainerProvider(new 
XWorkConfigurationProvider());
+        Container container = 
configurationManager.getConfiguration().getContainer();
+        stack = 
container.getInstance(ValueStackFactory.class).createValueStack();
+    }
+
+    @AfterEach
+    void tearDown() {
+        factory.close();
+    }
+
+    /** Set request parameters on the action the way the params interceptor 
does. */
+    private void bind(Pings action, String name, String value) {
+        stack.push(action);
+        ReflectionContextState.setCreatingNullObjects(stack.getContext(), 
true);
+        ReflectionContextState.setDenyMethodExecution(stack.getContext(), 
true);
+        try {
+            stack.setParameter(name, value);
+        } finally {
+            ReflectionContextState.setCreatingNullObjects(stack.getContext(), 
false);
+            stack.pop();
+        }
+    }
+
+    @Test
+    void pingTargetFieldsInTheRequestDoNotMakeATarget() throws Exception {
+        Pings action = new Pings();
+        bind(action, "pingTarget.pingUrl", "http://localhost:1/";);
+        action.myPrepare();
+
+        assertNull(action.getPingTarget());
+    }
+
+    @Test
+    void pingTargetIdSelectsAStoredTarget() throws Exception {
+        PingTarget stored = new PingTarget("target-1", "Stored", 
"http://ping.example.com/";, false);
+        when(pingTargets.getPingTarget("target-1")).thenReturn(stored);
+
+        Pings action = new Pings();
+        bind(action, "pingTargetId", "target-1");
+        bind(action, "pingTarget.pingUrl", "http://localhost:1/";);
+        action.myPrepare();
+
+        assertSame(stored, action.getPingTarget());
+        assertSame("http://ping.example.com/";, 
action.getPingTarget().getPingUrl());
+    }
+}
diff --git 
a/app/src/test/java/org/apache/roller/weblogger/ui/struts2/util/UIActionInterceptorTest.java
 
b/app/src/test/java/org/apache/roller/weblogger/ui/struts2/util/UIActionInterceptorTest.java
new file mode 100644
index 000000000..f0184e196
--- /dev/null
+++ 
b/app/src/test/java/org/apache/roller/weblogger/ui/struts2/util/UIActionInterceptorTest.java
@@ -0,0 +1,78 @@
+/*
+ * 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.
+ */
+package org.apache.roller.weblogger.ui.struts2.util;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+
+import com.opensymphony.xwork2.ActionContext;
+import com.opensymphony.xwork2.ActionInvocation;
+import org.apache.roller.weblogger.pojos.User;
+import org.apache.roller.weblogger.pojos.Weblog;
+import org.apache.struts2.StrutsStatics;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+/**
+ * The interceptor must set the authenticated user and the action weblog from
+ * trusted sources only, overwriting anything bound from request parameters.
+ */
+class UIActionInterceptorTest {
+
+    static class TestAction extends UIAction {
+        TestAction() { this.actionName = "test"; }
+        @Override public String execute() { return SUCCESS; }
+    }
+
+    @Test
+    void parameterBoundUserAndWeblogAreOverwrittenWhenThereIsNoSession() 
throws Exception {
+        // An attacker-controlled request with no session: getSession(false) 
is null,
+        // so RollerSession.getRollerSession returns null.
+        HttpServletRequest request = mock(HttpServletRequest.class);
+        when(request.getSession(false)).thenReturn(null);
+
+        // The action arrives with a user and weblog already bound from 
parameters.
+        TestAction action = new TestAction();
+        User forgedUser = new User();
+        forgedUser.setUserName("siteadmin");
+        action.setAuthenticatedUser(forgedUser);
+        Weblog forgedWeblog = new Weblog();
+        forgedWeblog.setHandle("team");
+        action.setActionWeblog(forgedWeblog);
+        // No weblog handle parameter, so no weblog can resolve.
+        action.setWeblog(null);
+
+        Map<String, Object> contextMap = new HashMap<>();
+        contextMap.put(StrutsStatics.HTTP_REQUEST, request);
+        ActionContext context = new ActionContext(contextMap);
+
+        ActionInvocation invocation = mock(ActionInvocation.class);
+        when(invocation.getAction()).thenReturn(action);
+        when(invocation.getInvocationContext()).thenReturn(context);
+        when(invocation.invoke()).thenReturn(UIAction.SUCCESS);
+
+        new UIActionInterceptor().doIntercept(invocation);
+
+        assertNull(action.getAuthenticatedUser());
+        assertNull(action.getActionWeblog());
+    }
+}

Reply via email to