Repository navigation
Harden SocialSample FailureMessage rendering and add READMEs into samples - #67995
Conversation
javiercn
left a comment
There was a problem hiding this comment.
We likely don't need the test for the sample
|
@copilot Look around in other samples for similar missing escaping. If you find some, fix it as well. |
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
left a comment
There was a problem hiding this comment.
@copilot And add test back per #67995 (review).
Addressed in b3e62c5. |
There was a problem hiding this comment.
Pull request overview
This PR hardens sample apps that render user-controlled or request-derived values into HTML by encoding those values before writing them to the response body, with added test coverage specifically for SocialSample’s /error endpoint.
Changes:
- Encode
FailureMessage(and other request/user-derived values) before rendering inSocialSamplesample HTML responses. - Add HTML/URL encoding for rendered values in
HotAddSampleand HTML encoding for rendered values inCookiePolicySample. - Add a new integration-style test that hosts
SocialSampleand verifies/errorrenders the encoded failure message, plus a test-project reference to the sample.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Servers/HttpSys/samples/HotAddSample/Startup.cs | Encodes query inputs and displayed prefixes in generated HTML; URL-encodes remove links. |
| src/Security/CookiePolicy/samples/CookiePolicySample/Startup.cs | HTML-encodes request path/cookie key/value before rendering into HTML. |
| src/Security/Authentication/test/SocialSampleTests.cs | Adds a focused test validating /error HTML-encodes FailureMessage. |
| src/Security/Authentication/test/Microsoft.AspNetCore.Authentication.Test.csproj | References the SocialSample project so the new test can host it. |
| src/Security/Authentication/samples/SocialSample/Startup.cs | HTML/URL-encodes multiple user/request-derived values, including FailureMessage. |
c68d1c7 to
3ee291f
Compare
|
/ba-g Failures are unrelated. |
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.