<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Apko (&lt; 1.2.5) — CraftedSignal Threat Feed</title><link>https://feed.craftedsignal.io/products/apko--1.2.5/</link><description>Trending threats, MITRE ATT&amp;CK coverage, and detection metadata — refreshed continuously.</description><generator>Hugo</generator><language>en</language><managingEditor>hello@craftedsignal.io</managingEditor><webMaster>hello@craftedsignal.io</webMaster><lastBuildDate>Tue, 02 Jan 2024 12:00:00 +0000</lastBuildDate><atom:link href="https://feed.craftedsignal.io/products/apko--1.2.5/feed.xml" rel="self" type="application/rss+xml"/><item><title>Apko DirFS Symlink Path Traversal Vulnerability</title><link>https://feed.craftedsignal.io/briefs/2024-01-apko-path-traversal/</link><pubDate>Tue, 02 Jan 2024 12:00:00 +0000</pubDate><author>hello@craftedsignal.io</author><guid isPermaLink="true">https://feed.craftedsignal.io/briefs/2024-01-apko-path-traversal/</guid><description>A symlink-following path traversal vulnerability exists in apko versions prior to 1.2.5 allowing a malicious .apk file to create a symbolic link pointing outside the build root and subsequently modify files on the host system.</description><content:encoded><![CDATA[<p>A path traversal vulnerability exists in apko&rsquo;s <code>DirFS</code> component, specifically within the <code>sanitizePath</code> helper function in versions prior to 1.2.5. The vulnerability allows a malicious <code>.apk</code> file to install a <code>TypeSymlink</code> tar entry pointing outside the intended build root. Subsequent directory creation or file writing operations could then traverse this symbolic link, leading to unauthorized access and modification of files on the host system. This issue affects users of apko and downstream tools, such as melange, that embed vulnerable versions of the <code>pkg/apk/fs</code> package. The vulnerability was addressed in apko version 1.2.5 with the introduction of <code>*os.Root</code>, which prevents path traversal.</p>
<h2 id="attack-chain">Attack Chain</h2>
<ol>
<li>An attacker crafts a malicious <code>.apk</code> file containing a <code>TypeSymlink</code> tar entry.</li>
<li>The symbolic link&rsquo;s target is set to a path outside the intended build root, potentially targeting sensitive system directories.</li>
<li>The malicious <code>.apk</code> is processed using a vulnerable version of apko (prior to 1.2.5) via commands like <code>apko build-cpio</code> or through disk-backed consumers such as <code>melange</code>.</li>
<li>During tar extraction, the vulnerable <code>sanitizePath</code> function fails to properly resolve or refuse the malicious symlink.</li>
<li>A subsequent directory-creation or file-write operation is initiated within the same or a later archive entry.</li>
<li>The file operation traverses the previously created symbolic link, gaining access to the file system location outside the intended build root.</li>
<li>The attacker can then create directories or write files to the compromised location, potentially overwriting critical system files or injecting malicious code.</li>
<li>Successful exploitation can lead to privilege escalation and persistent compromise of the host system.</li>
</ol>
<h2 id="impact">Impact</h2>
<p>Successful exploitation of this vulnerability allows an attacker to write files to arbitrary locations on the host system. This can lead to privilege escalation if the attacker can overwrite setuid binaries or modify system configuration files. It can also lead to persistent compromise of the system if the attacker injects malicious code into startup scripts or other system files. While the exact number of victims is unknown, any system running a vulnerable version of apko (prior to 1.2.5) or tools embedding vulnerable versions of <code>pkg/apk/fs</code>, such as melange, is potentially at risk.</p>
<h2 id="recommendation">Recommendation</h2>
<ul>
<li>Upgrade apko to version 1.2.5 or later. This version includes a fix that prevents path traversal vulnerabilities as described in the advisory and commit <a href="https://github.com/chainguard-dev/apko/commit/f5a96e1299ac81c7ea9441705ec467688086f442">f5a96e1</a>.</li>
<li>If upgrading is not immediately feasible, avoid consuming APKs from untrusted sources. However, note that this does not fully eliminate the risk.</li>
<li>Monitor file creation events in sensitive directories for unexpected activity, especially after processing <code>.apk</code> files.</li>
</ul>
]]></content:encoded><category domain="severity">high</category><category domain="type">advisory</category><category>path-traversal</category><category>symlink</category><category>apko</category><category>vulnerability</category><category>CVE-2026-42574</category></item></channel></rss>