Java: add File.getName as a path injection sanitizer

This commit is contained in:
Jami Cogswell
2024-12-04 16:56:49 -05:00
parent ccfb32e989
commit 121780c55a
2 changed files with 30 additions and 0 deletions

View File

@@ -333,3 +333,18 @@ private Method getSourceMethod(Method m) {
not exists(Method src | m = src.getKotlinParameterDefaultsProxy()) and
result = m
}
/**
* A sanitizer that protects against path injection vulnerabilities
* by extracting the final component of the user provided path.
*
* TODO: convert this class to models-as-data if sanitizer support is added
*/
private class FileGetNameSanitizer extends PathInjectionSanitizer {
FileGetNameSanitizer() {
exists(MethodCall mc |
mc.getMethod().hasQualifiedName("java.io", "File", "getName") and
this.asExpr() = mc
)
}
}