Skip to content

Add authentication and input validation to TaskLogHandler#5229

Open
petrmarinec wants to merge 1 commit intogoogle:masterfrom
petrmarinec:fix/tasklog-auth-and-filter-injection
Open

Add authentication and input validation to TaskLogHandler#5229
petrmarinec wants to merge 1 commit intogoogle:masterfrom
petrmarinec:fix/tasklog-auth-and-filter-injection

Conversation

@petrmarinec
Copy link
Copy Markdown

Summary

TaskLogHandler at /testcase-detail/task-log was missing authentication and authorization checks. Unlike the adjacent Handler (which uses check_testcase_access) and RefreshHandler (which uses oauth + internal access check), TaskLogHandler had only @handler.get(handler.TEXT) — which sets content type but does not verify the caller's identity.

This meant any unauthenticated caller could query Google Cloud Logging for task execution logs associated with any testcase.

Additionally, the task_id and task_name query parameters were interpolated directly into the Cloud Logging filter string without escaping, creating a potential filter injection vector.

Changes

  1. Added access.check_access_and_get_testcase(testcase_id) at the start of TaskLogHandler.get() to verify the caller is authenticated and has access to the requested testcase — consistent with other handlers in the same file.

  2. Added task_name validation against TestcaseStatusInfo.TASK_EVENTS_NAMES + CHROME_TASK_EVENTS_NAMES to reject unknown task names before they reach the Cloud Logging query.

  3. Added _sanitize_filter_value() to TestcaseEventHistory that escapes double quotes and backslashes in user-supplied values before interpolating them into the Cloud Logging filter string.

  4. Added unit tests for the sanitization function and task name validation.

Testing

  • Added SanitizeFilterValueTest in testcase_status_events_test.py covering normal values, quote injection, backslash escaping, and empty strings.
  • Added TaskLogHandlerValidationTest in show_test.py verifying that known task names are accepted and injection payloads are not in the valid set.

@petrmarinec petrmarinec requested a review from a team as a code owner April 4, 2026 19:04
@google-cla
Copy link
Copy Markdown

google-cla bot commented Apr 4, 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.

@petrmarinec petrmarinec force-pushed the fix/tasklog-auth-and-filter-injection branch from 3539541 to eddfd93 Compare April 4, 2026 19:09
The TaskLogHandler endpoint at /testcase-detail/task-log was missing
authentication and authorization checks, unlike every other handler in
the same file that accesses testcase data. This change:

1. Adds access.check_access_and_get_testcase() to verify the caller
   is authenticated and authorized to view the testcase before querying
   Cloud Logging.

2. Validates task_name against the known set of valid task names to
   prevent Cloud Logging filter injection via crafted query parameters.

3. Adds _sanitize_filter_value() to escape double quotes and backslashes
   in user-supplied values before interpolating them into the Cloud
   Logging filter string, as defense-in-depth against filter injection.

4. Adds unit tests for the sanitization function and task name validation.
@petrmarinec petrmarinec force-pushed the fix/tasklog-auth-and-filter-injection branch from eddfd93 to 8c37c2c Compare April 4, 2026 19:12
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