testcontainers-java: [Bug]: Vulnerable dependency commons-compress 1.24.0

Module

Core

Testcontainers version

1.19.5

Using the latest Testcontainers version?

Yes

Host OS

Linux

Host Arch

x86_64

Docker version

Podman 4.3.1

What happened?

Testcontainers pulls in common-compress 1.24.0.

https://github.com/testcontainers/testcontainers-java/blob/main/core/build.gradle#L76

Additional Information

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 20
  • Comments: 18

Commits related to this issue

Most upvoted comments

Any news on this?

We would really like to use Testcontainers again. But for security reasons we can’t. Unfortunately we can’t understand why the maintainers of Testcontainers refuse to upgrade the dependency. Sure, we could override this dependency ourself. But we are more concerned about how the maintainers deal with security issues. 😕

Anyone coming across this, please follow the discussion at #8354. The commons-compress dependency won’t be updated here for now.

When this does get upgraded it seems pretty clear that it should also become a shaded dependency. Libraries with other common libraries as dependencies are problematic.

It also works with 1.27.0. Please update.

The project continues to be vulnerable to CVE-2024-26308 and CVE-2024-25710.

What blocks merging a change like https://github.com/testcontainers/testcontainers-java/pull/9796? Can anyone share any reproducer if any issue is present?

@eddumelendez Let me respond here because this issue was referred in my PR. Thank you for looking into it.

I am following Maven repository vulnerabilities indication. If those are true, then testcontainers version 1.20.6 is referring to commons-compress version 1.24.0 that has direct CVE-2024-26308, CVE-2024-25710 and indirect CVE-2024-47554 vulnerabilities. So the question is the vulnerabilities of test dependencies can be considered as attack vector? Since those are executed as well (in test environment) then my answer is yes. Therefore the CVEs are not false positives.

Just thinking out loudly and approach this question from different angle… core/build.gradle is exposing commons-compress because the library is in dependencies api. This means it is part of the shipped APIs (https://docs.gradle.org/current/userguide/java_library_plugin.html#sec:java_library_separation). Why is that? I don’t think testcontainers ambition is to provide a compression library. So if we could put this reference among implementation or shared then it must not affect on other libraries… unless they have been using this reference and those did not include among their own library references.

So I did an experiment.

  1. I removed api commons-compress reference completely. The project is still compiling fine. commons-compress was referred from deeper dependencies (1.21, 1.24, 1.26, 1.26.2)
    • Very interestingly upgrading com.github.docker-java:docker-java-core:3.4.2 to 3.5.0 left “only” commons-compress version 1.21 and 1.27.1. I could not identify where 1.21 version reference is coming from.
  2. I found the following testcontainer API references where commons-compress is referred.
    • org.testcontainers.utility.MountableFile is using TarArchiveOutputStream in the API. By changing it to its ArchiveOutputStream abstract class (org.testcontainers.images.builder.Transferable must be changed as well), we are limiting the potential impact for version changes. This is a fairly stable class.
    • org.testcontainers.images.builder.Transferable is using and explained above.
    • org.testcontainers.images.builder.ImageFromDockerfile is using only internally. No harm to the API.
    • org.testcontainers.containers.VncRecordingContainer is using only internally. No harm to the API.
    • org.testcontainers.containers.ContainerState is using only internally. No harm to the API.

So only org.testcontainers.utility.MountableFile is exposing commons-compress related object in transferTo method (inherited from org.testcontainers.images.builder.Transferable). This can be reduced to an abstract class (org.apache.commons.compress.archivers.ArchiveOutputStream).

Now the question is how can we hide or abstract this reference so that the need of commons-compress could be eliminated from the API completely to keep its usage internally in testcontainers?

For my particular team, we just overwrote the transitive dependency which seems to be fine for our use

That is a good temporary workaround. But a year later I was looking for some kind of official resolution.

Same issue for us - our security tooling does not allow us to disregard security vulnerabilities in our test code sadly.

In addition, this dependency should be “shaded” since it can conflict with other popular libraries like Apache POI which uses a newer version of commons-compress that is incompatible with test container and causes NoClassDefFound exception

Hi,

It still looks like Testcontainers is currently using commons-compress:1.24.0, which has some known vulnerabilities: 1. [GHSA-4g9r-vxhx-9pgx]: High severity (8.1) - Infinite loop in corrupted DUMP files causing a DoS. 2. [GHSA-4265-ccf5-phj5]: Medium severity (5.5) - OutOfMemoryError when unpacking broken Pack200 files.

These issues are resolved in commons-compress:1.27.1. For now, I’m overriding the dependency in my project, but it would be great if this was updated in Testcontainers directly to help others avoid this issue.

Thanks for all the work on this amazing project!

All the best, Martin

Apache have released patch version 1.26.1 of commons-compress last week that may address this?

COMPRESS-659: TarArchiveOutputStream should use Commons IO Charsets instead of Commons Codec Charsets.

I was able to successfully upgrade the commons-compress version in a project of mine to 1.26.1 that was previously failing on 1.26.0 with:

java.lang.NoClassDefFoundError: org/apache/commons/codec/Charsets

	at org.apache.commons.compress.archivers.tar.TarArchiveOutputStream.<init>(TarArchiveOutputStream.java:212)
	at org.apache.commons.compress.archivers.tar.TarArchiveOutputStream.<init>(TarArchiveOutputStream.java:157)
	at org.apache.commons.compress.archivers.tar.TarArchiveOutputStream.<init>(TarArchiveOutputStream.java:147)
	at org.testcontainers.containers.ContainerState.copyFileToContainer(ContainerState.java:350)
	at org.testcontainers.containers.ContainerState.copyFileToContainer(ContainerState.java:331)
	at java.base/java.util.LinkedHashMap.forEach(LinkedHashMap.java:986)
	at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:441)