Skip to content
This repository was archived by the owner on Oct 14, 2021. It is now read-only.

Commit 3758a7f

Browse files
authored
Avoid false negative on WhiteList with multiple points on path (#61)
1 parent adbc275 commit 3758a7f

File tree

2 files changed

+11
-28
lines changed

2 files changed

+11
-28
lines changed

dotnet/dotnetframework/SecurityAPICommons/Utils/ExtensionsWhiteList.cs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ public void SetExtension(string value)
2828
[SecuritySafeCritical]
2929
public bool IsValid(string path)
3030
{
31-
if (!IsValidName(path))
32-
{
33-
return false;
34-
}
3531
string ext = SecurityUtils.getFileExtension(path);
3632
for (int i = 0; i < this.whitelist.Count; i++)
3733
{
@@ -53,23 +49,5 @@ public bool IsEmpty()
5349
return false;
5450
}
5551

56-
private bool IsValidName(string path)
57-
{
58-
int counter = 0;
59-
int i = 0;
60-
while (i < path.Length && counter <= 2)
61-
{
62-
if (path[i] == '.')
63-
{
64-
counter++;
65-
}
66-
i++;
67-
}
68-
if (counter >= 2)
69-
{
70-
return false;
71-
}
72-
return true;
73-
}
7452
}
7553
}

dotnet/dotnetframework/SecurityAPICommons/Utils/SecurityUtils.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Org.BouncyCastle.Utilities.Encoders;
33
using SecurityAPICommons.Commons;
44
using System;
5+
using System.IO;
56
using System.Security;
67

78
namespace SecurityAPICommons.Utils
@@ -49,13 +50,17 @@ public static bool extensionIs(string path, string ext)
4950
[SecuritySafeCritical]
5051
public static string getFileExtension(string path)
5152
{
52-
53-
int lastIndexOf = path.LastIndexOf(".");
54-
if (lastIndexOf == -1)
55-
{
56-
return ""; // empty extension
53+
string fileName = Path.GetFileName(path);
54+
string extension;
55+
try
56+
{
57+
extension = Path.GetExtension(fileName);
5758
}
58-
return path.Substring(lastIndexOf);
59+
catch(Exception)
60+
{
61+
extension = "";
62+
}
63+
return extension;
5964
}
6065

6166
[SecuritySafeCritical]

0 commit comments

Comments
 (0)