HYPERFLEET-1259 - fix: SQL injection protection for orderBy/search#244
HYPERFLEET-1259 - fix: SQL injection protection for orderBy/search#244ma-hill wants to merge 1 commit into
Conversation
|
Skipping CI for Draft Pull Request. |
|
[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 |
|
Caution Review failedAn error occurred during the review process. Please try again later. 📝 WalkthroughSummary by CodeRabbitRelease Notes
WalkthroughAdds a per-resource Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 9 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (9 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
Comment |
|
@coderabbitai review |
✅ Action performedReview finished.
|
Summary
Implements allowlist-based SQL injection protection for orderBy and search query parameters. Previously, the API validated field names against a disallowedFields blocklist, but attackers could potentially inject SQL functions (like
pg_sleep(),version()) or arbitrary column names that weren't explicitly blocked. This adds a comprehensive allowlist (OrderByAllowedFields) per resource type that explicitly enumerates valid sortable/searchable columns, rejecting anything not in the allowlist.HYPERFLEET-1259
Changes
OrderByAllowedFieldsmap inpkg/db/sql_helpers.godefining valid columns for Cluster, NodePool, and Resource types (includes standard fields likeid,name,created_time,status_conditions, plus resource-specific fields likeowner_idfor NodePools)getField()to validate field names against the allowlist after existing checks, returningHYPERFLEET-VAL-005error for disallowed fieldsallowedFieldsparameter throughFieldNameWalk(),cleanOrderBy(), andArgsToOrderBy()functions to enforce validation at every field name resolution pointnewListContext()to ensure resource types have allowlist configured, returning clear error message if missingcleanOrderBy()to use explicit error returns instead of naked returns, improving readabilitytrimedName→trimmedNamenilfor allowedFields where allowlist validation is not under testTest Plan
make test-allpassesmake lintpasses