Skip to content

Harden smali folder name validation during build to prevent path traversal - #4182

Draft
iBotPeaches with Copilot wants to merge 2 commits into
mainfrom
copilot/harden-smali-folder-during-build
Draft

Harden smali folder name validation during build to prevent path traversal#4182
iBotPeaches with Copilot wants to merge 2 commits into
mainfrom
copilot/harden-smali-folder-during-build

Conversation

Copilot AI commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Directories named smali_<suffix> in decoded projects are converted to dex output paths by replacing @ with the platform path separator. A malicious directory name like smali_..@..@..@outside produces ../../../outside.dex, enabling arbitrary file writes outside the build output directory.

Changes

  • ApkBuilder.java: After computing fileName from a smali_ directory name, validate the derived path using the existing BrutIO.sanitizePath(outDir, fileName). Throws AndrolibException if the resolved path escapes outDir.
} else if (dirName.startsWith("smali_")) {
    fileName = dirName.substring(dirName.indexOf('_') + 1).replace('@', File.separatorChar) + ".dex";
    try {
        BrutIO.sanitizePath(outDir, fileName);
    } catch (InvalidPathException | IOException ex) {
        throw new AndrolibException("Smali folder name leads to invalid dex path: "
            + dirName + " -> " + fileName, ex);
    }
}
  • SmaliDirectoryTraversalTest.java (new): Verifies that building a project containing a smali_..@..@..@outside directory throws AndrolibException rather than writing files outside the project.

Copilot AI linked an issue Jul 22, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Harden smali folder during build process Harden smali folder name validation during build to prevent path traversal Jul 22, 2026
Copilot AI requested a review from iBotPeaches July 22, 2026 15:49
@iBotPeaches
iBotPeaches force-pushed the copilot/harden-smali-folder-during-build branch from edf683e to e9697b1 Compare July 24, 2026 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Harden "smali" folder during build

2 participants