Skip to content

Commit

Permalink
Merge pull request #427 from JoshCunninghame/kotlin_file_path_traversal
Browse files Browse the repository at this point in the history
Kotlin file path traversal sink signatures
  • Loading branch information
h3xstream committed Aug 13, 2018
2 parents 132639e + 02ce3b0 commit 5b164fa
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 0 deletions.
@@ -0,0 +1,43 @@
/**
* Find Security Bugs
* Copyright (c) Philippe Arteau, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
package com.h3xstream.findsecbugs.pathtraversal

import java.io.File
import java.io.IOException
import java.net.URISyntaxException

class PathTraversalKotlin {

@Throws(IOException::class, URISyntaxException::class)
fun main(args: Array<String>) {
val filepath = args[1]

// Unsafe
createTempDir(filepath, filepath)
createTempDir(filepath, filepath, File("static"))

createTempFile(filepath, filepath)
createTempFile(filepath, filepath, File("static"))

// Safe
createTempDir()
createTempFile()
createTempDir("static", "static")
createTempFile("static", "static")
}
}
Expand Up @@ -34,6 +34,7 @@ public PathTraversalDetector(BugReporter bugReporter) {
loadConfiguredSinks("path-traversal-in.txt", PATH_TRAVERSAL_IN_TYPE);
loadConfiguredSinks("path-traversal-out.txt", PATH_TRAVERSAL_OUT_TYPE);
loadConfiguredSinks("scala-path-traversal-in.txt", SCALA_PATH_TRAVERSAL_IN_TYPE);
loadConfiguredSinks("kotlin-path-traversal-in.txt", PATH_TRAVERSAL_IN_TYPE);

// We are not using a Scala-specific message because it doesn't have an embed code example
loadConfiguredSinks("scala-path-traversal-out.txt", PATH_TRAVERSAL_OUT_TYPE);
Expand Down
@@ -0,0 +1,4 @@
kotlin/io/FilesKt.createTempFile$default(Ljava/lang/String;Ljava/lang/String;Ljava/io/File;ILjava/lang/Object;)Ljava/io/File;:3,4
kotlin/io/FilesKt.createTempFile(Ljava/lang/String;Ljava/lang/String;Ljava/io/File;)Ljava/io/File;:0,1,2
kotlin/io/FilesKt.createTempDir$default(Ljava/lang/String;Ljava/lang/String;Ljava/io/File;ILjava/lang/Object;)Ljava/io/File;:3,4
kotlin/io/FilesKt.createTempDir(Ljava/lang/String;Ljava/lang/String;Ljava/io/File;)Ljava/io/File;:0,1,2
@@ -0,0 +1,53 @@
/**
* Find Security Bugs
* Copyright (c) Philippe Arteau, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
package com.h3xstream.findsecbugs.kotlin;

import com.h3xstream.findbugs.test.BaseDetectorTest;
import com.h3xstream.findbugs.test.EasyBugReporter;
import org.testng.annotations.Test;

import java.util.Arrays;

import static org.mockito.Mockito.*;

public class KotlinPathTraversalDetectorTest extends BaseDetectorTest {

@Test
public void detectPathTraversal() throws Exception {

//Locate test code
String[] files = {
getClassFilePath("com/h3xstream/findsecbugs/pathtraversal/PathTraversalKotlin")
};

//Run the analysis
EasyBugReporter reporter = spy(new SecurityReporter());
analyze(files, reporter);

for (Integer line : Arrays.asList(31, 32, 34, 35)) {
verify(reporter).doReportBug(
bugDefinition()
.bugType("PATH_TRAVERSAL_IN")
.inClass("PathTraversalKotlin").inMethod("main").atLine(line)
.build()
);
}

verify(reporter, times(4)).doReportBug(bugDefinition().bugType("PATH_TRAVERSAL_IN").build());
}
}

0 comments on commit 5b164fa

Please sign in to comment.