Skip to content

Commit 5950fbd

Browse files
vuln-fix: Partial Path Traversal Vulnerability
This fixes a partial path traversal vulnerability. Replaces `dir.getCanonicalPath().startsWith(parent.getCanonicalPath())`, which is vulnerable to partial path traversal attacks, with the more secure `dir.getCanonicalFile().toPath().startsWith(parent.getCanonicalFile().toPath())`. To demonstrate this vulnerability, consider `"/usr/outnot".startsWith("/usr/out")`. The check is bypassed although `/outnot` is not under the `/out` directory. It's important to understand that the terminating slash may be removed when using various `String` representations of the `File` object. For example, on Linux, `println(new File("/var"))` will print `/var`, but `println(new File("/var", "/")` will print `/var/`; however, `println(new File("/var", "/").getCanonicalPath())` will print `/var`. Weakness: CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') Severity: Medium CVSSS: 6.1 Detection: CodeQL & OpenRewrite (https://public.moderne.io/recipes/org.openrewrite.java.security.PartialPathTraversalVulnerability) Reported-by: Jonathan Leitschuh <[email protected]> Signed-off-by: Jonathan Leitschuh <[email protected]> Bug-tracker: JLLeitschuh/security-research#13 Co-authored-by: Moderne <[email protected]>
1 parent acaf0ee commit 5950fbd

File tree

1 file changed

+1
-2
lines changed
  • src/main/java/com/simpligility/maven/plugins/android/phase09package

1 file changed

+1
-2
lines changed

src/main/java/com/simpligility/maven/plugins/android/phase09package/ApklibMojo.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,9 @@ protected void addJavaResource( JarArchiver jarArchiver, Resource javaResource,
258258
final File javaResourceDirectory = new File( javaResource.getDirectory() );
259259
if ( javaResourceDirectory.exists() )
260260
{
261-
final String resourcePath = javaResourceDirectory.getCanonicalPath();
262261
final String apkLibUnpackBasePath = getUnpackedLibsDirectory().getCanonicalPath();
263262
// Don't include our dependencies' resource dirs.
264-
if ( ! resourcePath.startsWith( apkLibUnpackBasePath ) )
263+
if ( ! javaResourceDirectory.getCanonicalFile().toPath().startsWith(apkLibUnpackBasePath) )
265264
{
266265
final DefaultFileSet javaResourceFileSet = new DefaultFileSet();
267266
javaResourceFileSet.setDirectory( javaResourceDirectory );

0 commit comments

Comments
 (0)