Skip to content

fix: URL-encode userId and sessionId in VertexAiClient#1072

Open
Tulgaaaaaaaa wants to merge 2 commits intogoogle:mainfrom
Tulgaaaaaaaa:fix/url-encode-session-params
Open

fix: URL-encode userId and sessionId in VertexAiClient#1072
Tulgaaaaaaaa wants to merge 2 commits intogoogle:mainfrom
Tulgaaaaaaaa:fix/url-encode-session-params

Conversation

@Tulgaaaaaaaa
Copy link

@Tulgaaaaaaaa Tulgaaaaaaaa commented Mar 23, 2026

Problem

VertexAiClient.java concatenates userId and sessionId directly into Vertex AI REST API URL paths and query parameters without encoding.

For example in listSessions():

"reasoningEngines/" + reasoningEngineId + "/sessions?filter=user_id=" + userId

A userId containing & or = characters can inject additional query parameters. A sessionId containing / or .. can manipulate the URL path structure.

Fix

  • Added encodeParam() helper using URLEncoder.encode(value, StandardCharsets.UTF_8)
  • Applied encoding to userId in listSessions and sessionId in listEvents, getSession, deleteSession, and appendEvent
  • reasoningEngineId is already validated by parseReasoningEngineId() regex (digits only)

Tests added

VertexAiClientTest.java — 10 tests covering all 5 methods:

  • Query parameter injection prevention (user&extra=valueuser%26extra%3Dvalue)
  • Path traversal prevention (../../secret..%2F..%2Fsecret)
  • Normal alphanumeric values pass through correctly
  • Uses Mockito + ArgumentCaptor to verify actual URL paths

User-supplied userId and sessionId values were concatenated directly
into Vertex AI REST API URL paths and query parameters without
encoding. This allows query parameter injection via userId (e.g.,
"attacker&extra_param=value") and path manipulation via sessionId
(e.g., "../../other-resource").

Apply URLEncoder.encode() to all user-supplied values before URL
construction in listSessions, listEvents, getSession, deleteSession,
and appendEvent.

Bug: CWE-116 (Improper Encoding or Escaping of Output)
@google-cla
Copy link

google-cla bot commented Mar 23, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

10 tests covering all 5 methods that construct URLs with user-supplied
values. Verifies query parameter injection (& = characters), path
traversal (../ sequences), and normal values pass through correctly.
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