rspec/rules/S2612/vbnet/rule.adoc

74 lines
2.1 KiB
Plaintext
Raw Normal View History

2021-02-09 12:11:03 +01:00
In Unix, "others" class refers to all users except the owner of the file and the members of the group assigned to this file.
In Windows, "Everyone" group is similar and includes all members of the Authenticated Users group as well as the built-in Guest account, and several other built-in security accounts.
Granting permissions to these groups can lead to unintended access to files.
include::../ask-yourself.adoc[]
include::../recommended.adoc[]
== Sensitive Code Example
.Net Framework:
----
Dim unsafeAccessRule = new FileSystemAccessRule("Everyone", FileSystemRights.FullControl, AccessControlType.Allow)
Dim fileSecurity = File.GetAccessControl("path")
fileSecurity.AddAccessRule(unsafeAccessRule) ' Sensitive
fileSecurity.SetAccessRule(unsafeAccessRule) ' Sensitive
File.SetAccessControl("fileName", fileSecurity)
2021-02-09 12:11:03 +01:00
----
.Net / .Net Core
----
2021-02-15 12:31:39 +01:00
Dim fileInfo = new FileInfo("path")
Dim fileSecurity = fileInfo.GetAccessControl()
fileSecurity.AddAccessRule(new FileSystemAccessRule("Everyone", FileSystemRights.Write, AccessControlType.Allow)) ' Sensitive
fileInfo.SetAccessControl(fileSecurity)
2021-02-09 12:11:03 +01:00
----
.Net / .Net Core using Mono.Posix.NETStandard
----
2021-02-15 12:31:39 +01:00
Dim fileSystemEntry = UnixFileSystemInfo.GetFileSystemEntry("path")
fileSystemEntry.FileAccessPermissions = FileAccessPermissions.OtherReadWriteExecute ' Sensitive
2021-02-09 12:11:03 +01:00
----
== Compliant Solution
.Net Framework
----
Dim safeAccessRule = new FileSystemAccessRule("Everyone", FileSystemRights.FullControl, AccessControlType.Deny)
Dim fileSecurity = File.GetAccessControl("path")
fileSecurity.AddAccessRule(safeAccessRule)
File.SetAccessControl("path", fileSecurity)
2021-02-09 12:11:03 +01:00
----
.Net / .Net Core
----
Dim safeAccessRule = new FileSystemAccessRule("Everyone", FileSystemRights.FullControl, AccessControlType.Deny)
2021-02-15 12:31:39 +01:00
Dim fileInfo = new FileInfo("path")
Dim fileSecurity = fileInfo.GetAccessControl()
fileSecurity.SetAccessRule(safeAccessRule)
fileInfo.SetAccessControl(fileSecurity)
2021-02-09 12:11:03 +01:00
----
.Net / .Net Core using Mono.Posix.NETStandard
----
2021-02-15 12:31:39 +01:00
Dim fs = UnixFileSystemInfo.GetFileSystemEntry("path")
fs.FileAccessPermissions = FileAccessPermissions.UserExecute
2021-02-09 12:11:03 +01:00
----
include::../see.adoc[]