Skip to content

fix(adkrest): backport create-session event validation (#1995) - #2482

Open
baptmont wants to merge 1 commit into
google:v1from
baptmont:fix/v1-backport-session-init-validation
Open

baptmont wants to merge 1 commit into
google:v1from
baptmont:fix/v1-backport-session-init-validation

Conversation

@baptmont

Copy link
Copy Markdown
Contributor

Summary

Backports #1995 to the 1.x line.

POST /apps/{app}/users/{user}/sessions appends the client's events verbatim. On v1 a client can seed an agent-authored adk_request_confirmation call and approve it on the next /run, which runs a confirmation-gated tool with arguments the user never saw. It can also write app: and user: state through an event's actions.stateDelta.

This ports adk-python's _validate_session_initialization_events (src/google/adk/cli/api_server.py:811-828). Any initialization event that carries event actions, long-running tool IDs, or an adk_request_confirmation, adk_request_credential or adk_request_input call or response is rejected with 400 before the session is created.

Adapted for 1.x

  • tool/toolauth and workflow do not exist on v1, so the credential and input call names are spelled out. They match adk-python's CLIENT_FUNCTION_CALL_NAMES and v1's requestEUCFunctionCallName.
  • The v1 REST event has no routes or requestedInput, so those checks and their tests are dropped. The same goes for the requestedToolConfirmations, compaction and requestedAuthConfigs action cases, because v1's EventActions has only five fields. hasEventActions checks every field by reflection, so it covers all five.
  • v1's REST server has no authn, so the shared-state integration test uses one server.
  • The doc comment edit to internal/llminternal/auth_preprocessor.go is dropped because that file does not exist on v1.

What changes for existing users

A create-session request whose events include any of the following now gets a 400, and no session is created:

  • non-empty actions
  • longRunningToolIds
  • an ADK protocol function call or response

Ordinary messages, tool calls and tool responses are still accepted, so importing a conversation that used tools keeps working. Empty stateDelta/artifactDelta maps, which every runtime event reads back with, are still accepted.

Testing Plan

  • New unit tests TestCreateSessionValidatesInitializationEvents and TestCreateSessionRejectsEveryEventActionsField, and the integration test TestCreateSessionKeepsSeededStateDeltaOutOfSharedState.
  • Revert check: with sessions.go restored to v1, 16 reject cases, all 5 action-field cases and both shared-state subtests fail.
  • Guard-by-guard mutation: each of the following was removed or inverted in turn, and at least one test failed every time: the long-running check, the actions check, the protocol check, each of the three reserved names, the call scan, the response scan, the empty-map exemption, and the check on later events.
  • End-to-end exploit check (not committed): a REST server with an LLM agent whose only tool has RequireConfirmation: true.
    • Before this change, the exploit from the report ran the tool with attacker-chosen arguments in 5 of 13 variants.
    • After it, none do.
    • The positive control, a normal request → confirm → approve flow, still runs the tool.
  • go build, go test -race ./..., go mod tidy -diff and golangci-lint v2.3.1 (the CI pin, under Go 1.26.10) are clean on the root module.

POST /apps/{app}/users/{user}/sessions appended client-supplied events
verbatim. A client could seed an agent-authored adk_request_confirmation
call and approve it on the next /run, running a confirmation-gated tool
with arguments the user never saw, or write "app:" and "user:" state
through an event's Actions.StateDelta.

Port adk-python's _validate_session_initialization_events: reject any
initialization event that carries event actions, long-running tool IDs,
or an adk_request_confirmation, adk_request_credential or
adk_request_input call or response, before the session is created.

Adapted for 1.x: tool/toolauth and workflow do not exist here, so the
credential and input call names are spelled out; the REST event has no
routes or requestedInput, so those checks and their tests are dropped;
the server has no authn, so the shared-state test uses one server; and
internal/llminternal/auth_preprocessor.go, whose doc comment google#1995
updated, does not exist here.

(cherry picked from commit 57c6bd8)

This branch has not been deployed

No deployments
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.

2 participants