Skip to content

Commit be58cb2

Browse files
committed
[Modify] Add some checks for the path
1 parent 5e28b6d commit be58cb2

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

websocket-sharp/Server/HttpServer.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1338,7 +1338,15 @@ public void AddWebSocketService<TBehaviorWithNew> (
13381338
/// <paramref name="path"/> is <see langword="null"/>.
13391339
/// </exception>
13401340
/// <exception cref="ArgumentException">
1341-
/// <paramref name="path"/> is an empty string.
1341+
/// <para>
1342+
/// <paramref name="path"/> is an empty string.
1343+
/// </para>
1344+
/// <para>
1345+
/// -or-
1346+
/// </para>
1347+
/// <para>
1348+
/// <paramref name="path"/> is an invalid path.
1349+
/// </para>
13421350
/// </exception>
13431351
public byte[] GetFile (string path)
13441352
{
@@ -1348,6 +1356,18 @@ public byte[] GetFile (string path)
13481356
if (path.Length == 0)
13491357
throw new ArgumentException ("An empty string.", "path");
13501358

1359+
if (path.IndexOf (':') > -1)
1360+
throw new ArgumentException ("It contains ':'.", "path");
1361+
1362+
if (path.IndexOf ("..") > -1)
1363+
throw new ArgumentException ("It contains '..'.", "path");
1364+
1365+
if (path.IndexOf ("//") > -1)
1366+
throw new ArgumentException ("It contains '//'.", "path");
1367+
1368+
if (path.IndexOf ("\\\\") > -1)
1369+
throw new ArgumentException ("It contains '\\\\'.", "path");
1370+
13511371
path = createFilePath (path);
13521372
return File.Exists (path) ? File.ReadAllBytes (path) : null;
13531373
}

0 commit comments

Comments
 (0)