fix: escape Pinot string literals in PinotQueryFilter.addEqual
Summary
PinotQueryFilter.addEqual wraps string values in single quotes via fmt.Sprintf("'%s'", val) without escaping embedded quotes. The legacy ListOpenWorkflowExecutions / ListClosedWorkflowExecutions filter paths reach this helper with request-controlled ExecutionFilter.WorkflowID and TypeFilter.Name, so a value containing ' breaks out of its literal and alters the surrounding Pinot predicate.
This PR adds a small escapePinotStringLiteral helper that doubles single quotes (SQL-92 standard, Pinot-compatible) and routes string values through it. Two regression tests cover the workflow type and workflow ID paths.
Why this matters
The newer query APIs (CountWorkflowExecutions, ScanWorkflowExecutions, ListWorkflowExecutions) already enforce a validated shape via common/pinot/pinotQueryValidator.go (pinotQueryValidator_test.go includes explicit rejection of multi-statement and UNION-style input). The legacy list filter paths bypass that validator and reach addEqual directly:
service/frontend/api/request_validator.go:196-224andrequest_validator.go:244-282validate domain / time filter / cardinality / page size but do not validate or normalizeExecutionFilter.WorkflowIDorTypeFilter.Name.service/frontend/api/list_workflow_handlers.go:141-164and:272-296copy those values into persistence-layer requests.common/persistence/pinot/pinot_visibility_store.go:980-1048builds the Pinot text query throughaddEqual.
addEqual was the right place to fix this — it's the central helper every legacy filter goes through. Aligning it with the newer-API validation pattern closes the gap without changing the API shape. Authenticated callers with PermissionRead on the visibility surface remain the only ones who can reach the path; the patch removes the predicate-shape break, not the auth boundary.
Changes
addEqualnow passes string values throughescapePinotStringLiteralbefore the'%s'wrap. Non-string values are unaffected; only the string branch changes.escapePinotStringLiteralis unexported and a one-liner over the existingstrings.ReplaceAll. No new imports.TestGetListWorkflowExecutionsByTypeQueryandTestGetListWorkflowExecutionsByWorkflowIDQueryeach gain a case with a single-quote in the filter value, asserting the generated query contains a doubled quote inside one literal rather than two adjacent literals.
Testing
go test ./common/pinot ./common/persistence/pinot
ok github.com/uber/cadence/common/persistence/pinot
ok github.com/uber/cadence/common/pinot
gofmt -l and go vet ./common/persistence/pinot both clean on the changed files.
Sorry for the delay, this looks good to me @mvanhorn - would you be able to re-run the tests, it looks like it flaked on an unrelated test. (If possible could you update to latest master as well?) Thanks for the contribution!
Adds an escaping helper to 2 rules not applicable. Show all rules by commenting Auto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change:Code Review ✅ Approved
PinotQueryFilter.addEqual to prevent quote injection in legacy list workflow filter paths. No issues found.Rules ⚠️ 1/2 requirements met
Repository Rules
gitar display:verbose.Options
Display: compact → Showing less information.
Auto-apply
Compact
gitar auto-apply:on
gitar display:verbose
Was this helpful? React with 👍 / 👎 | Gitar
Thanks @c-warren! Rebased onto latest master and force-pushed, which re-triggered the full CI run (the earlier codecov failure was a flake on an unrelated test). I also re-ran the pinot visibility package tests locally and they pass. Should be green shortly.
Appreciate it, @c-warren - Pinot string literals are properly escaped in addEquals now.
Thanks for merging, @c-warren - escaping Pinot string literals in addEqual closes a real injection-shaped hole.