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

coheigea pushed a commit to branch coheigea/XmlSecInInterceptor
in repository https://gitbox.apache.org/repos/asf/cxf.git

commit d1b2717545f6e10feb1aded6040f6064dffeacbd
Author: Colm O hEigeartaigh <[email protected]>
AuthorDate: Wed Nov 25 10:09:21 2026 +0000

    Don't return exception messages to the client from XmlSecInInterceptor
---
 .../cxf/rs/security/xml/XmlSecInInterceptor.java   |  6 ++++--
 .../rs/security/xml/XmlSecInInterceptorTest.java   | 24 ++++++++++++++++++++++
 2 files changed, 28 insertions(+), 2 deletions(-)

diff --git 
a/rt/rs/security/xml/src/main/java/org/apache/cxf/rs/security/xml/XmlSecInInterceptor.java
 
b/rt/rs/security/xml/src/main/java/org/apache/cxf/rs/security/xml/XmlSecInInterceptor.java
index 2388a1ba1f0..b26940fce55 100644
--- 
a/rt/rs/security/xml/src/main/java/org/apache/cxf/rs/security/xml/XmlSecInInterceptor.java
+++ 
b/rt/rs/security/xml/src/main/java/org/apache/cxf/rs/security/xml/XmlSecInInterceptor.java
@@ -86,6 +86,7 @@ import 
org.apache.xml.security.stax.securityToken.SecurityToken;
 public class XmlSecInInterceptor extends AbstractPhaseInterceptor<Message> 
implements ReaderInterceptor  {
 
     private static final Logger LOG = 
LogUtils.getL7dLogger(XmlSecInInterceptor.class);
+    private static final String SECURITY_PROCESSING_FAILED = "Security 
processing failed";
 
     private static final Set<String> ALLOWED_TRANSFORMS = Set.of(
         XMLSecurityConstants.NS_XMLDSIG_ENVELOPED_SIGNATURE,
@@ -147,7 +148,8 @@ public class XmlSecInInterceptor extends 
AbstractPhaseInterceptor<Message> imple
             inMsg.setContent(XMLStreamReader.class, newXmlStreamReader);
 
         } catch (XMLStreamException | XMLSecurityException | IOException | 
UnsupportedCallbackException e) {
-            throwFault(e.getMessage(), e);
+            // Don't return the exception message to the client, it is logged 
instead
+            throwFault(SECURITY_PROCESSING_FAILED, e);
         }
     }
 
@@ -402,7 +404,7 @@ public class XmlSecInInterceptor extends 
AbstractPhaseInterceptor<Message> imple
 
 
     protected void throwFault(String error, Exception ex) {
-        LOG.warning(error);
+        LOG.warning(ex == null ? error : error + " - " + ex.getMessage());
         Response response = 
JAXRSUtils.toResponseBuilder(400).entity(error).type("text/plain").build();
         throw ExceptionUtils.toBadRequestException(null, response);
     }
diff --git 
a/rt/rs/security/xml/src/test/java/org/apache/cxf/rs/security/xml/XmlSecInInterceptorTest.java
 
b/rt/rs/security/xml/src/test/java/org/apache/cxf/rs/security/xml/XmlSecInInterceptorTest.java
index a48209bdef6..d339a9ac741 100644
--- 
a/rt/rs/security/xml/src/test/java/org/apache/cxf/rs/security/xml/XmlSecInInterceptorTest.java
+++ 
b/rt/rs/security/xml/src/test/java/org/apache/cxf/rs/security/xml/XmlSecInInterceptorTest.java
@@ -30,6 +30,7 @@ import javax.crypto.KeyGenerator;
 import javax.crypto.SecretKey;
 import javax.security.auth.callback.Callback;
 import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.callback.UnsupportedCallbackException;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 
@@ -181,6 +182,29 @@ public class XmlSecInInterceptorTest {
         assertEquals("Book", root.getLocalName());
     }
 
+    @Test
+    public void testSecurityProcessingErrorIsNotReturnedToClient() throws 
Exception {
+        Message message = new MessageImpl();
+        message.setExchange(new ExchangeImpl());
+        message.put(Message.HTTP_REQUEST_METHOD, "POST");
+        message.put(SecurityConstants.ENCRYPT_CRYPTO, crypto);
+        CallbackHandler callbackHandler = (Callback[] callbacks) -> {
+            throw new UnsupportedCallbackException(callbacks[0], "internal 
details");
+        };
+        message.put(SecurityConstants.CALLBACK_HANDLER, callbackHandler);
+        byte[] bytes = 
StaxUtils.toString(createSignedDocument()).getBytes(StandardCharsets.UTF_8);
+        message.setContent(InputStream.class, new ByteArrayInputStream(bytes));
+        message.setInterceptorChain(new PhaseInterceptorChain(new 
PhaseManagerImpl().getInPhases()));
+
+        try {
+            new XmlSecInInterceptor().handleMessage(message);
+            fail("Failure expected on a security processing error");
+        } catch (WebApplicationException ex) {
+            assertEquals(400, ex.getResponse().getStatus());
+            assertEquals("Security processing failed", 
ex.getResponse().getEntity());
+        }
+    }
+
     private static void assertRejected(Document doc) throws Exception {
         try {
             process(doc);

Reply via email to