HYPERFLEET-1366 - refactor: remove search and order field allowlists - #322
HYPERFLEET-1366 - refactor: remove search and order field allowlists#322Mischulee wants to merge 1 commit into
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
📝 WalkthroughSummary by CodeRabbit
Walkthrough
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 10 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (10 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
Comment |
Risk Score: 0 —
|
| Signal | Detail | Points |
|---|---|---|
| PR size | 72 lines | +0 |
| Sensitive paths | none | +0 |
| Test coverage | Tests cover changed packages | +0 |
Computed by hyperfleet-risk-scorer
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
pkg/db/sql_helpers.go (1)
772-772: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winAllow digits in order field names.
After Line 772 removes the whitelist check,
orderPatternis the only field validator. Its actual pattern excludes digits, sofield2 descstill returnsinvalid order format. The pattern comment claims that digits are accepted, but the regex does not. (github.com)Update the pattern and add a regression test:
-var orderPattern = regexp.MustCompile(`^[a-z_][a-z_]*(\s+(asc|desc))?$`) +var orderPattern = regexp.MustCompile(`^[a-z_][a-z0-9_]*(\s+(asc|desc))?$`)As per PR objectives, “all fields are now valid search and order targets.”
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@pkg/db/sql_helpers.go` at line 772, The order-field validation pattern used by orderPattern must accept digits in field names, matching its documented behavior and allowing inputs such as field2 desc. Update the pattern while preserving existing direction validation, and add a regression test covering a digit-containing order field; all fields should remain valid search and order targets.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@pkg/db/sql_helpers.go`:
- Line 772: The order-field validation pattern used by orderPattern must accept
digits in field names, matching its documented behavior and allowing inputs such
as field2 desc. Update the pattern while preserving existing direction
validation, and add a regression test covering a digit-containing order field;
all fields should remain valid search and order targets.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Central YAML (base), Organization UI (inherited)
Review profile: CHILL
Plan: Enterprise
Run ID: 582f02a5-eae8-47f0-8f87-3da82c9b2d8a
📒 Files selected for processing (4)
pkg/db/sql_helpers.gopkg/db/sql_helpers_test.gopkg/services/generic_test.gotest/integration/order_field_mapping_test.go
🔗 Linked repositories identified
CodeRabbit considers these linked repositories for cross-repo context during reviews:
openshift-hyperfleet/architecture(manual)openshift-hyperfleet/hyperfleet-api(manual)openshift-hyperfleet/hyperfleet-sentinel(manual)openshift-hyperfleet/hyperfleet-adapter(manual)openshift-hyperfleet/hyperfleet-broker(manual)
💤 Files with no reviewable changes (3)
- test/integration/order_field_mapping_test.go
- pkg/db/sql_helpers_test.go
- pkg/services/generic_test.go
| return | ||
| } | ||
|
|
||
| field = trimmedName |
There was a problem hiding this comment.
The spec.* branch validates identifiers via validateJSONBKey (^[a-z0-9_]+$), but removing the search allowlist leaves the plain-field branch of getField with no character-level validation. Identifiers like id/1 or version() pass through to raw SQL text. Consider adding a similar regex for non-spec field segments.
|
The PR removes four tests that guarded against invalid field names (including the
|
Summary
Removes the
searchAllowedFieldsandorderAllowedFieldsallowlists frompkg/db/sql_helpers.goso all fields are now valid search and order targets.Test Plan
make test-allpassesmake lintpassesmake test-helm(if applicable)