Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dotnet/src/dotnetframework/GxClasses/Core/GXUtilsCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ public class StringUtil
static char[] numbersAndSep = new char[] { '1', '2', '3', '4', '5', '6', '7', '8', '9', '-' };
static char[] numbers = new char[] { '1', '2', '3', '4', '5', '6', '7', '8', '9' };
internal static Dictionary<char, char> LogUserEntryWhiteList = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz123456789+-_=/[]{}\":, ".ToDictionary(item => item, item => item);
internal static Dictionary<char, char> HostWhiteList = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz123456789./".ToDictionary(item => item, item => item);
internal static Dictionary<char, char> HttpHeaderWhiteList = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz123456789./;-@(){}[]?,<>\\".ToDictionary(item => item, item => item);

internal static string Sanitize(string input, Dictionary<char, char> WhiteList)
{
Expand Down
17 changes: 8 additions & 9 deletions dotnet/src/dotnetframework/GxClasses/Helpers/HttpHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ static void CorsValuesToHeaders(OutgoingWebResponseContext httpResponse, string[
httpResponse.Headers[HeaderNames.AccessControlAllowCredentials] = true.ToString();

if (!string.IsNullOrEmpty(requestHeaders))
httpResponse.Headers[HeaderNames.AccessControlAllowHeaders] = requestHeaders;
httpResponse.Headers[HeaderNames.AccessControlAllowHeaders] = StringUtil.Sanitize(requestHeaders, StringUtil.HttpHeaderWhiteList);

if (!string.IsNullOrEmpty(requestMethods))
httpResponse.Headers[HeaderNames.AccessControlAllowMethods] = requestMethods;
httpResponse.Headers[HeaderNames.AccessControlAllowMethods] = StringUtil.Sanitize(requestMethods, StringUtil.HttpHeaderWhiteList);

httpResponse.Headers[HeaderNames.AccessControlMaxAge] = CORS_MAX_AGE_SECONDS;

Expand All @@ -150,10 +150,10 @@ static void CorsValuesToHeaders(HttpResponseMessageProperty httpResponse, string
httpResponse.Headers[HeaderNames.AccessControlAllowCredentials] = true.ToString();

if (!string.IsNullOrEmpty(requestHeaders))
httpResponse.Headers[HeaderNames.AccessControlAllowHeaders] = requestHeaders;
httpResponse.Headers[HeaderNames.AccessControlAllowHeaders] = StringUtil.Sanitize(requestHeaders, StringUtil.HttpHeaderWhiteList);

if (!string.IsNullOrEmpty(requestMethods))
httpResponse.Headers[HeaderNames.AccessControlAllowMethods] = requestMethods;
httpResponse.Headers[HeaderNames.AccessControlAllowMethods] = StringUtil.Sanitize(requestMethods, StringUtil.HttpHeaderWhiteList);

httpResponse.Headers[HeaderNames.AccessControlMaxAge] = CORS_MAX_AGE_SECONDS;
}
Expand All @@ -170,10 +170,10 @@ static void CorsValuesToHeaders(HttpResponse httpResponse, string[] origins, str
httpResponse.AppendHeader(HeaderNames.AccessControlAllowCredentials, true.ToString());

if (!string.IsNullOrEmpty(requestHeaders))
httpResponse.AppendHeader(HeaderNames.AccessControlAllowHeaders, requestHeaders);
httpResponse.AppendHeader(HeaderNames.AccessControlAllowHeaders, StringUtil.Sanitize(requestHeaders, StringUtil.HttpHeaderWhiteList));

if (!string.IsNullOrEmpty(requestMethods))
httpResponse.AppendHeader(HeaderNames.AccessControlAllowMethods, requestMethods);
httpResponse.AppendHeader(HeaderNames.AccessControlAllowMethods, StringUtil.Sanitize(requestMethods, StringUtil.HttpHeaderWhiteList));

httpResponse.AppendHeader(HeaderNames.AccessControlMaxAge, CORS_MAX_AGE_SECONDS);
}
Expand All @@ -193,7 +193,7 @@ public static void SetResponseStatus(HttpContext httpContext, HttpStatusCode htt
{
wcfcontext.OutgoingResponse.StatusCode = httpStatusCode;
if (httpStatusCode==HttpStatusCode.Unauthorized){
wcfcontext.OutgoingResponse.Headers.Add(HttpHeader.AUTHENTICATE_HEADER, OatuhUnauthorizedHeader(StringUtil.Sanitize(wcfcontext.IncomingRequest.Headers["Host"],StringUtil.HostWhiteList), httpStatusCode.ToString(INT_FORMAT), string.Empty));
wcfcontext.OutgoingResponse.Headers.Add(HttpHeader.AUTHENTICATE_HEADER, OatuhUnauthorizedHeader(StringUtil.Sanitize(wcfcontext.IncomingRequest.Headers["Host"],StringUtil.HttpHeaderWhiteList), httpStatusCode.ToString(INT_FORMAT), string.Empty));
}
if (!string.IsNullOrEmpty(statusDescription))
wcfcontext.OutgoingResponse.StatusDescription = statusDescription.Replace(Environment.NewLine, string.Empty);
Expand All @@ -211,7 +211,7 @@ public static void SetResponseStatus(HttpContext httpContext, HttpStatusCode htt
#endif
if (httpStatusCode == HttpStatusCode.Unauthorized)
{
httpContext.Response.Headers[HttpHeader.AUTHENTICATE_HEADER] = HttpHelper.OatuhUnauthorizedHeader(StringUtil.Sanitize(httpContext.Request.Headers["Host"], StringUtil.HostWhiteList), httpStatusCode.ToString(INT_FORMAT), string.Empty);
httpContext.Response.Headers[HttpHeader.AUTHENTICATE_HEADER] = HttpHelper.OatuhUnauthorizedHeader(StringUtil.Sanitize(httpContext.Request.Headers["Host"], StringUtil.HttpHeaderWhiteList), httpStatusCode.ToString(INT_FORMAT), string.Empty);
}

#if !NETCORE
Expand Down Expand Up @@ -447,7 +447,6 @@ public static string[] GetParameterValues(string query)
return query.Split(',');
}
}

internal static void AllowHeader(HttpContext httpContext, List<string> methods)
{
httpContext.Response.AppendHeader(HeaderNames.Allow, string.Join(",", methods));
Expand Down