2021-01-26 04:07:35 +00:00
|
|
|
include::../description.adoc[]
|
|
|
|
|
|
|
|
include::../ask-yourself.adoc[]
|
|
|
|
|
|
|
|
include::../recommended.adoc[]
|
|
|
|
|
|
|
|
== Sensitive Code Example
|
|
|
|
|
|
|
|
----
|
|
|
|
new File("/tmp/myfile.txt"); // Sensitive
|
|
|
|
Paths.get("/tmp/myfile.txt"); // Sensitive
|
|
|
|
|
|
|
|
java.io.File.createTempFile("prefix", "suffix"); // Sensitive, will be in the default temporary-file directory.
|
|
|
|
java.nio.file.Files.createTempDirectory("prefix"); // Sensitive, will be in the default temporary-file directory.
|
|
|
|
----
|
|
|
|
|
|
|
|
----
|
|
|
|
Map<String, String> env = System.getenv();
|
|
|
|
env.get("TMP"); // Sensitive
|
|
|
|
----
|
|
|
|
|
|
|
|
== Compliant Solution
|
|
|
|
|
2022-02-04 17:28:24 +01:00
|
|
|
[source,java]
|
2021-01-26 04:07:35 +00:00
|
|
|
----
|
2021-05-05 08:56:28 +00:00
|
|
|
new File("/myDirectory/myfile.txt"); // Compliant
|
|
|
|
|
|
|
|
File.createTempFile("prefix", "suffix", new File("/mySecureDirectory")); // Compliant
|
|
|
|
|
|
|
|
if(SystemUtils.IS_OS_UNIX) {
|
|
|
|
FileAttribute<Set<PosixFilePermission>> attr = PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rwx------"));
|
|
|
|
Files.createTempFile("prefix", "suffix", attr); // Compliant
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
File f = Files.createTempFile("prefix", "suffix").toFile(); // Compliant
|
|
|
|
f.setReadable(true, true);
|
|
|
|
f.setWritable(true, true);
|
|
|
|
f.setExecutable(true, true);
|
|
|
|
}
|
2021-01-26 04:07:35 +00:00
|
|
|
----
|
|
|
|
|
|
|
|
include::../see.adoc[]
|
2021-06-02 20:44:38 +02:00
|
|
|
|
2021-06-03 09:05:38 +02:00
|
|
|
ifdef::env-github,rspecator-view[]
|
2021-09-20 15:38:42 +02:00
|
|
|
|
|
|
|
'''
|
|
|
|
== Implementation Specification
|
|
|
|
(visible only on this page)
|
|
|
|
|
|
|
|
include::../message.adoc[]
|
|
|
|
|
2021-06-08 15:52:13 +02:00
|
|
|
'''
|
2021-06-02 20:44:38 +02:00
|
|
|
== Comments And Links
|
|
|
|
(visible only on this page)
|
|
|
|
|
|
|
|
include::../comments-and-links.adoc[]
|
2023-06-22 10:38:01 +02:00
|
|
|
|
2021-06-03 09:05:38 +02:00
|
|
|
endif::env-github,rspecator-view[]
|