Harden SocialSample FailureMessage rendering#67995
Draft
cincuranet with Copilot wants to merge 7 commits into
Draft
Harden SocialSample FailureMessage rendering#67995cincuranet with Copilot wants to merge 7 commits into
cincuranet with Copilot wants to merge 7 commits into
Conversation
Co-authored-by: cincuranet <4540597+cincuranet@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix escaping of FailureMessage in SocialSample
Harden SocialSample FailureMessage rendering
Jul 24, 2026
javiercn
approved these changes
Jul 24, 2026
javiercn
left a comment
Member
There was a problem hiding this comment.
We likely don't need the test for the sample
cincuranet
requested changes
Jul 24, 2026
Co-authored-by: cincuranet <4540597+cincuranet@users.noreply.github.com>
Contributor
|
@copilot Look around in other samples for similar missing escaping. If you find some, fix it as well. |
Agent-Logs-Url: https://github.com/dotnet/aspnetcore/sessions/efe9cfb2-0353-4123-9bf1-aa24ed3e6081 Co-authored-by: cincuranet <4540597+cincuranet@users.noreply.github.com>
Copilot stopped work on behalf of
cincuranet due to an error
July 24, 2026 12:37
Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com>
Contributor
Author
Addressed in a2cb944. I checked the other sample HTML responses for similar request-derived rendering and hardened two additional spots: CookiePolicySample now encodes request path/path-base values before using them in links, and HotAddSample now encodes PathBase before writing it into link/form attributes. |
cincuranet
requested changes
Jul 24, 2026
cincuranet
left a comment
Contributor
There was a problem hiding this comment.
@copilot And add test back per #67995 (review).
| response.ContentType = "text/html"; | ||
| await response.WriteAsync("<html><body>"); | ||
| await response.WriteAsync("An remote failure has occurred: " + context.Request.Query["FailureMessage"] + "<br>"); | ||
| await response.WriteAsync("An remote failure has occurred: " + HtmlEncoder.Default.Encode(context.Request.Query["FailureMessage"]) + "<br>"); |
Co-authored-by: cincuranet <4540597+cincuranet@users.noreply.github.com>
Contributor
Author
Addressed in b3e62c5. |
cincuranet
requested changes
Jul 24, 2026
| using var host = await CreateHost(); | ||
| using var client = host.GetTestClient(); | ||
|
|
||
| var failureMessage = "<script>alert('xss') & \"boom\"</script>"; |
Co-authored-by: cincuranet <4540597+cincuranet@users.noreply.github.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Harden SocialSample FailureMessage rendering
HTML-encode SocialSample FailureMessage before rendering
Description
SocialSamplewroteRequest.Query["FailureMessage"]directly into an HTML response. This change encodes that value before rendering so query content cannot break the page or inject markup.Endpoint hardening
/errorendpoint'sFailureMessagequery value withHtmlEncoder.Default.Encode(...)before writing it into the response body.Coverage
SocialSample, calls/errorwith markup-bearing input, and verifies the encoded value is rendered instead of the raw string.