Skip to content

fix(dev): restrict default CORS origins and WebSocket allowed origins to localhost#1222

Open
g0w6y wants to merge 1 commit into
google:mainfrom
g0w6y:fix/dev-server-wildcard-cors-websocket-origin
Open

fix(dev): restrict default CORS origins and WebSocket allowed origins to localhost#1222
g0w6y wants to merge 1 commit into
google:mainfrom
g0w6y:fix/dev-server-wildcard-cors-websocket-origin

Conversation

@g0w6y
Copy link
Copy Markdown

@g0w6y g0w6y commented May 26, 2026

Problem

The dev server (AdkWebServer / adk web) ships two independent wildcard origin policies:

  1. HTTP CORSAdkWebCorsProperties falls back to ["*"] when no origins are configured, so every response carries Access-Control-Allow-Origin: *. Any page on the internet can therefore read agent responses cross-origin.

  2. WebSocket (/run_live)WebSocketConfig calls .setAllowedOrigins("*"), making the endpoint accept upgrade requests from any Origin header. This allows Cross-Site WebSocket Hijacking (CSWSH): a malicious page can open a live session against a dev server that is reachable from the victim's browser.

Combined, these let a remote origin read HTTP responses and drive the agent over WebSocket without any user interaction beyond visiting a page.

Fix

AdkWebCorsProperties.java – change the default origins fallback from ["*"] to ["http://localhost:8080", "http://127.0.0.1:8080"]. The dev UI (served on the same host) continues to work; all other origins are blocked by the browser.

WebSocketConfig.java – inject AdkWebCorsProperties and derive setAllowedOrigins from the same property instead of a separate hardcoded wildcard, so both policies stay in sync. Users who need a broader origin allowlist can set adk.web.cors.origins explicitly in their application properties.

Impact

  • No change to users running the standard dev workflow (UI on localhost:8080).
  • Users who access the dev server from a custom host/port need to add that origin via adk.web.cors.origins.
  • Eliminates wildcard CORS and CSWSH exposure on /run_live for all default-configuration deployments.

… to localhost

The dev server defaulted to a wildcard CORS policy (Access-Control-Allow-Origin: *)
and registered the /run_live WebSocket endpoint with setAllowedOrigins("*"). Any page
loaded from an arbitrary origin could therefore read HTTP responses and complete a
cross-origin WebSocket handshake against a locally running dev server, giving a remote
site read and drive access to the agent.

- AdkWebCorsProperties: change the default allowed-origins fallback from ["*"] to
  ["http://localhost:8080", "http://127.0.0.1:8080"] so the dev UI keeps working out
  of the box while all other origins are rejected by the browser.
- WebSocketConfig: inject AdkWebCorsProperties and derive the WebSocket allowed-origins
  list from the same property, eliminating the separate hardcoded wildcard and keeping
  both policies in sync. Users who need a broader allowlist can set
  adk.web.cors.origins explicitly.
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.

1 participant