2020-06-30 12:48:07 +02:00
|
|
|
include::../description.adoc[]
|
|
|
|
|
|
|
|
include::../ask-yourself.adoc[]
|
|
|
|
|
|
|
|
include::../recommended.adoc[]
|
|
|
|
|
|
|
|
== Sensitive Code Example
|
|
|
|
|
|
|
|
----
|
|
|
|
public void setPermissions(String filePath) {
|
|
|
|
Set<PosixFilePermission> perms = new HashSet<PosixFilePermission>();
|
|
|
|
// user permission
|
|
|
|
perms.add(PosixFilePermission.OWNER_READ);
|
|
|
|
perms.add(PosixFilePermission.OWNER_WRITE);
|
|
|
|
perms.add(PosixFilePermission.OWNER_EXECUTE);
|
|
|
|
// group permissions
|
|
|
|
perms.add(PosixFilePermission.GROUP_READ);
|
|
|
|
perms.add(PosixFilePermission.GROUP_EXECUTE);
|
|
|
|
// others permissions
|
|
|
|
perms.add(PosixFilePermission.OTHERS_READ); // Sensitive
|
|
|
|
perms.add(PosixFilePermission.OTHERS_WRITE); // Sensitive
|
|
|
|
perms.add(PosixFilePermission.OTHERS_EXECUTE); // Sensitive
|
|
|
|
|
|
|
|
Files.setPosixFilePermissions(Paths.get(filePath), perms);
|
|
|
|
}
|
|
|
|
----
|
|
|
|
|
|
|
|
----
|
|
|
|
public void setPermissionsUsingRuntimeExec(String filePath) {
|
|
|
|
Runtime.getRuntime().exec("chmod 777 file.json"); // Sensitive
|
|
|
|
}
|
|
|
|
----
|
|
|
|
|
|
|
|
----
|
|
|
|
public void setOthersPermissionsHardCoded(String filePath ) {
|
|
|
|
Files.setPosixFilePermissions(Paths.get(filePath), PosixFilePermissions.fromString("rwxrwxrwx")); // Sensitive
|
|
|
|
}
|
|
|
|
----
|
|
|
|
|
|
|
|
== Compliant Solution
|
|
|
|
|
2021-01-27 13:42:22 +01:00
|
|
|
On operating systems that implement POSIX standard. This will throw a ``++UnsupportedOperationException++`` on Windows.
|
2020-06-30 12:48:07 +02:00
|
|
|
|
2021-02-02 15:02:10 +01:00
|
|
|
|
2022-02-04 17:28:24 +01:00
|
|
|
[source,java]
|
2020-06-30 12:48:07 +02:00
|
|
|
----
|
|
|
|
public void setPermissionsSafe(String filePath) throws IOException {
|
|
|
|
Set<PosixFilePermission> perms = new HashSet<PosixFilePermission>();
|
|
|
|
// user permission
|
|
|
|
perms.add(PosixFilePermission.OWNER_READ);
|
|
|
|
perms.add(PosixFilePermission.OWNER_WRITE);
|
|
|
|
perms.add(PosixFilePermission.OWNER_EXECUTE);
|
|
|
|
// group permissions
|
|
|
|
perms.add(PosixFilePermission.GROUP_READ);
|
|
|
|
perms.add(PosixFilePermission.GROUP_EXECUTE);
|
|
|
|
// others permissions removed
|
|
|
|
perms.remove(PosixFilePermission.OTHERS_READ); // Compliant
|
|
|
|
perms.remove(PosixFilePermission.OTHERS_WRITE); // Compliant
|
|
|
|
perms.remove(PosixFilePermission.OTHERS_EXECUTE); // Compliant
|
|
|
|
|
|
|
|
Files.setPosixFilePermissions(Paths.get(filePath), perms);
|
|
|
|
}
|
|
|
|
----
|
|
|
|
|
2021-09-21 15:40:35 +02:00
|
|
|
== See
|
|
|
|
|
2021-11-01 15:00:32 +01:00
|
|
|
* https://owasp.org/Top10/A01_2021-Broken_Access_Control/[OWASP Top 10 2021 Category A1] - Broken Access Control
|
|
|
|
* https://owasp.org/Top10/A03_2021-Injection/[OWASP Top 10 2021 Category A4] - Insecure Design
|
2021-09-21 15:40:35 +02:00
|
|
|
* https://www.owasp.org/index.php/Top_10-2017_A5-Broken_Access_Control[OWASP Top 10 2017 Category A5] - Broken Access Control
|
|
|
|
* https://www.owasp.org/index.php/Test_File_Permission_(OTG-CONFIG-009)[OWASP File Permission]
|
2021-10-28 10:07:16 +02:00
|
|
|
* https://cwe.mitre.org/data/definitions/732.html[MITRE, CWE-732] - Incorrect Permission Assignment for Critical Resource
|
2021-09-21 15:40:35 +02:00
|
|
|
* https://cwe.mitre.org/data/definitions/266.html[MITRE, CWE-266] - Incorrect Privilege Assignment
|
|
|
|
* https://wiki.sei.cmu.edu/confluence/display/java/FIO01-J.+Create+files+with+appropriate+access+permissions[CERT, FIO01-J.] - Create files with appropriate access permissions
|
|
|
|
* https://wiki.sei.cmu.edu/confluence/display/c/FIO06-C.+Create+files+with+appropriate+access+permissions[CERT, FIO06-C.] - Create files with appropriate access permissions
|
|
|
|
* https://www.sans.org/top25-software-errors/#cat3[SANS Top 25] - Porous Defenses
|
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[]
|
2021-06-03 09:05:38 +02:00
|
|
|
endif::env-github,rspecator-view[]
|