Skip to content

Commit ef95654

Browse files
author
Manuel Ullmann
committed
Add powershell argument quote sanitizing in Firewall model.
Signed-off-by: Manuel Ullmann <manuel.ullmann@rediecon.com>
1 parent f92d09b commit ef95654

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Source/NETworkManager.Models/Firewall/Firewall.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ private bool ApplyRules(List<FirewallRule> rules)
4242
string nextRule = string.Empty;
4343
try
4444
{
45-
nextRule += $"New-NetFirewallRule -DisplayName '{rule.Name}'";
45+
nextRule += $"New-NetFirewallRule -DisplayName '{SanitizeStringArguments(rule.Name)}'";
4646
if (!string.IsNullOrEmpty(rule.Description))
47-
nextRule += $" -Description '{rule.Description}'";
47+
nextRule += $" -Description '{SanitizeStringArguments(rule.Description)}'";
4848
nextRule += $" -Direction {Enum.GetName(rule.Direction)}";
4949
if (rule.LocalPorts.Count > 0
5050
&& rule.Protocol is FirewallProtocol.TCP or FirewallProtocol.UDP)
@@ -64,7 +64,7 @@ private bool ApplyRules(List<FirewallRule> rules)
6464
try
6565
{
6666
if (File.Exists(rule.Program.Name))
67-
nextRule += $" -Program '{rule.Program.Name}'";
67+
nextRule += $" -Program '{SanitizeStringArguments(rule.Program.Name)}'";
6868
else
6969
continue;
7070
}
@@ -125,6 +125,11 @@ private static string GetClearAllRulesCommand()
125125
{
126126
return $"Remove-NetFirewallRule -DisplayName 'NwM_*'";
127127
}
128+
129+
private static string SanitizeStringArguments(string value)
130+
{
131+
return value.Replace("'", "''");
132+
}
128133

129134
/// <summary>
130135
/// Applies firewall rules asynchronously by invoking the ApplyRules method in a separate task.

0 commit comments

Comments
 (0)