-
Notifications
You must be signed in to change notification settings - Fork 466
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 #712 from jbindel/master
taint-config files java-lang.txt and scala.txt propagate taint from character types
- Loading branch information
Showing
13 changed files
with
551 additions
and
20 deletions.
There are no files selected for viewing
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
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
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
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
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
52 changes: 52 additions & 0 deletions
52
...ugs-plugin/src/test/java/com/h3xstream/findsecbugs/scala/ScalaStringBuilderTaintTest.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,52 @@ | ||
/** | ||
* 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.scala; | ||
|
||
import com.h3xstream.findbugs.test.BaseDetectorTest; | ||
import com.h3xstream.findbugs.test.EasyBugReporter; | ||
import org.testng.annotations.Test; | ||
|
||
import static org.mockito.Mockito.*; | ||
|
||
public class ScalaStringBuilderTaintTest extends BaseDetectorTest { | ||
|
||
/** | ||
* Test the taint propagation for Scala StringBuilder | ||
* @throws Exception | ||
*/ | ||
@Test | ||
public void detectTaintedStringBuilder() throws Exception { | ||
|
||
//Locate test code | ||
String[] files = { | ||
getClassFilePath("bytecode_samples/scala_stringbuilder_taint.jar") | ||
}; | ||
|
||
//Run the analysis | ||
EasyBugReporter reporter = spy(new SecurityReporter()); | ||
analyze(files, reporter); | ||
|
||
//Assertions | ||
verify(reporter, times(1)).doReportBug( | ||
bugDefinition() | ||
.bugType("PATH_TRAVERSAL_IN") | ||
.inClass("ScalaStringBuilderTaint").inMethod("unsafeFileFromCharAppend") | ||
.build() | ||
); | ||
} | ||
} |
108 changes: 108 additions & 0 deletions
108
.../src/test/java/com/h3xstream/findsecbugs/taintanalysis/CharacterTaintPropagationTest.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,108 @@ | ||
/** | ||
* 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.taintanalysis; | ||
|
||
import com.h3xstream.findbugs.test.BaseDetectorTest; | ||
import com.h3xstream.findbugs.test.EasyBugReporter; | ||
import org.testng.annotations.Test; | ||
|
||
import static org.testng.Assert.assertTrue; | ||
|
||
import static org.mockito.Mockito.*; | ||
|
||
public class CharacterTaintPropagationTest extends BaseDetectorTest { | ||
|
||
@Test | ||
public void validateCharacterTaintPropagation() throws Exception { | ||
//Locate test code | ||
String[] files = { getClassFilePath("testcode/taint/CharacterTaintPropagation") }; | ||
|
||
//Run the analysis | ||
EasyBugReporter reporter = spy(new SecurityReporter()); | ||
|
||
analyze(files, reporter); | ||
|
||
verify(reporter, times(9)).doReportBug( | ||
bugDefinition().bugType("PATH_TRAVERSAL_IN").build()); | ||
|
||
verify(reporter, times(1)).doReportBug( | ||
bugDefinition().bugType("PATH_TRAVERSAL_IN") | ||
.inClass("CharacterTaintPropagation").inMethod("unsafeFileFromCharConcat") | ||
.withPriority("Medium") | ||
.build()); | ||
|
||
verify(reporter, times(1)).doReportBug( | ||
bugDefinition().bugType("PATH_TRAVERSAL_IN") | ||
.inClass("CharacterTaintPropagation").inMethod("unsafeFileFromChar") | ||
.withPriority("Medium") | ||
.build()); | ||
|
||
verify(reporter, times(1)).doReportBug( | ||
bugDefinition().bugType("PATH_TRAVERSAL_IN") | ||
.inClass("CharacterTaintPropagation").inMethod("unsafeFileFromCharToString") | ||
.withPriority("Medium") | ||
.build()); | ||
|
||
verify(reporter, times(1)).doReportBug( | ||
bugDefinition().bugType("PATH_TRAVERSAL_IN") | ||
.inClass("CharacterTaintPropagation").inMethod("unsafeFileFromCharGetName") | ||
.withPriority("Medium") | ||
.build()); | ||
|
||
verify(reporter, times(1)).doReportBug( | ||
bugDefinition().bugType("PATH_TRAVERSAL_IN") | ||
.inClass("CharacterTaintPropagation").inMethod("unsafeFileFromCharStringBuilder") | ||
.withPriority("Medium") | ||
.build()); | ||
|
||
verify(reporter, times(1)).doReportBug( | ||
bugDefinition().bugType("PATH_TRAVERSAL_IN") | ||
.inClass("CharacterTaintPropagation").inMethod("unsafeFileFromCharStringBuffer") | ||
.withPriority("Medium") | ||
.build()); | ||
|
||
verify(reporter, times(1)).doReportBug( | ||
bugDefinition().bugType("PATH_TRAVERSAL_IN") | ||
.inClass("CharacterTaintPropagation").inMethod("unsafeFileFromCharacterToString") | ||
.withPriority("Medium") | ||
.build()); | ||
|
||
verify(reporter, times(1)).doReportBug( | ||
bugDefinition().bugType("PATH_TRAVERSAL_IN") | ||
.inClass("CharacterTaintPropagation").inMethod("unsafeFileFromCharacterConcat") | ||
.withPriority("Medium") | ||
.build()); | ||
|
||
verify(reporter, times(1)).doReportBug( | ||
bugDefinition().bugType("PATH_TRAVERSAL_IN") | ||
.inClass("CharacterTaintPropagation").inMethod("unsafeFileFromString") | ||
.withPriority("Medium") | ||
.build()); | ||
|
||
verify(reporter, never()).doReportBug( | ||
bugDefinition().bugType("PATH_TRAVERSAL_IN") | ||
.inClass("CharacterTaintPropagation").inMethod("safeFileFromConstant") | ||
.build()); | ||
|
||
verify(reporter, never()).doReportBug( | ||
bugDefinition().bugType("PATH_TRAVERSAL_IN") | ||
.inClass("CharacterTaintPropagation").inMethod("safeFileFromConstantWithInt") | ||
.build()); | ||
|
||
} | ||
} |
Oops, something went wrong.