This is an automated email from the ASF dual-hosted git repository. coheigea pushed a commit to branch coheigea/AbstractXmlEncInHandler in repository https://gitbox.apache.org/repos/asf/cxf.git
commit e9a0293d8f5ab11be8ccb2c58428e276de8d56a8 Author: Colm O hEigeartaigh <[email protected]> AuthorDate: Tue Nov 24 16:06:40 2026 +0000 Check the symmetric encryption algorithm before decrypting the EncryptedKey --- .../cxf/rs/security/xml/AbstractXmlEncInHandler.java | 5 +++-- .../cxf/rs/security/xml/XmlEncInHandlerTest.java | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/rt/rs/security/xml/src/main/java/org/apache/cxf/rs/security/xml/AbstractXmlEncInHandler.java b/rt/rs/security/xml/src/main/java/org/apache/cxf/rs/security/xml/AbstractXmlEncInHandler.java index fe2f0971fcc..5b7564bcb98 100644 --- a/rt/rs/security/xml/src/main/java/org/apache/cxf/rs/security/xml/AbstractXmlEncInHandler.java +++ b/rt/rs/security/xml/src/main/java/org/apache/cxf/rs/security/xml/AbstractXmlEncInHandler.java @@ -73,8 +73,8 @@ public abstract class AbstractXmlEncInHandler extends AbstractXmlSecInHandler { Element root = doc.getDocumentElement(); - byte[] symmetricKeyBytes = getSymmetricKeyBytes(message, root); - + // Check the content encryption algorithm before the EncryptedKey is processed, so that the + // private key is not used for a message that is going to be rejected anyway String symKeyAlgo = getEncodingMethodAlgorithm(root); if (encProps != null && encProps.getEncryptionSymmetricKeyAlgo() != null @@ -82,6 +82,7 @@ public abstract class AbstractXmlEncInHandler extends AbstractXmlSecInHandler { throwFault("Encryption Symmetric Key Algorithm is not supported", null); } + byte[] symmetricKeyBytes = getSymmetricKeyBytes(message, root); byte[] decryptedPayload = null; try { diff --git a/rt/rs/security/xml/src/test/java/org/apache/cxf/rs/security/xml/XmlEncInHandlerTest.java b/rt/rs/security/xml/src/test/java/org/apache/cxf/rs/security/xml/XmlEncInHandlerTest.java index a3c89bd19ab..49dadf3e869 100644 --- a/rt/rs/security/xml/src/test/java/org/apache/cxf/rs/security/xml/XmlEncInHandlerTest.java +++ b/rt/rs/security/xml/src/test/java/org/apache/cxf/rs/security/xml/XmlEncInHandlerTest.java @@ -101,6 +101,26 @@ public class XmlEncInHandlerTest { assertDecryptionFailed(() -> handler.decryptContent(createMessage())); } + @Test + public void testSymmetricAlgorithmCheckedBeforeKeyDecryption() { + AbstractXmlEncInHandler handler = new AbstractXmlEncInHandler() { + @Override + protected byte[] getSymmetricKeyBytes(Message message, Element encDataElement) { + throw new AssertionError("The EncryptedKey must not be processed"); + } + }; + EncryptionProperties encProps = new EncryptionProperties(); + encProps.setEncryptionSymmetricKeyAlgo(XMLCipher.AES_256_GCM); + handler.setEncryptionProperties(encProps); + try { + handler.decryptContent(createMessage()); + fail("Expected the request to be rejected"); + } catch (WebApplicationException ex) { + assertEquals(400, ex.getResponse().getStatus()); + assertEquals("Encryption Symmetric Key Algorithm is not supported", ex.getResponse().getEntity()); + } + } + @Test public void testEncryptedKeyBase64Failure() { assertDecryptionFailed(() -> decryptSymmetricKey("!!! not base64 !!!"));
