Fix path security bug and added features
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using System.IO;
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
|
||||
namespace Tesses.WebServer
|
||||
{
|
||||
@@ -70,6 +71,20 @@ internal class SizedStream : Stream
|
||||
}
|
||||
public class ServerContext
|
||||
{
|
||||
const string bad_chars = "<>?/\\\"*|:";
|
||||
public static string FixFileName(string filename,bool requireAscii=false)
|
||||
{
|
||||
StringBuilder builder=new StringBuilder();
|
||||
foreach(var c in filename)
|
||||
{
|
||||
if(char.IsControl(c)) continue;
|
||||
if(requireAscii && c > 127) continue;
|
||||
if(bad_chars.Contains(c.ToString())) continue;
|
||||
builder.Append(c);
|
||||
}
|
||||
|
||||
return builder.ToString();
|
||||
}
|
||||
/// <summary>
|
||||
/// Some user data
|
||||
/// </summary>
|
||||
@@ -277,6 +292,10 @@ internal class SizedStream : Stream
|
||||
return new SizedStream(NetworkStream,len);
|
||||
}
|
||||
}
|
||||
else if(RequestHeaders.TryGetFirst("Transfer-Encoding",out var res) && res == "chunked")
|
||||
{
|
||||
return new ChunkedStream(NetworkStream,true);
|
||||
}
|
||||
//DajuricSimpleHttpExtensions.Print("Returns NetworkStream");
|
||||
return NetworkStream;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user