Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a8d25b6

Browse files
JLLeitschuhsmowton
andcommitted
Apply suggestions from code review
Co-authored-by: Chris Smowton <[email protected]>
1 parent e795823 commit a8d25b6

3 files changed

Lines changed: 18 additions & 19 deletions

File tree

java/ql/src/Security/CWE/CWE-200/TempDirLocalInformationDisclosureFromMethodCall.ql

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/**
2-
* @name Temporary directory local information disclosure
3-
* @description Writing information without explicit permissions to a shared temporary directory may disclose it to other users.
2+
* @name Temporary directory local information disclosure (file creation via inherently insecure method)
3+
* @description Creating a temporary file in the system shared temporary directory, using a method that always creates it world-readable, may disclose its contents to other users.
44
* @kind problem
55
* @problem.severity warning
66
* @precision very-high
7-
* @id java/local-temp-file-or-directory-information-disclosure-method
7+
* @id java/local-temp-file-or-directory-information-disclosure-insecure-method
88
* @tags security
99
* external/cwe/cwe-200
1010
* external/cwe/cwe-732
@@ -15,21 +15,22 @@ import TempDirUtils
1515

1616
abstract class MethodAccessInsecureFileCreation extends MethodAccess {
1717
/**
18-
* Docstring describing the file system type (ie. file, directory, etc...) returned.
18+
* Gets the type of entity created (e.g. `file`, `directory`, ...).
1919
*/
20-
abstract string getFileSystemType();
20+
abstract string getFileSystemEntityType();
2121
}
2222

2323
/**
24-
* Insecure calls to `java.io.File::createTempFile`.
24+
* An insecure call to `java.io.File::createTempFile`.
2525
*/
2626
class MethodAccessInsecureFileCreateTempFile extends MethodAccessInsecureFileCreation {
2727
MethodAccessInsecureFileCreateTempFile() {
2828
this.getMethod() instanceof MethodFileCreateTempFile and
2929
(
30+
// `File.createTempFile(string, string)` always uses the default temporary directory
3031
this.getNumArgument() = 2
3132
or
32-
// Vulnerablilty exists when the last argument is `null`
33+
// The default temporary directory is used when the last argument of `File.createTempFile(string, string, File)` is `null`
3334
getArgument(2) instanceof NullLiteral
3435
)
3536
}

java/ql/src/Security/CWE/CWE-200/TempDirLocalInformationDisclosureFromSystemProperty.ql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/**
2-
* @name Temporary Directory Local information disclosure
3-
* @description Writing information without explicit permissions to a shared temporary directory may disclose it to other users.
2+
* @name Temporary directory local information disclosure (file creation without explicit mode)
3+
* @description Creating a temporary file in the system shared temporary directory without specifying explicit access rights (mode) may disclose its contents to other users.
44
* @kind path-problem
55
* @problem.severity warning
66
* @precision very-high
7-
* @id java/local-temp-file-or-directory-information-disclosure-path
7+
* @id java/local-temp-file-or-directory-information-disclosure-missing-mode
88
* @tags security
99
* external/cwe/cwe-200
1010
* external/cwe/cwe-732
@@ -36,7 +36,7 @@ private class FileFileCreationSink extends FileCreationSink {
3636
}
3737

3838
/**
39-
* Sink for if tained File/Path having some `Files` method called on it that creates a file or directory.
39+
* Sink for calling a file-creating or directory-creating `Files` method on a tainted `File` or `Path`.
4040
*/
4141
private class FilesFileCreationSink extends FileCreationSink {
4242
FilesFileCreationSink() {
@@ -63,7 +63,7 @@ private class FilesVulnerableCreationMethodAccess extends MethodAccess {
6363
}
6464

6565
/**
66-
* A call to `java.io.File::createTempFile` where the the system temp dir sinks to the last argument.
66+
* The temp directory argument to a call to `java.io.File::createTempFile`, treated as a sink by `TempDirSystemGetPropertyToCreateConfig`.
6767
*/
6868
private class FileCreateTempFileSink extends FileCreationSink {
6969
FileCreateTempFileSink() {

java/ql/src/Security/CWE/CWE-200/TempDirUtils.qll

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,23 +63,21 @@ private predicate isTaintedFileCreation(Expr expSource, Expr exprDest) {
6363
private class TaintFollowingFileMethod extends Method {
6464
TaintFollowingFileMethod() {
6565
getDeclaringType() instanceof TypeFile and
66-
(
67-
hasName("getAbsoluteFile") or
68-
hasName("getCanonicalFile")
69-
)
66+
hasName(["getAbsoluteFile", "getCanonicalFile"])
7067
}
7168
}
7269

73-
private predicate isTaintFollowingFileTransformation(Expr expSource, Expr exprDest) {
70+
private predicate isTaintPropagatingFileTransformation(Expr expSource, Expr exprDest) {
7471
exists(MethodAccess fileMethodAccess |
75-
fileMethodAccess.getMethod() instanceof TaintFollowingFileMethod and
72+
fileMethodAccess.getMethod() instanceof TaintPropagatingFileMethod and
7673
fileMethodAccess.getQualifier() = expSource and
7774
fileMethodAccess = exprDest
7875
)
7976
}
8077

8178
/**
82-
* Holds if the system temporary directory is still part of the root of the file path.
79+
* Holds if taint should propagate from `node1` to `node2` across some file creation or transformation operation.
80+
* For example, `taintedFile.getCanonicalFile()` is itself tainted.
8381
*/
8482
predicate isAdditionalFileTaintStep(DataFlow::Node node1, DataFlow::Node node2) {
8583
isTaintedFileCreation(node1.asExpr(), node2.asExpr()) or

0 commit comments

Comments
 (0)