-
Notifications
You must be signed in to change notification settings - Fork 773
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sanitize http.url
attribute
#1961
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
e3494f6
Sanitize http.url in HTTP instrumentation
pellared 3e88ae6
Revert
pellared 91d083d
Refine GetUriTagValueFromRequestUri
pellared 824183b
Fix build warning
pellared 0df727e
Add new test case in HttpInListenerTests
pellared e02fc4d
Add missing whitespace
pellared 736ecb1
Add missing line
pellared a2db594
Fix AspNetRequestsAreCollectedSuccessfully
pellared 0259b3a
Sanitize http.url in ASP.NET instrumentation
pellared c7dec90
Make the tests passing
pellared 721c529
Fix test case in AspNetRequestsAreCollectedSuccessfully
pellared 683ec3e
Update Changelog
pellared 5f517db
Add URL fragments to HTTP test cases
pellared 275d431
Add complex URLs to ASP.NET test cases
pellared 8c5360e
Merge branch 'main' into sanitize-http.url
cijothomas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,21 +46,25 @@ public void Dispose() | |
} | ||
|
||
[Theory] | ||
[InlineData("http://localhost/", 0, null, "TraceContext")] | ||
[InlineData("http://localhost/", 0, null, "TraceContext", true)] | ||
[InlineData("https://localhost/", 0, null, "TraceContext")] | ||
[InlineData("http://localhost:443/", 0, null, "TraceContext")] // Test http over 443 | ||
[InlineData("https://localhost:80/", 0, null, "TraceContext")] // Test https over 80 | ||
[InlineData("http://localhost:80/Index", 1, "{controller}/{action}/{id}", "TraceContext")] | ||
[InlineData("https://localhost:443/about_attr_route/10", 2, "about_attr_route/{customerId}", "TraceContext")] | ||
[InlineData("http://localhost:1880/api/weatherforecast", 3, "api/{controller}/{id}", "TraceContext")] | ||
[InlineData("https://localhost:1843/subroute/10", 4, "subroute/{customerId}", "TraceContext")] | ||
[InlineData("http://localhost/api/value", 0, null, "TraceContext", false, "/api/value")] // Request will be filtered | ||
[InlineData("http://localhost/api/value", 0, null, "TraceContext", false, "{ThrowException}")] // Filter user code will throw an exception | ||
[InlineData("http://localhost/api/value/2", 0, null, "CustomContextMatchParent")] | ||
[InlineData("http://localhost/api/value/2", 0, null, "CustomContextNonmatchParent")] | ||
[InlineData("http://localhost/api/value/2", 0, null, "CustomContextNonmatchParent", false, null, true)] | ||
[InlineData("http://localhost/", "http://localhost/", 0, null, "TraceContext")] | ||
[InlineData("http://localhost/", "http://localhost/", 0, null, "TraceContext", true)] | ||
[InlineData("https://localhost/", "https://localhost/", 0, null, "TraceContext")] | ||
[InlineData("https://localhost/", "https://user:pass@localhost/", 0, null, "TraceContext")] // Test URL sanitization | ||
[InlineData("http://localhost:443/", "http://localhost:443/", 0, null, "TraceContext")] // Test http over 443 | ||
[InlineData("https://localhost:80/", "https://localhost:80/", 0, null, "TraceContext")] // Test https over 80 | ||
[InlineData("https://localhost:80/Home/Index.htm?q1=v1&q2=v2#FragmentName", "https://localhost:80/Home/Index.htm?q1=v1&q2=v2#FragmentName", 0, null, "TraceContext")] // Test complex URL | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could update this test case to use |
||
[InlineData("https://localhost:80/Home/Index.htm?q1=v1&q2=v2#FragmentName", "https://user:password@localhost:80/Home/Index.htm?q1=v1&q2=v2#FragmentName", 0, null, "TraceContext")] // Test complex URL sanitization | ||
[InlineData("http://localhost:80/Index", "http://localhost:80/Index", 1, "{controller}/{action}/{id}", "TraceContext")] | ||
[InlineData("https://localhost:443/about_attr_route/10", "https://localhost:443/about_attr_route/10", 2, "about_attr_route/{customerId}", "TraceContext")] | ||
[InlineData("http://localhost:1880/api/weatherforecast", "http://localhost:1880/api/weatherforecast", 3, "api/{controller}/{id}", "TraceContext")] | ||
[InlineData("https://localhost:1843/subroute/10", "https://localhost:1843/subroute/10", 4, "subroute/{customerId}", "TraceContext")] | ||
[InlineData("http://localhost/api/value", "http://localhost/api/value", 0, null, "TraceContext", false, "/api/value")] // Request will be filtered | ||
[InlineData("http://localhost/api/value", "http://localhost/api/value", 0, null, "TraceContext", false, "{ThrowException}")] // Filter user code will throw an exception | ||
[InlineData("http://localhost/api/value/2", "http://localhost/api/value/2", 0, null, "CustomContextMatchParent")] | ||
[InlineData("http://localhost/api/value/2", "http://localhost/api/value/2", 0, null, "CustomContextNonmatchParent")] | ||
[InlineData("http://localhost/api/value/2", "http://localhost/api/value/2", 0, null, "CustomContextNonmatchParent", false, null, true)] | ||
public void AspNetRequestsAreCollectedSuccessfully( | ||
string expectedUrl, | ||
string url, | ||
int routeType, | ||
string routeTemplate, | ||
|
@@ -302,7 +306,7 @@ public void AspNetRequestsAreCollectedSuccessfully( | |
Assert.True(string.IsNullOrEmpty(span.GetStatus().Description)); | ||
} | ||
|
||
var expectedUri = new Uri(url); | ||
var expectedUri = new Uri(expectedUrl); | ||
var actualUrl = span.GetTagValue(SemanticConventions.AttributeHttpUrl); | ||
|
||
Assert.Equal(expectedUri.ToString(), actualUrl); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add test cases to cover all the parts that would make up the new Uri such as scheme, authority, path and query, fragment etc.?
How about adding two unit tests like these which would ensure that
Uri.PathAndQuery
(/Home/Index.html) andUri.Fragment
(#search) are concatenated?Url:
https://user:password@localhost:443/Home/Index.html#search
ExpectedUrl:
https://localhost:443/Home/Index.html#search
And one for http
Url:
http://user:password@localhost:80/Home/Index.html#search
ExpectedUrl:
http://localhost:80/Home/Index.html#search
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did my best to address it here: 5f517db and here: 275d431
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a comment.