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

robertlazarski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/axis-axis2-java-core.git

commit 82e5b88d9d0377f0cd81fd41e8cfa5ab706dfb35
Author: Robert Lazarski <[email protected]>
AuthorDate: Fri Nov 13 04:50:33 2026 -1000

    Read a resolver-less WSDL through a locator that refuses absolute imports
    
    WSDL11ToAxisServiceBuilder.readInTheWSDLFile handed wsdl4j a parsed
    Document when no resolver was set, and wsdl4j then fetched wsdl:import
    and xsd:import locations itself. It now reads through HardenedWSDLLocator
    over a locator that refuses absolute and network-path locations and
    resolves relative ones against the base URI, the rule getXMLSchema
    already applies to schemas. setCustomWSDLResolver remains the opt-in.
    
    Co-Authored-By: Claude Fable 5.1 <[email protected]>
---
 SECURITY.md                                        |  14 +-
 .../description/WSDL11ToAxisServiceBuilder.java    | 107 ++++++++++----
 .../description/ResolverlessWsdlImportTest.java    | 158 +++++++++++++++++++++
 src/site/markdown/release-notes/2.0.3.md           |   1 +
 4 files changed, 249 insertions(+), 31 deletions(-)

diff --git a/SECURITY.md b/SECURITY.md
index a1f97740c7..bbc359650a 100644
--- a/SECURITY.md
+++ b/SECURITY.md
@@ -263,11 +263,15 @@ migration from `commons-fileupload` 1.x to 
`commons-fileupload2` in
      generation rather than being ignored, so the tool cannot quietly parse a
      document other than the one named. Connect and read timeouts apply
      (`axis2.codegen.wsdl.connect.timeout`, `axis2.codegen.wsdl.read.timeout`).
-   - Not screened: `WSDL11ToAxisServiceBuilder.readInTheWSDLFile` when no
-     resolver is supplied parses the top document with the hardened
-     `XMLUtils.newDocument`, but wsdl4j fetches any `wsdl:import` itself. The
-     deployment callers do supply a resolver; a caller that does not, with a
-     remote base URI, is outside what is screened.
+   - `WSDL11ToAxisServiceBuilder.readInTheWSDLFile` with no resolver supplied
+     (the public `InputStream` constructors, and exploded-directory deployment)
+     now also reads through `HardenedWSDLLocator`, over a locator that refuses
+     every absolute or network-path `wsdl:import` location and `xsd:import`
+     schemaLocation -- `file:` included -- and resolves a relative one against
+     the base URI, the rule the schema resolver below already applied. Until
+     2.0.3 this branch handed wsdl4j a parsed `Document`, and wsdl4j fetched 
the
+     imports itself. A caller that needs absolute imports opts in with
+     `setCustomWSDLResolver`.
 
 3. **Schema import security:** URI resolvers for AAR and WAR deployments
    refuse HTTP/HTTPS/FTP/JAR/file scheme resolution, so an import cannot
diff --git 
a/modules/kernel/src/org/apache/axis2/description/WSDL11ToAxisServiceBuilder.java
 
b/modules/kernel/src/org/apache/axis2/description/WSDL11ToAxisServiceBuilder.java
index 19a0bfdcf8..8feca8d551 100644
--- 
a/modules/kernel/src/org/apache/axis2/description/WSDL11ToAxisServiceBuilder.java
+++ 
b/modules/kernel/src/org/apache/axis2/description/WSDL11ToAxisServiceBuilder.java
@@ -50,7 +50,7 @@ import org.w3c.dom.Element;
 import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
-import org.xml.sax.SAXException;
+import org.xml.sax.InputSource;
 
 import javax.wsdl.Binding;
 import javax.wsdl.BindingFault;
@@ -95,9 +95,8 @@ import javax.wsdl.extensions.soap12.SOAP12Operation;
 import javax.wsdl.xml.WSDLLocator;
 import javax.wsdl.xml.WSDLReader;
 import javax.xml.namespace.QName;
-import javax.xml.parsers.ParserConfigurationException;
-import java.io.IOException;
 import java.io.InputStream;
+import java.net.URI;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -2324,13 +2323,15 @@ public class WSDL11ToAxisServiceBuilder extends 
WSDLToAxisServiceBuilder {
         // AxisService.createClientSideAxisService() defaults to false and uses
         // a hardened WSDLLocator when opt-in is enabled.
         //
-        // Note what this method does and does not enforce. Where a resolver is
-        // supplied -- which the deployment callers do -- both the document 
and its
-        // imports are screened, below. On the resolver-less branch only the 
top
-        // document is (XMLUtils.newDocument is hardened); wsdl4j fetches any
-        // wsdl:import itself, and nothing here checks that the input really is
-        // local. A caller handing this method a remote base URI without a 
resolver
-        // is outside what is screened.
+        // Both branches below read through a WSDLLocator, because that is the 
only
+        // hook wsdl4j offers: given a Document instead, it fetches every
+        // wsdl:import location and xsd:import schemaLocation itself, with any
+        // scheme and host the document names. Where a resolver is supplied -- 
which
+        // the deployment callers do -- it decides where imports come from and 
is
+        // only screened for a DOCTYPE. Where none is, the input is a stream 
whose
+        // origin nothing here can check, so an absolute import location is 
refused
+        // outright and only a relative one resolves, against the base URI; 
this is
+        // the same rule getXMLSchema applies to schema imports.
         reader.setFeature("javax.wsdl.importDocuments", true);
 
         Definition def;
@@ -2344,33 +2345,87 @@ public class WSDL11ToAxisServiceBuilder extends 
WSDLToAxisServiceBuilder {
             def.setDocumentBaseURI(customWSDLResolver.getBaseURI());
             return def;
         } else {
-            Document doc;
-            try {
-                doc = XMLUtils.newDocument(in);
-            } catch (ParserConfigurationException e) {
-                throw new WSDLException(WSDLException.PARSER_ERROR,
-                                        "Parser Configuration Error", e);
-            } catch (SAXException e) {
-                throw new WSDLException(WSDLException.PARSER_ERROR,
-                                        "Parser SAX Error", e);
-
-            } catch (IOException e) {
-                throw new WSDLException(WSDLException.INVALID_WSDL, "IO Error",
-                                        e);
-            }
-
             // Log when and from where the WSDL is loaded.
             if (log.isDebugEnabled()) {
                 log.debug("Reading 1.1 WSDL with base uri = " + getBaseUri());
                 log.debug("  the document base uri = " + getDocumentBaseUri());
                 log.trace("  the stack at this point is: " + stackToString());
             }
-            def = reader.readWSDL(getBaseUri(), doc);
+            // The hardened wrapper screens the top document for a DOCTYPE, 
which is
+            // what the XMLUtils.newDocument parse used to do here, and reads 
each
+            // relative import the inner locator resolves.
+            def = reader.readWSDL(new HardenedWSDLLocator(
+                    new RelativeImportsOnlyLocator(in, getBaseUri())));
             def.setDocumentBaseURI(getDocumentBaseUri());
             return def;
         }
     }
 
+    /**
+     * The locator for a WSDL supplied as a stream with no resolver. It 
refuses an
+     * absolute or network-path import location -- {@code file:} included, 
like the
+     * schema resolver in {@link WSDLToAxisServiceBuilder#getXMLSchema} -- and 
resolves
+     * a relative one against its parent document, so co-packaged documents 
keep
+     * loading while the document cannot name a location of its own choosing. 
It
+     * never reads anything itself: an import comes back as a bare system id 
for
+     * {@link HardenedWSDLLocator} to open and screen. A caller that needs 
absolute
+     * imports opts in with {@link #setCustomWSDLResolver(WSDLLocator)}.
+     */
+    private static final class RelativeImportsOnlyLocator implements 
WSDLLocator {
+
+        private final InputStream in;
+        private final String baseURI;
+        private String latestImportURI;
+
+        RelativeImportsOnlyLocator(InputStream in, String baseURI) {
+            this.in = in;
+            this.baseURI = baseURI;
+        }
+
+        public InputSource getBaseInputSource() {
+            InputSource source = new InputSource(in);
+            source.setSystemId(baseURI);
+            return source;
+        }
+
+        public String getBaseURI() {
+            return baseURI;
+        }
+
+        public InputSource getImportInputSource(String parentLocation, String 
importLocation) {
+            if (isAbsoluteSchemaLocation(importLocation)) {
+                throw new RuntimeException("Absolute import location blocked: "
+                        + importLocation + " (use setCustomWSDLResolver to opt 
in)");
+            }
+            String context = parentLocation != null ? parentLocation : baseURI;
+            if (context == null) {
+                throw new RuntimeException("Cannot resolve import location "
+                        + importLocation + ": the WSDL was read from a stream"
+                        + " with no base URI");
+            }
+            String resolved;
+            try {
+                resolved = 
URI.create(context).resolve(importLocation).toString();
+            } catch (IllegalArgumentException e) {
+                // Fail closed: a location that cannot be resolved against its 
parent
+                // is not one to open as given.
+                throw new RuntimeException("Cannot resolve import location "
+                        + importLocation + " against " + context, e);
+            }
+            latestImportURI = resolved;
+            InputSource source = new InputSource();
+            source.setSystemId(resolved);
+            return source;
+        }
+
+        public String getLatestImportURI() {
+            return latestImportURI;
+        }
+
+        public void close() {
+        }
+    }
+
     /**
      * Get the Extensible elements form wsdl4jExtensibleElements
      * <code>Vector</code> if any and copy them to <code>Component</code>
diff --git 
a/modules/kernel/test/org/apache/axis2/description/ResolverlessWsdlImportTest.java
 
b/modules/kernel/test/org/apache/axis2/description/ResolverlessWsdlImportTest.java
new file mode 100644
index 0000000000..118d6c3288
--- /dev/null
+++ 
b/modules/kernel/test/org/apache/axis2/description/ResolverlessWsdlImportTest.java
@@ -0,0 +1,158 @@
+/*
+ * 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.axis2.description;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.InetSocketAddress;
+import java.nio.charset.StandardCharsets;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import com.sun.net.httpserver.HttpServer;
+
+import junit.framework.TestCase;
+
+/**
+ * A WSDL handed to the builder as a stream, with no resolver, is a document 
whose
+ * origin nothing can check. wsdl4j fetches wsdl:import locations and 
xsd:import
+ * schemaLocations itself when it is given a parsed Document, so until 2.0.3 
such a
+ * document could name any host and the server would send it a request. The
+ * resolver-less read now goes through a locator that refuses an absolute 
location
+ * before anything is opened; a relative one still resolves, since that is how
+ * co-packaged documents refer to each other.
+ */
+public class ResolverlessWsdlImportTest extends TestCase {
+
+    private static final String HEAD =
+            "<?xml version='1.0'?>"
+            + "<wsdl:definitions xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/'"
+            + " xmlns:xs='http://www.w3.org/2001/XMLSchema'"
+            + " targetNamespace='urn:test'>";
+
+    private HttpServer server;
+    private final AtomicInteger requests = new AtomicInteger();
+
+    @Override
+    protected void setUp() throws Exception {
+        // Stands in for an internal host. It answers, so a request that does 
get
+        // through fails the count assertion instead of hanging the test.
+        server = HttpServer.create(new InetSocketAddress("127.0.0.1", 0), 0);
+        server.createContext("/", exchange -> {
+            requests.incrementAndGet();
+            byte[] body = (HEAD + 
"</wsdl:definitions>").getBytes(StandardCharsets.UTF_8);
+            exchange.sendResponseHeaders(200, body.length);
+            OutputStream out = exchange.getResponseBody();
+            out.write(body);
+            out.close();
+        });
+        server.start();
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        server.stop(0);
+    }
+
+    private String origin() {
+        return "http://127.0.0.1:"; + server.getAddress().getPort();
+    }
+
+    private static String wsdlImporting(String location) {
+        return HEAD + "<wsdl:import namespace='urn:imported' location='" + 
location + "'/>"
+                + "</wsdl:definitions>";
+    }
+
+    private static String wsdlWithSchemaImport(String location) {
+        return HEAD + "<wsdl:types><xs:schema targetNamespace='urn:test'>"
+                + "<xs:import namespace='urn:types' schemaLocation='" + 
location + "'/>"
+                + "</xs:schema></wsdl:types></wsdl:definitions>";
+    }
+
+    private static WSDL11ToAxisServiceBuilder builderFor(String wsdl) {
+        return new WSDL11ToAxisServiceBuilder(
+                new 
ByteArrayInputStream(wsdl.getBytes(StandardCharsets.UTF_8)), null, null);
+    }
+
+    private static boolean causeChainMentions(Throwable t, String text) {
+        for (Throwable c = t; c != null; c = c.getCause()) {
+            if (c.getMessage() != null && c.getMessage().contains(text)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    private void assertRefusedWithoutFetching(WSDL11ToAxisServiceBuilder 
builder,
+                                              String expectedInMessage) {
+        try {
+            builder.populateService();
+            fail("the import must be refused");
+        } catch (Exception expected) {
+            assertTrue("should say why it was refused, was: " + expected,
+                    causeChainMentions(expected, expectedInMessage));
+        }
+        assertEquals("no request may reach the host the document named",
+                0, requests.get());
+    }
+
+    public void testAnAbsoluteWsdlImportIsRefusedBeforeItIsFetched() {
+        assertRefusedWithoutFetching(
+                builderFor(wsdlImporting(origin() + "/imported.wsdl")),
+                "Absolute import location blocked");
+    }
+
+    public void testAnAbsoluteSchemaImportIsRefusedBeforeItIsFetched() {
+        assertRefusedWithoutFetching(
+                builderFor(wsdlWithSchemaImport(origin() + "/types.xsd")),
+                "Absolute import location blocked");
+    }
+
+    /** A network-path reference would take the base document's scheme. */
+    public void testANetworkPathImportIsRefused() {
+        assertRefusedWithoutFetching(
+                builderFor(wsdlImporting("//127.0.0.1:" + 
server.getAddress().getPort()
+                        + "/imported.wsdl")),
+                "Absolute import location blocked");
+    }
+
+    /** Refusing absolute locations must not stop a relative one resolving. */
+    public void testARelativeImportStillResolvesAgainstTheBaseUri() throws 
Exception {
+        File wsdl = new 
File("test-resources/wsdl/imports/binding/EchoService.wsdl");
+        InputStream in = new FileInputStream(wsdl);
+        try {
+            WSDL11ToAxisServiceBuilder builder = new 
WSDL11ToAxisServiceBuilder(in);
+            builder.setBaseUri(wsdl.getParentFile().toURI().toString());
+            builder.setDocumentBaseUri(wsdl.toURI().toString());
+            AxisService service = builder.populateService();
+            
assertNotNull(service.getEndpoint("EchoServiceHttpSoap12Endpoint"));
+        } finally {
+            in.close();
+        }
+        assertEquals(0, requests.get());
+    }
+
+    /** With no base URI there is nothing to resolve a relative location 
against. */
+    public void testARelativeImportWithNoBaseUriFailsClosed() {
+        assertRefusedWithoutFetching(
+                builderFor(wsdlImporting("imported.wsdl")), "no base URI");
+    }
+}
diff --git a/src/site/markdown/release-notes/2.0.3.md 
b/src/site/markdown/release-notes/2.0.3.md
index 5dc77fff7f..7d22f52f28 100644
--- a/src/site/markdown/release-notes/2.0.3.md
+++ b/src/site/markdown/release-notes/2.0.3.md
@@ -8,6 +8,7 @@ Apache Axis2 2.0.3 Release Notes
 | Change | Restore the old behaviour with |
 |---|---|
 | The JSON dispatcher no longer selects a service from the XML body namespace 
| `<parameter name="allowContentBasedServiceDispatch">true</parameter>` |
+| A WSDL read with no resolver refuses absolute `wsdl:import` and `xsd:import` 
locations | `WSDL11ToAxisServiceBuilder.setCustomWSDLResolver(...)` with a 
locator of your own |
 
 `JSONBasedDefaultDispatcher`, the Dispatch-phase dispatcher in the Spring Boot
 starter's `axis2-json.xml`, now honours `allowContentBasedServiceDispatch` as 
the

Reply via email to