This is an automated email from the ASF dual-hosted git repository.
coheigea pushed a commit to branch 4.1.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git
The following commit(s) were added to refs/heads/4.1.x-fixes by this push:
new 6ce85eba812 Restrict the object reference addresses accepted in CORBA
messages (#3738)
6ce85eba812 is described below
commit 6ce85eba8120e0312e3196240b28ea4e0987acc8
Author: Colm O hEigeartaigh <[email protected]>
AuthorDate: Wed Nov 18 13:06:50 2026 +0000
Restrict the object reference addresses accepted in CORBA messages (#3738)
(cherry picked from commit 06326c8d08a88053c8a0ac1c2ac7924a9ed00ad6)
---
.../corba/types/CorbaObjectReferenceListener.java | 34 +++++
.../types/CorbaObjectReferenceListenerTest.java | 137 +++++++++++++++++++++
2 files changed, 171 insertions(+)
diff --git
a/rt/bindings/corba/src/main/java/org/apache/cxf/binding/corba/types/CorbaObjectReferenceListener.java
b/rt/bindings/corba/src/main/java/org/apache/cxf/binding/corba/types/CorbaObjectReferenceListener.java
index 28106979b59..1199c97f1df 100644
---
a/rt/bindings/corba/src/main/java/org/apache/cxf/binding/corba/types/CorbaObjectReferenceListener.java
+++
b/rt/bindings/corba/src/main/java/org/apache/cxf/binding/corba/types/CorbaObjectReferenceListener.java
@@ -19,13 +19,35 @@
package org.apache.cxf.binding.corba.types;
+import java.util.Arrays;
+import java.util.Locale;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import org.apache.cxf.binding.corba.CorbaBindingException;
import org.apache.cxf.binding.corba.utils.CorbaObjectReferenceHelper;
import org.apache.cxf.binding.corba.utils.CorbaUtils;
+import org.apache.cxf.common.util.SystemPropertyAction;
import org.omg.CORBA.ORB;
public class CorbaObjectReferenceListener extends AbstractCorbaTypeListener {
+ /**
+ * The URL schemes that the address of an object reference in a message
may use, as a comma-separated
+ * list. The default is "IOR,corbaloc". The address is resolved as soon as
the reference is marshalled.
+ * IOR and corbaloc addresses only describe the object, but a corbaname
address makes the ORB contact the
+ * naming service it names, and a file address reads a local file. So
corbaname and file should only be
+ * allowed if the addresses can be trusted. It is set as a system property.
+ */
+ public static final String ALLOWED_ADDRESS_SCHEMES =
"org.apache.cxf.corba.objectReferenceAddressSchemes";
+
+ private static final Set<String> ALLOWED_SCHEMES =
+
Arrays.stream(SystemPropertyAction.getProperty(ALLOWED_ADDRESS_SCHEMES,
"IOR,corbaloc").split(","))
+ .map(scheme -> scheme.trim().toLowerCase(Locale.ENGLISH))
+ .filter(scheme -> !scheme.isEmpty())
+ .collect(Collectors.toSet());
+
private final CorbaObjectReferenceHandler value;
private final ORB orb;
@@ -46,6 +68,7 @@ public class CorbaObjectReferenceListener extends
AbstractCorbaTypeListener {
throw new RuntimeException("Anonymous endpoint reference types
not supported");
}
+ checkAddressScheme(text);
try {
ref = CorbaUtils.importObjectReference(orb, text);
} catch (org.omg.CORBA.BAD_PARAM ex) {
@@ -54,4 +77,15 @@ public class CorbaObjectReferenceListener extends
AbstractCorbaTypeListener {
value.setReference(ref);
}
}
+
+ private static void checkAddressScheme(String address) {
+ String trimmed = address.trim();
+ int index = trimmed.indexOf(':');
+ String scheme = index > 0 ? trimmed.substring(0,
index).toLowerCase(Locale.ENGLISH) : "";
+ if (!ALLOWED_SCHEMES.contains(scheme)) {
+ // don't include the address, so that the error doesn't reveal
anything about it
+ throw new CorbaBindingException("The object reference address
scheme \"" + scheme
+ + "\" is not allowed, see " + ALLOWED_ADDRESS_SCHEMES);
+ }
+ }
}
diff --git
a/rt/bindings/corba/src/test/java/org/apache/cxf/binding/corba/types/CorbaObjectReferenceListenerTest.java
b/rt/bindings/corba/src/test/java/org/apache/cxf/binding/corba/types/CorbaObjectReferenceListenerTest.java
new file mode 100644
index 00000000000..aa68748839c
--- /dev/null
+++
b/rt/bindings/corba/src/test/java/org/apache/cxf/binding/corba/types/CorbaObjectReferenceListenerTest.java
@@ -0,0 +1,137 @@
+/**
+ * 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.cxf.binding.corba.types;
+
+import java.io.File;
+import java.net.ServerSocket;
+import java.net.SocketTimeoutException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+
+import javax.xml.namespace.QName;
+
+import org.apache.cxf.binding.corba.CorbaBindingException;
+import org.apache.cxf.binding.corba.wsdl.CorbaConstants;
+import org.omg.CORBA.ORB;
+import org.omg.CORBA.TCKind;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThrows;
+
+public class CorbaObjectReferenceListenerTest {
+
+ private static final QName ADDRESS = new
QName("http://www.w3.org/2005/08/addressing", "Address");
+
+ private ORB orb;
+
+ @Before
+ public void setUp() throws Exception {
+ java.util.Properties props = System.getProperties();
+ props.put("yoko.orb.id", "CXF-CORBA-Binding");
+ orb = ORB.init(new String[0], props);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ if (orb != null) {
+ try {
+ orb.destroy();
+ } catch (Exception ex) {
+ // ignore
+ }
+ }
+ }
+
+ @Test
+ public void testIorAddress() {
+ // parsing a corbaloc URL doesn't contact the host, it just builds the
reference
+ String ior =
orb.object_to_string(orb.string_to_object("corbaloc::127.0.0.1:1/Test"));
+
+ CorbaObjectReferenceHandler handler = createHandler();
+ CorbaObjectReferenceListener listener = new
CorbaObjectReferenceListener(handler, orb);
+ listener.processStartElement(ADDRESS);
+ listener.processCharacters(ior);
+ assertNotNull(handler.getReference());
+ }
+
+ @Test
+ public void testFileAddressRejected() throws Exception {
+ File file = File.createTempFile("objref", ".ref");
+ try {
+ Files.write(file.toPath(),
+
orb.object_to_string(orb.string_to_object("corbaloc::127.0.0.1:1/Test"))
+ .getBytes(StandardCharsets.UTF_8));
+
+ CorbaObjectReferenceHandler handler = createHandler();
+ CorbaObjectReferenceListener listener = new
CorbaObjectReferenceListener(handler, orb);
+ listener.processStartElement(ADDRESS);
+ assertThrows(CorbaBindingException.class,
+ () -> listener.processCharacters("file:" +
file.getAbsolutePath()));
+ assertNull(handler.getReference());
+ } finally {
+ file.delete();
+ }
+ }
+
+ @Test
+ public void testCorbalocAddress() {
+ // a corbaloc address only describes the object, nothing is contacted
when it is resolved
+ CorbaObjectReferenceHandler handler = createHandler();
+ CorbaObjectReferenceListener listener = new
CorbaObjectReferenceListener(handler, orb);
+ listener.processStartElement(ADDRESS);
+ listener.processCharacters("corbaloc::127.0.0.1:1/Test");
+ assertNotNull(handler.getReference());
+ }
+
+ @Test(timeout = 30000)
+ public void testCorbanameAddressRejected() throws Exception {
+ // resolving a corbaname address would contact the naming service it
names, so check that nothing is
+ try (ServerSocket server = new ServerSocket(0)) {
+ CorbaObjectReferenceHandler handler = createHandler();
+ CorbaObjectReferenceListener listener = new
CorbaObjectReferenceListener(handler, orb);
+ listener.processStartElement(ADDRESS);
+ assertThrows(CorbaBindingException.class,
+ () -> listener.processCharacters("corbaname::127.0.0.1:" +
server.getLocalPort() + "#Test"));
+ assertNull(handler.getReference());
+
+ server.setSoTimeout(500);
+ assertThrows(SocketTimeoutException.class, () ->
server.accept().close());
+ }
+ }
+
+ @Test
+ public void testAddressWithoutSchemeRejected() {
+ CorbaObjectReferenceHandler handler = createHandler();
+ CorbaObjectReferenceListener listener = new
CorbaObjectReferenceListener(handler, orb);
+ listener.processStartElement(ADDRESS);
+ assertThrows(CorbaBindingException.class, () ->
listener.processCharacters("no-scheme"));
+ assertNull(handler.getReference());
+ }
+
+ private CorbaObjectReferenceHandler createHandler() {
+ QName idlType = new QName(CorbaConstants.NU_WSDL_CORBA, "object",
CorbaConstants.NP_WSDL_CORBA);
+ return new CorbaObjectReferenceHandler(new QName("ref"), idlType,
+
orb.get_primitive_tc(TCKind.tk_objref), null);
+ }
+}