cadence icon indicating copy to clipboard operation
cadence copied to clipboard

fix: escape Pinot string literals in PinotQueryFilter.addEqual

Open mvanhorn opened this issue 6 months ago • 3 comments

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-224 and request_validator.go:244-282 validate domain / time filter / cardinality / page size but do not validate or normalize ExecutionFilter.WorkflowID or TypeFilter.Name.
  • service/frontend/api/list_workflow_handlers.go:141-164 and :272-296 copy those values into persistence-layer requests.
  • common/persistence/pinot/pinot_visibility_store.go:980-1048 builds the Pinot text query through addEqual.

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

  • addEqual now passes string values through escapePinotStringLiteral before the '%s' wrap. Non-string values are unaffected; only the string branch changes.
  • escapePinotStringLiteral is unexported and a one-liner over the existing strings.ReplaceAll. No new imports.
  • TestGetListWorkflowExecutionsByTypeQuery and TestGetListWorkflowExecutionsByWorkflowIDQuery each 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.

mvanhorn avatar May 22 '26 17:05 mvanhorn

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!

c-warren avatar Jun 23 '26 18:06 c-warren

Code Review ✅ Approved

Adds an escaping helper to PinotQueryFilter.addEqual to prevent quote injection in legacy list workflow filter paths. No issues found.

Rules ⚠️ 1/2 requirements met

Repository Rules

❌ GitHub Issue Linking Requirement: The PR description does not contain a link to a GitHub issue and the fix prefix is not exempt from the issue linking requirement.
✅ PR Description Quality Standards: The PR description covers all required sections with substantive content adhering to the PR template guidance.

2 rules not applicable. Show all rules by commenting gitar display:verbose.

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing less information.

Comment with these commands to change:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

gitar-bot avatar Jun 23 '26 23:06 gitar-bot

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.

mvanhorn avatar Jun 23 '26 23:06 mvanhorn

Appreciate it, @c-warren - Pinot string literals are properly escaped in addEquals now.

mvanhorn avatar Jul 10 '26 18:07 mvanhorn

Thanks for merging, @c-warren - escaping Pinot string literals in addEqual closes a real injection-shaped hole.

mvanhorn avatar Jul 12 '26 14:07 mvanhorn