Resolve the AI tool authorization caller through IUserAccessor - #117
Merged
Conversation
fsfh60
force-pushed
the
fix/hub-user-tool-authorization
branch
from
July 28, 2026 20:09
0f969e9 to
d42431c
Compare
Tool authorization resolved the current caller from IHttpContextAccessor, which is unreliable inside SignalR hub invocations. Long-lived transports, backplane-delivered invocations, and hosted SignalR services all run hub methods outside the request that opened the connection, so HttpContext is frequently null there and every tool was denied. Introduce IAIUserAccessor, an ambient accessor that prefers a principal pushed onto the current asynchronous flow and falls back to HttpContext.User for ordinary requests. The AI chat and chat interaction hubs now publish Context.User for the duration of every invocation. A null principal now means there is no caller at all, such as a background task, a workflow, or a recipe, so authorization is skipped and every tool stays available. Unauthenticated callers remain non-null and are still evaluated, so host-defined anonymous permissions keep applying. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
fsfh60
force-pushed
the
fix/hub-user-tool-authorization
branch
from
July 28, 2026 20:24
d42431c to
a99bc5d
Compare
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.
What changed
AI tool authorization resolved the current caller from
IHttpContextAccessor.HttpContextis documented as unreliable inside SignalR hub invocations — long-lived transports such as WebSockets, backplane-delivered invocations, and hosted SignalR services all run hub methods outside the request that opened the connection, so the accessor is frequentlynullthere.Because
FunctionInvocationAICompletionServiceHandlerpassed thatnullprincipal straight toIAIToolAccessEvaluator, hosts that enforce permissions denied every tool for hub-based chat. The user simply got an answer with no tools and no explanation.The fix
New
IAIUserAccessorabstraction, backed by anAsyncLocalimplementation that mirrors theHttpContextAccessorpattern:HttpContext.Userfor ordinary HTTP requests.AIChatHubCoreandChatInteractionHubBasenow publishContext.Userfor the duration of every invocation via a privateRunInScopeAsyncwrapper.ExecuteInScopeAsyncstaysprotected virtual, so existing host overrides keep working untouched.Null policy
This is the one behavior change worth reviewing:
nullmeans there is no caller at all — a background task, a workflow, a recipe. Authorization is skipped and every tool stays available, because trusted server-side code is not a security boundary.null. Hubs and HTTP requests always provide aClaimsPrincipalwith an unauthenticated identity, so the evaluator still runs and hosts can grant or deny tools for anonymous users as they see fit.This makes the framework agree with the Orchard Core integration, which already used the "no principal means skip the check" rule.
Testing
-warnaserrorAIUserAccessorTestscovering the HTTP fallback, push/restore,nullpush, async continuation flow, and isolation between concurrent flowsDocs
docs/core/tools.md— newIAIUserAccessorsection documenting the resolution order and the null contractdocs/changelog/v1.0.0.md— changelog entry