Skip to content

Commit

Permalink
ab55018
Browse files Browse the repository at this point in the history
  • Loading branch information
leefine02 authored and leefine02 committed Mar 6, 2024
1 parent b53710b commit b964e8e
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 4 deletions.
2 changes: 2 additions & 0 deletions RemoteFile/ApplicationSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public enum FileTransferProtocolEnum

private const string DEFAULT_LINUX_PERMISSION_SETTING = "600";
private const string DEFAULT_OWNER_SETTING = "";
private const string DEFAULT_SUDO_IMPERSONATION_SETTING = "";

private static Dictionary<string,string> configuration;

Expand All @@ -36,6 +37,7 @@ public enum FileTransferProtocolEnum
public static string SeparateUploadFilePath { get { return configuration.ContainsKey("SeparateUploadFilePath") ? AddTrailingSlash(configuration["SeparateUploadFilePath"]) : string.Empty; } }
public static string DefaultLinuxPermissionsOnStoreCreation { get { return configuration.ContainsKey("DefaultLinuxPermissionsOnStoreCreation") ? configuration["DefaultLinuxPermissionsOnStoreCreation"] : DEFAULT_LINUX_PERMISSION_SETTING; } }
public static string DefaultOwnerOnStoreCreation { get { return configuration.ContainsKey("DefaultOwnerOnStoreCreation") ? configuration["DefaultOwnerOnStoreCreation"] : DEFAULT_OWNER_SETTING; } }
public static string DefaultSudoImpersonatedOwner { get { return configuration.ContainsKey("DefaultSudoImpersonatedOwner") ? configuration["DefaultSudoImpersonatedOwner"] : DEFAULT_SUDO_IMPERSONATION_SETTING; } }
public static FileTransferProtocolEnum FileTransferProtocol
{
get
Expand Down
26 changes: 23 additions & 3 deletions RemoteFile/RemoteCertificateStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ internal RemoteCertificateStore(string server, string serverId, string serverPas
UploadFilePath = !string.IsNullOrEmpty(ApplicationSettings.SeparateUploadFilePath) && ServerType == ServerTypeEnum.Linux ? ApplicationSettings.SeparateUploadFilePath : StorePath;
logger.LogDebug($"UploadFilePath: {UploadFilePath}");

if (!IsStorePathValid())
if (!IsValueSafeRegex(StorePath + StoreFileName))
{
logger.LogDebug("Store path not valid");
string partialMessage = ServerType == ServerTypeEnum.Windows ? @"'\', ':', " : string.Empty;
Expand Down Expand Up @@ -133,6 +133,14 @@ internal void Terminate()
internal List<string> FindStores(string[] paths, string[] extensions, string[] files, bool includeSymLinks)
{
logger.MethodEntry(LogLevel.Debug);

if (!AreValuesSafeRegex(paths))
throw new RemoteFileException("Invalid/unsafe directories to search value supplied.");
if (!AreValuesSafeRegex(extensions))
throw new RemoteFileException("Invalid/unsafe file extension value supplied.");
if (!AreValuesSafeRegex(files))
throw new RemoteFileException("Invalid/unsafe file name value supplied.");

logger.MethodExit(LogLevel.Debug);

if (DiscoveredStores != null)
Expand Down Expand Up @@ -342,15 +350,27 @@ internal void Initialize()
logger.MethodExit(LogLevel.Debug);
}

private bool IsStorePathValid()
private bool AreValuesSafeRegex(string[] values)
{
bool valueIsSafe = true;
foreach(string value in values)
{
valueIsSafe = IsValueSafeRegex(value);
if (!valueIsSafe)
break;
}
return valueIsSafe;
}

private bool IsValueSafeRegex(string value)
{
logger.MethodEntry(LogLevel.Debug);

Regex regex = new Regex(ServerType == ServerTypeEnum.Linux ? $@"^[\d\s\w-_/.]*$" : $@"^[\d\s\w-_/.:)(\\\\]*$");

logger.MethodExit(LogLevel.Debug);

return regex.IsMatch(StorePath + StoreFileName);
return regex.IsMatch(value);
}

private List<string> FindStoresLinux(string[] paths, string[] extensions, string[] fileNames, bool includeSymLinks)
Expand Down
2 changes: 1 addition & 1 deletion RemoteFile/RemoteHandlers/SSHHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public override string RunCommand(string commandText, object[] arguments, bool w
_logger.MethodEntry(LogLevel.Debug);
_logger.LogDebug($"RunCommand: {commandText}");

string sudo = $"sudo -i -S ";
string sudo = $"sudo -S ";
string echo = $"echo -e '\n' | ";

try
Expand Down
1 change: 1 addition & 0 deletions RemoteFile/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"UseSudo": "N",
"SudoImpersonatingUser": "",
"CreateStoreIfMissing": "N",
"UseNegotiate": "N",
"SeparateUploadFilePath": "",
Expand Down
48 changes: 48 additions & 0 deletions integration-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@
"DependsOn": "",
"Type": "String",
"DefaultValue": ""
},
{
"Name": "SudoImpersonatingUser",
"DisplayName": "Sudo Impersonating User",
"Required": false,
"DependsOn": "",
"Type": "String",
"DefaultValue": ""
}
],
"EntryParameters": []
Expand Down Expand Up @@ -110,6 +118,14 @@
"Type": "String",
"DefaultValue": ""
},
{
"Name": "SudoImpersonatingUser",
"DisplayName": "Sudo Impersonating User",
"Required": false,
"DependsOn": "",
"Type": "String",
"DefaultValue": ""
},
{
"Name": "IsTrustStore",
"DisplayName": "Trust Store",
Expand Down Expand Up @@ -190,6 +206,14 @@
"DependsOn": "",
"Type": "String",
"DefaultValue": ""
},
{
"Name": "SudoImpersonatingUser",
"DisplayName": "Sudo Impersonating User",
"Required": false,
"DependsOn": "",
"Type": "String",
"DefaultValue": ""
}
],
"EntryParameters": []
Expand Down Expand Up @@ -232,6 +256,14 @@
"Type": "String",
"DefaultValue": ""
},
{
"Name": "SudoImpersonatingUser",
"DisplayName": "Sudo Impersonating User",
"Required": false,
"DependsOn": "",
"Type": "String",
"DefaultValue": ""
},
{
"Name": "SeparatePrivateKeyFilePath",
"DisplayName": "Separate Private Key File Location",
Expand Down Expand Up @@ -280,6 +312,14 @@
"DependsOn": "",
"Type": "String",
"DefaultValue": ""
},
{
"Name": "SudoImpersonatingUser",
"DisplayName": "Sudo Impersonating User",
"Required": false,
"DependsOn": "",
"Type": "String",
"DefaultValue": ""
}
],
"EntryParameters": []
Expand Down Expand Up @@ -322,6 +362,14 @@
"Type": "String",
"DefaultValue": ""
},
{
"Name": "SudoImpersonatingUser",
"DisplayName": "Sudo Impersonating User",
"Required": false,
"DependsOn": "",
"Type": "String",
"DefaultValue": ""
},
{
"Name": "WorkFolder",
"DisplayName": "Location to use for creation/removal of work files",
Expand Down

0 comments on commit b964e8e

Please sign in to comment.