Skip to content

fix(agent.service): attach X-XSRF-TOKEN header to run_sse requests - #568

Open
utkarshpatwa393-sys wants to merge 1 commit into
google:mainfrom
utkarshpatwa393-sys:fix/run-sse-xsrf-token-459
Open

utkarshpatwa393-sys wants to merge 1 commit into
google:mainfrom
utkarshpatwa393-sys:fix/run-sse-xsrf-token-459

Conversation

@utkarshpatwa393-sys

Copy link
Copy Markdown

Description

Fixes #459.

When XSRF protection is enabled on the ADK backend, requests from the ADK web UI to POST /run_sse fail with HTTP 401 Unauthorized. Other requests (such as GET /list-apps or session creation) succeed because they go through Angular's HttpClient which automatically attaches the XSRF token header.

runSse uses native fetch to stream SSE responses and did not include the X-XSRF-TOKEN header.

Solution

  1. Inject HttpXsrfTokenExtractor from @angular/common/http in AgentService.
  2. Extract the token via this.xsrfTokenExtractor.getToken().
  3. If present, attach 'X-XSRF-TOKEN': xsrfToken to the request headers passed to fetch.
  4. Add unit test in src/app/core/services/agent.service.spec.ts verifying that the X-XSRF-TOKEN header is attached when the token is present.

Testing

  • Full Angular production build (npm run build) completed successfully without errors.
  • Added regression unit test in agent.service.spec.ts.

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unauthorized runSSE requests when XSRF protection enabled

1 participant