Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #427 from JoshCunninghame/kotlin_file_path_traversal
Kotlin file path traversal sink signatures
- Loading branch information
Showing
4 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
...est-kotlin/src/test/kotlin/com/h3xstream/findsecbugs/pathtraversal/PathTraversalKotlin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
plugin/src/main/resources/injection-sinks/kotlin-path-traversal-in.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
53 changes: 53 additions & 0 deletions
53
plugin/src/test/java/com/h3xstream/findsecbugs/kotlin/KotlinPathTraversalDetectorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
} |