Repository navigation
fix(agent.service): attach X-XSRF-TOKEN header to run_sse requests - #568
Open
utkarshpatwa393-sys wants to merge 1 commit into
Open
utkarshpatwa393-sys wants to merge 1 commit into
utkarshpatwa393-sys wants to merge 1 commit into
Conversation
When XSRF protection is enabled on the ADK backend, fetch requests to /run_sse fail with 401 Unauthorized because raw fetch does not inherit Angular's HttpXsrfInterceptor. Inject HttpXsrfTokenExtractor in AgentService and append X-XSRF-TOKEN header to runSse fetch request if token is present. Fixes google#459 Signed-off-by: utkarshpatwa393-sys <utkarshpatwa393@gmail.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.
Description
Fixes #459.
When XSRF protection is enabled on the ADK backend, requests from the ADK web UI to
POST /run_ssefail with HTTP 401 Unauthorized. Other requests (such asGET /list-appsor session creation) succeed because they go through Angular'sHttpClientwhich automatically attaches the XSRF token header.runSseuses nativefetchto stream SSE responses and did not include theX-XSRF-TOKENheader.Solution
HttpXsrfTokenExtractorfrom@angular/common/httpinAgentService.this.xsrfTokenExtractor.getToken().'X-XSRF-TOKEN': xsrfTokento the request headers passed tofetch.src/app/core/services/agent.service.spec.tsverifying that theX-XSRF-TOKENheader is attached when the token is present.Testing
npm run build) completed successfully without errors.agent.service.spec.ts.