Repository navigation
refactor(Layout): update authentication state on navigation #8505
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -729,18 +729,34 @@ public async Task UpdateAsync(string key) | |
|
|
||
| private void Navigation_LocationChanged(object? sender, LocationChangedEventArgs e) | ||
| { | ||
| if (OnAuthorizing == null) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| if (OnAuthorizing != null) | ||
| InvokeAsync(async () => | ||
| { | ||
| InvokeAsync(async () => | ||
| var auth = await OnAuthorizing(e.Location); | ||
|
Contributor
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. 🔴 Critical · Failed checks retain access When the authorization callback hangs or throws after the layout was previously authorized, Fail closed while authorization is pending or fails, and handle callback exceptions and timeouts explicitly. Prompt for AI agentsIn `src/BootstrapBlazor/Components/Layout/Layout.razor.cs` at line 739:
**Failed checks retain access**
When the authorization callback hangs or throws after the layout was previously authorized, `_authenticated` is not cleared before `OnAuthorizing` is awaited, and the dispatched task has no failure handling. If the callback stalls or throws during a dependency failure, the previous authorized state remains active and the layout continues rendering protected content.
Fail closed while authorization is pending or fails, and handle callback exceptions and timeouts explicitly. |
||
| if (auth) | ||
| { | ||
| var auth = await OnAuthorizing(e.Location); | ||
| if (!auth && IsAutoNavigateWhenNotAuthorize) | ||
| // 当前地址已授权时恢复 UI 状态 | ||
| if (!_authenticated) | ||
| { | ||
|
Comment on lines
+739
to
744
Contributor
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. 🔴 Critical · Protected routes render as authorized When onAuthorizing returns true for a route whose framework authorization check denies the user, Combine the callback result with the destination route's framework authorization result before setting Also at Prompt for AI agentsIn `src/BootstrapBlazor/Components/Layout/Layout.razor.cs` at lines 739-744:
**Protected routes render as authorized**
When onAuthorizing returns true for a route whose framework authorization check denies the user, `Navigation_LocationChanged` sets `_authenticated` from `OnAuthorizing` alone, bypassing the route handler's `IsAuthorizedAsync` result, so the layout renders `Main` for a route the user cannot access.
Combine the callback result with the destination route's framework authorization result before setting `_authenticated`.
Also at `src/BootstrapBlazor/Components/Layout/Layout.razor.cs:745`. |
||
| Navigation.NavigateTo(NotAuthorizeUrl, true); | ||
| _authenticated = true; | ||
| StateHasChanged(); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
| else if (IsAutoNavigateWhenNotAuthorize) | ||
| { | ||
| Navigation.NavigateTo(NotAuthorizeUrl, true); | ||
| } | ||
| else if (_authenticated) | ||
| { | ||
| // 未开启自动跳转时更新 UI 状态显示 NotAuthorized 模板 | ||
| _authenticated = false; | ||
| StateHasChanged(); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
||
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.
🔴 Critical · Stale checks overwrite current authorization
When multiple navigations overlap and an earlier
OnAuthorizingcall completes after a later one,Navigation_LocationChangedapplies each result to the shared_authenticatedstate and may redirect based on the stale location, so the layout shows the wrong content for the current page.Before applying a result or redirecting, verify that its location is still current.
Also at
src/BootstrapBlazor/Components/Layout/Layout.razor.cs:739-758.Prompt for AI agents