Skip to content

Commit 76b7bd4

Browse files
authored
[two bugs away] checking for invalid symbols in path (#250)
1 parent 12fb53c commit 76b7bd4

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

durablefunctionsmonitor.dotnetbackend/Common/Auth.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
using System.IdentityModel.Tokens.Jwt;
88
using System.IO;
99
using System.Linq;
10-
using System.Reflection;
1110
using System.Security.Claims;
1211
using System.Text.RegularExpressions;
1312
using System.Threading.Tasks;
13+
using System.Web;
1414
using Microsoft.AspNetCore.Http;
1515
using Microsoft.IdentityModel.Protocols;
1616
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
@@ -246,6 +246,20 @@ public static void ThrowIfTaskHubNameHasInvalidSymbols(string hubName)
246246
}
247247
}
248248

249+
// Checks that a path does not look malicious
250+
public static void ThrowIfPathHasInvalidSymbols(string path)
251+
{
252+
if (!string.IsNullOrEmpty(path))
253+
{
254+
string invalidSymbols = "{}()<>:;=";
255+
256+
if (invalidSymbols.Any(path.Contains) || invalidSymbols.Any(HttpUtility.UrlDecode(path).Contains))
257+
{
258+
throw new ArgumentException($"Path contains invalid characters.");
259+
}
260+
}
261+
}
262+
249263
// Checks that a Task Hub name is valid for this instace
250264
public static async Task ThrowIfTaskHubNameIsInvalid(string hubName)
251265
{

durablefunctionsmonitor.dotnetbackend/Functions/ServeStatics.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ private static async Task<ContentResult> ReturnIndexHtml(ExecutionContext contex
162162
routePrefix = requestPath.Substring(0, pos);
163163
}
164164
}
165+
// Two bugs away. Checking that route prefix does not look malicious.
166+
Auth.ThrowIfPathHasInvalidSymbols(routePrefix);
165167

166168
routePrefix = routePrefix?.Trim('/');
167169

durablefunctionsmonitor.dotnetisolated.core/Common/Auth.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Security.Claims;
77
using System.Text;
88
using System.Text.RegularExpressions;
9+
using System.Web;
910
using Microsoft.Azure.Functions.Worker.Http;
1011
using Microsoft.IdentityModel.Protocols;
1112
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
@@ -244,6 +245,20 @@ public static void ThrowIfTaskHubNameHasInvalidSymbols(string hubName)
244245
}
245246
}
246247

248+
// Checks that a path does not look malicious
249+
public static void ThrowIfPathHasInvalidSymbols(string path)
250+
{
251+
if (!string.IsNullOrEmpty(path))
252+
{
253+
string invalidSymbols = "{}()<>:;=";
254+
255+
if (invalidSymbols.Any(path.Contains) || invalidSymbols.Any(HttpUtility.UrlDecode(path).Contains))
256+
{
257+
throw new DfmUnauthorizedException($"Path contains invalid characters.");
258+
}
259+
}
260+
}
261+
247262
// Checks that a Task Hub name is valid for this instace
248263
public static async Task ThrowIfTaskHubNameIsInvalid(string hubName, DfmExtensionPoints extensionPoints)
249264
{

durablefunctionsmonitor.dotnetisolated.core/Functions/ServeStatics.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ private async Task<string> ReturnIndexHtml(ILogger log, string rootFolderName, s
167167
}
168168
}
169169

170+
// Two bugs away. Checking that route prefix does not look malicious.
171+
Auth.ThrowIfPathHasInvalidSymbols(routePrefix);
172+
170173
routePrefix = routePrefix?.Trim('/');
171174

172175
// Prepending ingress route prefix, if configured

0 commit comments

Comments
 (0)