You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Proposed Fix: Validate task/request IDs in REST transport
The REST transport exposes endpoints like GET /v1/tasks/{task_id} where task_id comes directly from the URL path. Since these IDs are later used to look up tasks in the store (and potentially in file paths or database keys), accepting values like ../secret or ../../etc/passwd could be dangerous.
Root Cause
Starlette path parameters are URL-decoded by the time they reach the handler, so a request to /v1/tasks/..%2F..%2Fconfig would arrive as ../../config. Without sanitization this string is passed verbatim to task_store.get().
Suggested Fix
Add a shared validator function and apply it as a Starlette dependency (or inline check) at the REST handler layer:
importrefroma2a.typesimportInvalidParamsErrorfroma2a.utils.errorsimportServerError# Only allow characters that are safe in a task/request ID:# alphanumerics, hyphens, underscores, dots (but not leading dots)_SAFE_ID_RE=re.compile(r'^[a-zA-Z0-9][a-zA-Z0-9_\-\.]{0,127}$')
defvalidate_task_id(task_id: str) ->str:
"""Validates that a task/request ID is safe to use."""ifnottask_idornot_SAFE_ID_RE.match(task_id):
raiseServerError(
error=InvalidParamsError(
message=f'Invalid task ID format: {task_id!r}'
)
)
returntask_id
This can be called at the top of every REST handler that accepts a path parameter:
However, this only works if path parameters are defined with regex syntax, which requires Starlette ≥ 0.20. The inline validate_task_id() approach is more portable and gives a better error message to clients.
Notes
The same validation should apply to context_id if it appears as a path parameter.
JSON-RPC transport is not affected because IDs come in the request body and Pydantic already validates them as strings; the attack surface is the URL path.
The InvalidParamsError response ensures spec-compliant error responses (-32602).
Happy to submit a PR for this if it would be helpful.
Activity
mtsmyassin commentedon Apr 17, 2026
Proposed Fix: Validate task/request IDs in REST transport
The REST transport exposes endpoints like
GET /v1/tasks/{task_id}wheretask_idcomes directly from the URL path. Since these IDs are later used to look up tasks in the store (and potentially in file paths or database keys), accepting values like../secretor../../etc/passwdcould be dangerous.Root Cause
Starlette path parameters are URL-decoded by the time they reach the handler, so a request to
/v1/tasks/..%2F..%2Fconfigwould arrive as../../config. Without sanitization this string is passed verbatim totask_store.get().Suggested Fix
Add a shared validator function and apply it as a Starlette dependency (or inline check) at the REST handler layer:
This can be called at the top of every REST handler that accepts a path parameter:
Alternative: Starlette Path Regex Constraint
Starlette also supports regex constraints directly in route definitions, which catches the issue before it even reaches handler code:
However, this only works if path parameters are defined with regex syntax, which requires Starlette ≥ 0.20. The inline
validate_task_id()approach is more portable and gives a better error message to clients.Notes
context_idif it appears as a path parameter.InvalidParamsErrorresponse ensures spec-compliant error responses (-32602).Happy to submit a PR for this if it would be helpful.
fix(security): sanitize REST path parameters to prevent injection att…
fix(security): sanitize REST path parameters to prevent injection att…
fix(security): sanitize REST path parameters to prevent injection att…
fix(security): sanitize REST path parameters to prevent injection att…