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

coheigea pushed a commit to branch 3.6.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git

commit 7d7d89ebc9ed59e7447682439029f5263806bec2
Author: Colm O hEigeartaigh <[email protected]>
AuthorDate: Wed Nov 25 14:28:33 2026 +0000

    Don't return exception messages to the client from XmlSecInInterceptor 
(#3779)
    
    (cherry picked from commit 5e947cd1d82a33c3afb50a0b416588561cac4f3e)
---
 .../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 110dbd0a320..816d475ad3a 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
@@ -85,6 +85,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,
@@ -146,7 +147,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);
         }
     }
 
@@ -399,7 +401,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 d3a23ae7362..df581f678a6 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
@@ -31,6 +31,7 @@ import javax.crypto.SecretKey;
 import javax.security.auth.callback.Callback;
 import javax.security.auth.callback.CallbackHandler;
 import javax.ws.rs.WebApplicationException;
+import javax.security.auth.callback.UnsupportedCallbackException;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 
@@ -176,6 +177,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