gnodet-bot commented on code in PR #31126:
URL: https://github.com/apache/camel/pull/31126#discussion_r4739273766
##########
components/camel-xmlsecurity/src/main/java/org/apache/camel/dataformat/xmlsecurity/XMLSecurityDataFormat.java:
##########
@@ -783,18 +783,33 @@ private String generateXmlCipherAlgorithmKeyWrap() {
return algorithmKeyWrap;
}
- // Check to see if the asymmetric key transport algorithm is allowed
+ private static boolean isGcmAlgorithm(String algorithm) {
+ return XMLCipher.AES_128_GCM.equals(algorithm)
+ || XMLCipher.AES_192_GCM.equals(algorithm)
+ || XMLCipher.AES_256_GCM.equals(algorithm);
+ }
+
+ // Check to see if the data cipher and asymmetric key transport algorithms
are allowed
private void checkEncryptionAlgorithm(Key keyEncryptionKey, Element
parentElement) throws Exception {
+ Element encryptedElement = findEncryptedDataElement(parentElement);
+ if (encryptedElement == null) {
+ return;
+ }
+
+ String configuredXmlCipher = resolvedXmlCipherAlgorithm();
+ if (isGcmAlgorithm(configuredXmlCipher)) {
+ String foundDataMethod = findEncryptionMethod(encryptedElement);
+ if (foundDataMethod != null && !isGcmAlgorithm(foundDataMethod)) {
Review Comment:
When `findEncryptionMethod` returns `null` (i.e. the incoming
`EncryptedData` omits the optional `EncryptionMethod` element), the `!= null`
guard short-circuits the check and execution continues silently — the GCM
enforcement is bypassed. If a fail-closed posture is desired, consider:
```suggestion
if (foundDataMethod == null || !isGcmAlgorithm(foundDataMethod))
{
```
This would reject payloads with no declared data cipher when GCM is
configured. Legitimate compliant payloads always include `EncryptionMethod`, so
this shouldn't break valid use cases. If the current lenient behaviour is
intentional (e.g. for compatibility with older producers), a brief comment
explaining the choice would help future readers.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]