fix(jsonfilter): Sanitize input when parsing filters
Merged
JA
4mo ago+128+128+012345678901234567890123456789-14-14-01234567890123456789
This pull request strengthens the security of JSON field path filtering in workflow queries by validating user-supplied field paths to prevent SQL injection. It introduces a strict allowlist for field path syntax, surfaces validation errors to the API, and adds comprehensive tests to ensure only safe paths are accepted.
Security improvements for JSON field path filtering:
- Added a regular expression (
fieldPathRegexp) inpkg/jsonfilter/jsonfilter.goto strictly validate JSON field paths, allowing only dot-separated identifiers and numeric array indices, and rejecting any unsafe characters that could lead to SQL injection. - Implemented the
validateFieldPathfunction inpkg/jsonfilter/jsonfilter.goto enforce this validation before building SQL predicates. [1] [2] - Updated
BuildEntSelectorFromJSONFilterto return an error if the field path is unsafe, preventing unsafe queries from being constructed.
Workflow query logic and error handling:
- Refactored
applyWorkflowFiltersinapp/controlplane/pkg/data/workflow.goto return an error if any JSON filter is invalid, ensuring validation errors are surfaced instead of silently ignored. [1] [2] [3] [4] - Updated integration tests in
app/controlplane/pkg/biz/workflow_integration_test.goto verify that unsafe field paths are rejected with a validation error, and safe paths are accepted.
Test coverage:
- Expanded unit tests in
pkg/jsonfilter/jsonfilter_test.goto cover a wide range of valid and invalid field path scenarios, ensuring the validator correctly allows safe paths and rejects unsafe ones. [1] [2]
Other:
- Updated copyright years in
pkg/jsonfilter/jsonfilter.go. - Added missing import for
jsonfilterin integration tests.