CVE-2025-5981:
OSV-SCALIBR's Container Image Unpacking Vulnerable to Arbitrary File Write via Path Traversal
5.7
CVSS ScoreBasic Information
Technical Details
Package Name | Ecosystem | Vulnerable Versions | First Patched Version |
---|---|---|---|
github.com/google/osv-scalibr | go | >= 0.1.3, < 0.2.1 | 0.2.1 |
Vulnerability Intelligence
Miggo AI
Root Cause Analysis
The vulnerability (CVE-2025-5981) is an arbitrary file write due to path traversal in OSV-SCALIBR's container image unpacking functionality. This occurs when processing malicious container images, particularly via the --remote-image
CLI flag.
The root cause was the improper handling of file paths extracted from tar archive headers within container image layers. Specifically, paths were constructed by combining a base extraction directory with file/directory names from the tar entries. Insufficient sanitization of these names (e.g., not fully mitigating ../
sequences) allowed an attacker to craft tar entries that, when unpacked, would write files or create directories outside the intended extraction directory.
The patch (commit 2444419b1818c2d6917fc3394c947fb3276e9d59) addresses this by introducing the os.Root
API. This API provides a way to confine file system operations to a specific root directory, effectively creating a chroot-like jail for the unpacking process.
The key functions involved were:
(*Image).handleFile
: Pre-patch, this function usedos.OpenFile
with a potentially traversed path (realFilePath
) to write files. The patch changed this to useimg.root.OpenFile
, ensuring writes are contained.(*Image).handleDir
: Pre-patch, this function usedos.MkdirAll
with a potentially traversed path (realFilePath
) to create directories. The patch modified path handling and usesimg.root.Stat
to ensure operations are relative to the safe root.fillChainLayersWithFilesFromTar
: This function was responsible for reading tar entries and, pre-patch, for constructing therealFilePath
that was then passed tohandleFile
andhandleDir
. The logic for path cleaning here was insufficient. The patch removed this direct path construction, relying on theos.Root
context.FromV1Image
: This function orchestrates the image unpacking. The patch introduced the creation and use of anos.Root
object here, which is then used by the lower-level functions.
During exploitation, these functions (in their pre-patch state) would be on the call stack. handleFile
or handleDir
would be the functions directly executing the unsafe os.OpenFile
or os.MkdirAll
calls with the attacker-controlled path. The unpack()
function mentioned in the advisory likely calls FromV1Image
or a similar entry point that utilizes this vulnerable logic.
Vulnerable functions
github.com/google/osv-scalibr/artifact/image/layerscanning/image.(*Image).handleFile
artifact/image/layerscanning/image/image.go
github.com/google/osv-scalibr/artifact/image/layerscanning/image.(*Image).handleDir
artifact/image/layerscanning/image/image.go
github.com/google/osv-scalibr/artifact/image/layerscanning/image.fillChainLayersWithFilesFromTar
artifact/image/layerscanning/image/image.go
github.com/google/osv-scalibr/artifact/image/layerscanning/image.FromV1Image
artifact/image/layerscanning/image/image.go