Validate activities order_key against an allowlist - #51556
Conversation
Route the activities list queries through the allowlist-validated order-by helper instead of the deprecated regex-only one, so callers can only sort by known columns. Adds per-query allowlists and regression tests for both endpoints.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (5)
Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review. WalkthroughThe fleet and host activity endpoints now validate Possibly related PRs
Merge Risk: ⚪ Minimal · up to The activities endpoints now reject unsupported sort keys while preserving valid ordering and pagination, and no actionable merge-blocking risk remains after normal checks and review. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ast-grep (0.45.1)server/service/integration_enterprise_test.goast-grep timed out on this file server/service/integration_mdm_test.goast-grep timed out on this file Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
/agentic_review |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #51556 +/- ##
==========================================
+ Coverage 68.92% 68.94% +0.01%
==========================================
Files 4009 4010 +1
Lines 259778 260145 +367
Branches 13727 13727
==========================================
+ Hits 179061 179366 +305
- Misses 64863 64919 +56
- Partials 15854 15860 +6
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Code Review by Qodo
1. Qualified ID key rejected
|
The activities order-key allowlist accepts the documented unqualified keys (id, created_at, ...). Update integration tests that passed the qualified "a.id" form to "id", and document the allowed sort fields for the activities endpoints instead of "any column".
|
Could you also please remove the |
Related issue: N/A
Description
The activities list endpoints (
GET /api/v1/fleet/activitiesandGET /api/v1/fleet/hosts/{id}/activities) applied theorder_keyparameter through the deprecatedAppendListOptionsWithParamshelper, which only regex-filters the column name and does not check it against an allowlist. This let a caller sort by (and cursor-paginate over) arbitrary columns, including ones not in the SELECT.This routes both queries through
AppendListOptionsWithParamsSecurewith a per-query order-key allowlist, so only known sort keys are accepted and anything else returns a 422. It mirrors how the other list endpoints (hosts, labels, software, certificates, MDM commands) already validate their sort keys. This was the last remaining caller of the deprecated helper.Checklist for submitter
changes/.SELECT *is avoided, SQL injection is prevented (using placeholders for values in statements) — the sort key is validated against an allowlist and mapped to a fixed column expression; all values remain parameterized.Testing
id/created_atsorting and pagination still work.order_key=a.detailsnow returns a 422invalid order_key, whileid/created_at/the default still return 200 with correct ordering.cc @lukeheath for review.
Summary by CodeRabbit
created_atfield.