WASM+Identity same-site & antiforgery updates #31888
Merged
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.
Fixes #31389
Addresses #31205
Addresses #28161
Sample updates
FIRST ... before reviewing the article DIFF on this PR ... let's sort out the sample updates at ...
dotnet/blazor-samples#210
/Logout
to/logout
.empty != null
toempty is not null
.return
s ... that's by convention for Blazor example code.email
andpassword
, as they can't be null.UserBasic
class, as it isn't used.Auth
client to POST to theBackend
app.NOTE: The same errors shown in CORS help blazor-samples#161 are seen here when that code processes an unauthenticated request to theWe think now that this is resolved by the sample updates./data-processing
endpoint. I'll place the error at the bottom of this OP.Article updates
Security Overview
This section applies to all Blazor app hosting models/templates. The primary goal here is to add a reminder that ...
Antiforgery mitigation is for form submissions encoded asUpdated on review.application/x-www-form-urlencoded
,multipart/form-data
, ortext/plain
with a cross-link to the Blazor Forms article coverage on forms antiforgery support.Server API endpoints withUpdated on review.application/json
-encoded content and CORS don't require CSRF protection.Standalone with Identity article
I'm still a bit concerned ... even if this is all correct (or close to correct) ... that the bit about forms submission in a standalone WASM situation could use more work. Using an HTTP client with a JSON request and CORS is what we focus on throughout the docs. This will be the first time that we explicitly say that antiforgery isn't a concern in that scenario. However,
EditForm
is useful client-side to just collect the data for a JSON POST to a server API. I don't want readers to think that anything is happening forEditForm
in such an app vis-a-vis antiforgery. I might need to add more content on this point.... and BTW Jeremy ... it seems to me that one day if I ever get the time that I should convert your plain forms over to
EditForm
forms with the nice validation ... and roll in the bits to trigger validation failures with theValidationMessage
component. I can do all that ... it's just a question of TIME ⏲️ ... and I won't have any for the foreseeable future 🏃♂️😄.Error
This has been addressed by the updates to the sample app.
Error for unauthenticated hit on the/data-processing
endpoint. What the sample is doing now is trapping it in atry-catch
and showing a message. Can't we work out something more graceful than that? ... or does this all resolve back to your remarks here ...dotnet/blazor-samples#161 (comment)Internal previews