Skip to content

Commit deb8616

Browse files
Adding a check for uri. (#10993)
1 parent c09df1a commit deb8616

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

src/WebJobs.Script.WebHost/Middleware/SystemTraceMiddleware.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

44
using System;
5-
using System.Diagnostics;
6-
using System.IO;
75
using System.Linq;
86
using System.Text;
97
using System.Threading.Tasks;
108
using Microsoft.AspNetCore.Http;
9+
using Microsoft.Azure.WebJobs.Logging;
1110
using Microsoft.Azure.WebJobs.Script.Diagnostics;
1211
using Microsoft.Azure.WebJobs.Script.Extensions;
1312
using Microsoft.Azure.WebJobs.Script.WebHost.Diagnostics.Extensions;
@@ -33,7 +32,7 @@ public async Task Invoke(HttpContext context)
3332

3433
var sw = ValueStopwatch.StartNew();
3534
string userAgent = context.Request.GetHeaderValueOrDefault("User-Agent");
36-
_logger.ExecutingHttpRequest(requestId, context.Request.Method, userAgent, context.Request.Path);
35+
_logger.ExecutingHttpRequest(requestId, context.Request.Method, userAgent, Sanitizer.Sanitize(context.Request.Path));
3736

3837
await _next.Invoke(context);
3938

src/WebJobs.Script/Sanitizer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ internal static class Sanitizer
1818

1919
// List of keywords that should not be replaced with [Hidden Credential]
2020
private static readonly string[] AllowedTokens = new string[] { "PublicKeyToken=" };
21-
internal static readonly string[] CredentialTokens = new string[] { "Token=", "DefaultEndpointsProtocol=http", "AccountKey=", "Data Source=", "Server=", "Password=", "pwd=", "&sig=", "&sig=", "?sig=", "SharedAccessKey=", "&code=", "&code=", "?code=", "key=" };
21+
internal static readonly string[] CredentialTokens = new string[] { "Token=", "DefaultEndpointsProtocol=http", "AccountKey=", "Data Source=", "Server=", "Password=", "pwd=", "&sig=", "&sig=", "?sig=", "SharedAccessKey=", "&code=", "&code=", "?code=", "/code=", "key=" };
2222
private static readonly string[] CredentialNameFragments = new[] { "password", "pwd", "key", "secret", "token", "sas" };
2323

2424
// Pattern of format : "<protocol>://<username>:<password>@<address>:<port>"

test/WebJobs.Script.Tests/Middleware/SystemTraceMiddlewareTests.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@ public SystemTraceMiddlewareTests()
4040
_middleware = new SystemTraceMiddleware(requestDelegate, logger);
4141
}
4242

43-
[Fact]
44-
public async Task SendAsync_WritesExpectedTraces()
43+
[Theory]
44+
[InlineData("http://functions.com/api/testfunc?code=123", "/api/testfunc")]
45+
[InlineData("http://functions.com/api/testfunc/code=123", "/api/testfunc[Hidden Credential]")]
46+
public async Task SendAsync_WritesExpectedTraces(string uriString, string loggedUriString)
4547
{
4648
string requestId = Guid.NewGuid().ToString();
4749
var context = new DefaultHttpContext();
48-
Uri uri = new Uri("http://functions.com/api/testfunc?code=123");
50+
Uri uri = new Uri(uriString);
4951
var requestFeature = context.Request.HttpContext.Features.Get<IHttpRequestFeature>();
5052
requestFeature.Method = "GET";
5153
requestFeature.Scheme = uri.Scheme;
@@ -86,7 +88,7 @@ public async Task SendAsync_WritesExpectedTraces()
8688
Assert.Equal(4, jo.Count);
8789
Assert.Equal(requestId, jo["requestId"]);
8890
Assert.Equal("GET", jo["method"]);
89-
Assert.Equal("/api/testfunc", jo["uri"]);
91+
Assert.Equal(loggedUriString, jo["uri"]);
9092
Assert.Equal("TestAgent", jo["userAgent"]);
9193

9294
// validate executed trace

0 commit comments

Comments
 (0)