TRT-3122: Sippy security presubmit fails on Snyk Code SQL findings #4234
All Vouch review confidence checks passed
Residual risk 0.30 = Change Risk (0.75) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.75 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Sensitive Paths
sensitive_paths
0.075
Real PR Conversation Timeline
1 comments
"Review active on #4234"
general
weight: 0.35
sosiouxme
Summary
Fixes TRT-3122. The
ci/prow/securitypresubmit was failing on Snyk Codego/Sqlifindings. I went through each finding in thesnyk.sarif.jsonfrom the PR #4229 security run (7 findings: 6 HIGH, 1 LOW). One root cause turned out to be a real problem and is fixed here. The rest were checked by hand and confirmed as false positives. Where practical, the code was changed so request input cannot reach the SQL text. Two reviewed false positives that restructuring could not clear are moved into their own files, which are excluded in.snykwith the reason. SQL injection checks are not disabled for the rest of the code.Triage
| Reported location | Sink (from SARIF code flow) | Verdict | Resolution |
|---|---|---|---|
|
server.gojsonJobBugsFromDB(ListFilteredJobIDs) |Filter.ToSQLORWhere| Real defect | Column validation and quoting fix (below) ||
server.gojsonJobsAnalysisFromDB(ListFilteredJobIDs) |Filter.ToSQLORWhere| Real defect | Column validation and quoting fix ||
server.gojsonJobRunsReportFromDB|applyJobRunFilters->FilterFieldToSQL->Where| Real defect | Column validation and quoting fix ||
server.gojsonJobRunsReportFromDB(alias path) |applyJobRunFilters->FilterItemToSQL(alias)->Where| False positive | Alias columns come from the constantcolumnAliasesmap ||
server.gojsonJobRunsReportFromDB(server.go:1642) |applyJobRunFilters->FilterFieldToSQL/FilterItemToSQL/testNameFilterSQL->Where| False positive | Fields are validated and quoted or come from the constantcolumnAliasesmap, operators from fixed switches, and all values are bound. Restructuring did not clear it, so the builders moved topkg/api/job_runs_filters.go, which is excluded in.snyk||
server.gojsonFeatureGateDetail(GetPromotionStatus) |UncollapsedTestReportWithStatsRaw| False positive | Builder moved to its own file, which is excluded in.snyk||
server.gojsonTestsReportFromDB|UncollapsedTestReportWithStatsRaw| False positive | Same ||
pkg/api/tests.go(go/Sqli/test, LOW) |UncollapsedTestReportWithStatsRaw| False positive | Same ||
server.gojsonUpdateTriage|UpdateTriageFirst(&t, id)(both lookups) | False positive | ExplicitWhere("id = ?")|The real defect
FilterItem.FilterFieldToSQLquoted the filter column taken from the request with Go's%q. That is not SQL identifier quoting. PostgreSQL does not treat\"as an escape inside a double-quoted identifier, so a"incolumnFieldends the identifier early and the rest of the text is parsed as SQL. I checked this against the dev database:"x\" = 1 OR 1=1 --"parses as the identifierx\followed by= 1 OR 1=1. The BigQuery builder (toBQStr) was worse: it stripped the quotes entirely, so the column text went into the GoogleSQL query unescaped (for examplename) OR (TRUE).Fix:
filter.ValidateField/filter.ErrInvalidField: a filter column must be a simple identifier (^[A-Za-z_][A-Za-z0-9_]$). Every field the frontend and backend use already matches this pattern.FilterFieldToSQLvalidates the column, quotes it withpq.QuoteIdentifier, and now returns an error.Filter.ToSQLreturns(gorm.DB, error)likeToBQStr, so the request fails instead of running without that filter.ToBQStrvalidates every column and returns(BQFilterResult, error). The tests report also calls the newFilter.ValidateFieldsbefore splitting the filter, because the collapsed query never renders the processed part.ApplyFilters,FilterableDBResult,/api/testsand job analysis return theToSQLerror before building or embedding the query.IsBadRequestErrortreatsErrInvalidFieldandErrUnsupportedOperatoras client errors (HTTP 400).FilterItemToSQLwraps unsupported operators withErrUnsupportedOperator.applyJobRunFiltersand the BigQuery tests report return aValidationError.False positives
processedFilterConditionsalready limited pushdown to allowlisted columns, took operators from a fixed map, and bound values. It now looks up the quoted column SQL in a constant table (pushdownColumns), so text from the request is used only as a lookup key and never becomes SQL.lifecycleWhereClauseuses a constant column reference, an operator chosen from a switch, and bound values.UpdateTriagelooked up auintprimary key, which GORM binds. Both lookups now use an explicitWhere("id = ?", triage.ID).applyJobRunFilters: alias fields resolve through the constantcolumnAliasesmap and render withFilterItemToSQL, other fields go through the validated and quotedFilterFieldToSQL, and the test name fields usetestNameFilterSQL, whose status comes from the fixedtestNameStatusesmap. Snyk taints SQL built through the requestFilterItemand does not acceptValidateFieldorpq.QuoteIdentifieras sanitizers, so restructuring did not clear the finding.applyJobRunFilters,testNameFilterSQLand their supportingcolumnAliases,testNameStatusesandisTestNameFieldnow live inpkg/api/job_runs_filters.go. That file has a header warning that it is not scanned and must not gain new code, and.snykexcludes it with the reason. Which fields can be filtered is unchanged.TestResultsSpecfrom the validatedreleaseandperiodparams, so it flags the uncollapsed report'sRawcall regardless of how the fragments are built.UncollapsedTestReportWithStatsnow lives alone inpkg/db/query/uncollapsed_test_report.go, and.snykexcludes only that file, with the reason. Its condition builders (processedFilterConditions,lifecycleWhereClause) stay in scanned files.deepcode ignorecomments are not used. The CI scan runs without--remote-repo-urland applies only.snykpath excludes (an earlier run on this PR reportedIgnored issues: 0with inline comments present).Docs
pkg/api/README.md: documents the identifier rule for filterfieldand the HTTP 400 responses for invalid fields and unsupported operators..snyk: documents which suppression mechanism the scan applies (path excludes only) and adds the two reviewed files.Validation
make lint(sippy-dev MCPrun_lint) on the final code: passed (golangci-lint 0 issues, ESLint and npm audit passed).make test(sippy-dev MCPrun_tests) on the final code: passed. BDD 126/126, Go 16674 tests (32 skipped), Vitest 202/202, MCP pytest 289/289.make e2e(sippy-dev MCPrun_e2e, BigQuery coverage off) on the final code: passed,DONE 160 tests, 2 skipped.make integrationwas not run locally (no container socket available);ci/prow/integrationcovers it.-
pkg/filter/filterable_sql_test.go:ValidateField,Filter.ValidateFields; PostgreSQL rendering and field rejection inFilterFieldToSQL; rendering and theErrUnsupportedOperatorwrap inFilterItemToSQL;Filter.ToSQLAND/OR rendering through GORM dry-run with the real PostgreSQL dialect (no connection), including that an invalid column or unsupported operator returns an error;ToBQStrparameters and rejection;ApplyFiltersandFilterableDBResultreturnErrInvalidField.-
pkg/db/query/cumulative_query_test.go:processedFilterConditionspushdown and allowlist behavior, including a quote-breakout field that never reaches the SQL text.-
pkg/api/job_runs_filter_test.go:applyJobRunFiltersrendering and binding for alias and base columns (includingfailed, which is not an alias) and a negated alias, and theValidationErrorfor an invalid field or an unsupported operator.-
pkg/api/tests_test.go: the BigQuery tests report rejects an invalid field with aValidationErrorfor collapsed and uncollapsed queries (fails without the fix).-
pkg/api/api_test.go:IsBadRequestErrorclassifiesErrInvalidFieldas a bad request.test/e2e/filters_test.go: on/api/tests(collapsed and uncollapsed),/api/jobs/runsand/api/jobs/analysis, a valid filter column returns 200 and a quote-breakout column returns 400. An unsupported operator returns 400 on/api/tests, a/api/jobs/runsalias column, and the job analysis job runs subquery.Snyk
The Snyk CLI is not available locally.
ci/prow/securitypassed oncepkg/api/job_runs_filters.gowas excluded in.snyk. The job runs filter code in that file now matches what was there before the Snyk-only restructuring, andpkg/filteris back to its earlier shape. The nextci/prow/securityrun will confirm that the scan still passes.🤖 Generated with Claude Code
---
Generated with claude-opus-5-5
<!-- coderabbit-review -->
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
<!-- coderabbit-ai-generated:v1 -->
Summary by CodeRabbit
Bug Fixes
Invalid filter fields and unsupported operators now return
400 Bad Requestresponses across supported API endpoints.Job-run filters accept only supported fields, including the documented test-name filter.
Filter errors are reported instead of silently producing unusable queries.
Filter values are passed safely as query parameters, while valid filters continue to support column aliases and supported operators.
Documentation
* Updated API guidance to explain valid filter fields, supported job-run filters, error responses, and filter value handling.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->