Skip to content

Commit 4c56fe0

Browse files
owen-mcaschackmull
authored andcommitted
Convert path injection barrier to MaD
1 parent acecdc2 commit 4c56fe0

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

java/ql/lib/ext/java.io.model.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,8 @@ extensions:
162162
extensible: sourceModel
163163
data:
164164
- ["java.io", "FileInputStream", True, "FileInputStream", "", "", "Argument[this]", "file", "manual"]
165+
- addsTo:
166+
pack: codeql/java-all
167+
extensible: barrierModel
168+
data:
169+
- ["java.io", "File", True, "getName", "()", "", "ReturnValue", "path-injection", "manual"]

java/ql/lib/semmle/code/java/security/PathSanitizer.qll

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module;
44

55
import java
66
private import semmle.code.java.controlflow.Guards
7+
private import semmle.code.java.dataflow.ExternalFlow
78
private import semmle.code.java.dataflow.FlowSources
89
private import semmle.code.java.dataflow.SSA
910
private import semmle.code.java.frameworks.kotlin.IO
@@ -288,19 +289,8 @@ private Method getSourceMethod(Method m) {
288289
result = m
289290
}
290291

291-
/**
292-
* A sanitizer that protects against path injection vulnerabilities
293-
* by extracting the final component of the user provided path.
294-
*
295-
* TODO: convert this class to models-as-data if sanitizer support is added
296-
*/
297-
private class FileGetNameSanitizer extends PathInjectionSanitizer {
298-
FileGetNameSanitizer() {
299-
exists(MethodCall mc |
300-
mc.getMethod().hasQualifiedName("java.io", "File", "getName") and
301-
this.asExpr() = mc
302-
)
303-
}
292+
private class DefaultPathInjectionSanitizer extends PathInjectionSanitizer {
293+
DefaultPathInjectionSanitizer() { barrierNode(this, "path-injection") }
304294
}
305295

306296
/** Holds if `g` is a guard that checks for `..` components. */

0 commit comments

Comments
 (0)