feat: validate routing CEL expressions at write time in create/update handlers - #5288
Conversation
|
Warning Review limit reachedYou’ve reached a temporary PR review limit under our Fair Usage Limits Policy. Next review available in: 54 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughRouting rule handlers now validate CEL expressions before creating or updating rules. A cached governance helper normalizes map keys, performs routing schema validation, compiles expressions, and reports invalid input. Tests cover valid, empty, and invalid expressions. ChangesRouting CEL validation
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant HTTPClient
participant createRoutingRule
participant ValidateRoutingCELExpression
participant routing.ValidateCELExpression
HTTPClient->>createRoutingRule: Submit cel_expression
createRoutingRule->>ValidateRoutingCELExpression: Validate expression
ValidateRoutingCELExpression->>routing.ValidateCELExpression: Validate normalized expression
routing.ValidateCELExpression-->>ValidateRoutingCELExpression: Return validation result
ValidateRoutingCELExpression-->>createRoutingRule: Return error or success
createRoutingRule-->>HTTPClient: Return HTTP 400 or create rule
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
11b071c to
0698f7b
Compare
a4770ad to
c0909f9
Compare
Confidence Score: 5/5This looks safe to merge.
Important Files Changed
Reviews (2): Last reviewed commit: "feat: routing rules CEL expression valid..." | Re-trigger Greptile |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
transports/bifrost-http/handlers/governance.go (1)
4007-4011: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winAdd handler-level regression tests for the 400 contract.
The helper tests cover compilation, but not that create/update handlers return
400and skip persistence whencel_expressionis invalid. Add focused tests for both paths, including an update where the field is omitted.Also applies to: 4124-4129
🤖 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 `@transports/bifrost-http/handlers/governance.go` around lines 4007 - 4011, Add focused regression tests for the create and update governance handlers around their ValidateRoutingCELExpression calls, asserting malformed cel_expression returns HTTP 400 and does not persist changes. Include an update case with cel_expression omitted to confirm it remains valid and follows the existing update behavior.
🤖 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.
Nitpick comments:
In `@transports/bifrost-http/handlers/governance.go`:
- Around line 4007-4011: Add focused regression tests for the create and update
governance handlers around their ValidateRoutingCELExpression calls, asserting
malformed cel_expression returns HTTP 400 and does not persist changes. Include
an update case with cel_expression omitted to confirm it remains valid and
follows the existing update behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: a4a8cb09-e54b-4dad-820e-a39952573b6e
📒 Files selected for processing (3)
plugins/governance/routing.goplugins/governance/routing_test.gotransports/bifrost-http/handlers/governance.go
Merge activity
|
0698f7b to
e36d64e
Compare
e36d64e to
8b87614
Compare
… handlers (#5288) ## Summary Routing rule CEL expressions were previously only compiled and validated at first evaluation, meaning a malformed expression could be persisted successfully and fail silently at runtime. This PR adds write-time validation so that invalid CEL expressions are rejected with a `400` error when a routing rule is created or updated. ## Changes - Added `ValidateRoutingCELExpression` in `plugins/governance/routing.go` that builds the CEL environment once (via `sync.Once`) and compiles the normalized expression, returning a descriptive error on any syntax or type problem. Empty/whitespace-only expressions are treated as match-all and pass validation. - Wired `ValidateRoutingCELExpression` into the `createRoutingRule` and `updateRoutingRule` HTTP handlers so invalid expressions are rejected at write time. The update handler only validates when `CelExpression` is explicitly supplied, so unrelated updates (e.g. toggling `enabled`) are unaffected. - Added `TestValidateRoutingCELExpression` covering valid expressions (empty, whitespace, equality, `contains`, header lookup, conjunction) and invalid ones (unknown identifiers, syntax errors, type mismatches, dangling operators). ## Type of change - [ ] Bug fix - [x] Feature - [ ] Refactor - [ ] Documentation - [ ] Chore/CI ## Affected areas - [ ] Core (Go) - [x] Transports (HTTP) - [ ] Providers/Integrations - [x] Plugins - [ ] UI (React) - [ ] Docs ## How to test ```sh go test ./plugins/governance/... ./transports/bifrost-http/... ``` To validate manually, attempt to create or update a routing rule with an invalid CEL expression (e.g. `model ==`) and confirm a `400` response is returned with a descriptive error message. A valid expression (e.g. `model == "gpt-4o"`) should be accepted as before. ## Screenshots/Recordings N/A ## Breaking changes - [ ] Yes - [x] No ## Related issues ## Security considerations CEL expressions are now compiled before persistence, reducing the risk of storing expressions that could cause unexpected runtime behaviour or panics during evaluation. ## Checklist - [ ] I read `docs/contributing/README.md` and followed the guidelines - [x] I added/updated tests where appropriate - [ ] I updated documentation where needed - [x] I verified builds succeed (Go and UI) - [ ] I verified the CI pipeline passes locally if applicable
… handlers (#5288) ## Summary Routing rule CEL expressions were previously only compiled and validated at first evaluation, meaning a malformed expression could be persisted successfully and fail silently at runtime. This PR adds write-time validation so that invalid CEL expressions are rejected with a `400` error when a routing rule is created or updated. ## Changes - Added `ValidateRoutingCELExpression` in `plugins/governance/routing.go` that builds the CEL environment once (via `sync.Once`) and compiles the normalized expression, returning a descriptive error on any syntax or type problem. Empty/whitespace-only expressions are treated as match-all and pass validation. - Wired `ValidateRoutingCELExpression` into the `createRoutingRule` and `updateRoutingRule` HTTP handlers so invalid expressions are rejected at write time. The update handler only validates when `CelExpression` is explicitly supplied, so unrelated updates (e.g. toggling `enabled`) are unaffected. - Added `TestValidateRoutingCELExpression` covering valid expressions (empty, whitespace, equality, `contains`, header lookup, conjunction) and invalid ones (unknown identifiers, syntax errors, type mismatches, dangling operators). ## Type of change - [ ] Bug fix - [x] Feature - [ ] Refactor - [ ] Documentation - [ ] Chore/CI ## Affected areas - [ ] Core (Go) - [x] Transports (HTTP) - [ ] Providers/Integrations - [x] Plugins - [ ] UI (React) - [ ] Docs ## How to test ```sh go test ./plugins/governance/... ./transports/bifrost-http/... ``` To validate manually, attempt to create or update a routing rule with an invalid CEL expression (e.g. `model ==`) and confirm a `400` response is returned with a descriptive error message. A valid expression (e.g. `model == "gpt-4o"`) should be accepted as before. ## Screenshots/Recordings N/A ## Breaking changes - [ ] Yes - [x] No ## Related issues ## Security considerations CEL expressions are now compiled before persistence, reducing the risk of storing expressions that could cause unexpected runtime behaviour or panics during evaluation. ## Checklist - [ ] I read `docs/contributing/README.md` and followed the guidelines - [x] I added/updated tests where appropriate - [ ] I updated documentation where needed - [x] I verified builds succeed (Go and UI) - [ ] I verified the CI pipeline passes locally if applicable

Summary
Routing rule CEL expressions were previously only compiled and validated at first evaluation, meaning a malformed expression could be persisted successfully and fail silently at runtime. This PR adds write-time validation so that invalid CEL expressions are rejected with a
400error when a routing rule is created or updated.Changes
ValidateRoutingCELExpressioninplugins/governance/routing.gothat builds the CEL environment once (viasync.Once) and compiles the normalized expression, returning a descriptive error on any syntax or type problem. Empty/whitespace-only expressions are treated as match-all and pass validation.ValidateRoutingCELExpressioninto thecreateRoutingRuleandupdateRoutingRuleHTTP handlers so invalid expressions are rejected at write time. The update handler only validates whenCelExpressionis explicitly supplied, so unrelated updates (e.g. togglingenabled) are unaffected.TestValidateRoutingCELExpressioncovering valid expressions (empty, whitespace, equality,contains, header lookup, conjunction) and invalid ones (unknown identifiers, syntax errors, type mismatches, dangling operators).Type of change
Affected areas
How to test
go test ./plugins/governance/... ./transports/bifrost-http/...To validate manually, attempt to create or update a routing rule with an invalid CEL expression (e.g.
model ==) and confirm a400response is returned with a descriptive error message. A valid expression (e.g.model == "gpt-4o") should be accepted as before.Screenshots/Recordings
N/A
Breaking changes
Related issues
Security considerations
CEL expressions are now compiled before persistence, reducing the risk of storing expressions that could cause unexpected runtime behaviour or panics during evaluation.
Checklist
docs/contributing/README.mdand followed the guidelines