gnodet-bot commented on code in PR #26656:
URL: https://github.com/apache/camel/pull/26656#discussion_r4060079669


##########
components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/util/HttpMessageUtils.java:
##########
@@ -335,9 +342,28 @@ public static ApplicationEntity 
extractEdiPayloadFromCompressedEntity(
             ApplicationPkcs7MimeCompressedDataEntity compressedDataEntity, 
DecrpytingAndSigningInfo decrpytingAndSigningInfo,
             boolean hasValidSignature)
             throws HttpException {
+        return extractEdiPayloadFromCompressedEntity(compressedDataEntity, 
decrpytingAndSigningInfo, hasValidSignature,
+                MAX_COMPRESSED_ENTITY_EXPANSION);
+    }
+
+    /**
+     * As
+     * {@link 
#extractEdiPayloadFromCompressedEntity(ApplicationPkcs7MimeCompressedDataEntity,
 DecrpytingAndSigningInfo, boolean)},
+     * with an explicit bound on how far the compressed entity may expand.
+     *
+     * @param maxExpandedSize the largest expansion to accept, in bytes
+     */

Review Comment:
   ⚠️ **Incomplete fix — `MicUtils.java:179` still uses an unbounded 
`ZlibExpanderProvider()`.**
   
   `MicUtils.findSignedDataEntity()` contains:
   ```java
   MimeEntity inner = compressedEntity
           .getCompressedEntity(new ZlibExpanderProvider());
   ```
   This is called from `createReceivedContentMic()` while processing an inbound 
AS2 message — the same pre-authentication path described in the PR description. 
A decompression bomb sent to the MIC computation path is equally dangerous and 
is **not covered by this PR**.
   
   The bounded path should be used there too:
   ```java
   MimeEntity inner = compressedEntity
           .getCompressedEntity(new 
ZlibExpanderProvider(HttpMessageUtils.MAX_COMPRESSED_ENTITY_EXPANSION));
   ```
   (The constant is already `public`, so `MicUtils` can reference it directly.)



##########
components/camel-as2/camel-as2-api/src/test/java/org/apache/camel/component/as2/api/util/CompressedEntityExpansionBoundTest.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * 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.camel.component.as2.api.util;
+
+import org.apache.camel.component.as2.api.entity.ApplicationEDIFACTEntity;
+import org.apache.camel.component.as2.api.entity.ApplicationEntity;
+import 
org.apache.camel.component.as2.api.entity.ApplicationPkcs7MimeCompressedDataEntity;
+import org.apache.hc.core5.http.HttpException;
+import org.bouncycastle.cms.CMSCompressedDataGenerator;
+import org.bouncycastle.cms.jcajce.ZlibCompressor;
+import org.bouncycastle.operator.OutputCompressor;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * A compressed entity is expanded while the payload is extracted, which 
happens before the signature has been
+ * established. The expansion must therefore be bounded rather than 
proportional to whatever an unauthenticated sender
+ * claims.
+ */
+class CompressedEntityExpansionBoundTest {
+
+    /** Highly compressible, so the entity on the wire is a tiny fraction of 
what it expands to. */
+    private static final String PAYLOAD = "A".repeat(200_000);
+
+    private static final HttpMessageUtils.DecrpytingAndSigningInfo NO_SECURITY
+            = new HttpMessageUtils.DecrpytingAndSigningInfo(null, null);
+
+    @Test
+    void expansionBeyondTheBoundIsRefused() throws Exception {
+        ApplicationPkcs7MimeCompressedDataEntity compressed = 
compressedEntity();
+
+        // the failure must come from the bound itself, not from anything 
downstream, so assert the type
+        // the failure must come from the expander refusing, not from anything 
downstream

Review Comment:
   🔧 **Duplicate comment:** lines 49–50 say the same thing twice (one was 
clearly a leftover from an edit). Remove one.
   
   ```suggestion
           // the failure must come from the expander refusing, not from 
anything downstream
   ```



-- 
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]

Reply via email to