Repository navigation
fix(profile): reject rules with a reversed port range - #2305
RaphaelFakhri wants to merge 1 commit into
Conversation
A rule such as "- * TCP/8000-80" was accepted, but its start port is greater than its end port, so it never matched any connection. Reject it during parsing so the rule settings show an error instead of silently ignoring the rule.
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Port range validation and tests service/profile/endpoints/endpoint.go, service/profile/endpoints/endpoint_test.go |
parsePPP returns an invalid-definition error for reversed ranges. Tests verify that TCP/443-80 and UDP/HTTPS-HTTP fail to parse. |
Priority:
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix · Severity of issue fixed: Medium
Merge Risk: 
Minimal · up to 4cc0c
-
The PR addresses invalid reversed port ranges with focused tests and has no evidenced merge-blocking risk.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Title check
-
Explanation
The title names the main change: parsePPP now rejects port ranges whose end port is lower than the start port, so reversed-range rules are rejected. It matches the raw summary and the PR objectives, which both describe this change. The title uses the conventional fix(scope) prefix and is concise.
Full details: Linked Issues check
-
Explanation
Issue
#2304requires that a rule with a reversed port range (start port greater than end port, for example- * TCP/8000-80or- * UDP/HTTPS-HTTP) be rejected with a validation error, asTCP/0-80already is. At the reviewed head,parsePPPin service/profile/endpoints/endpoint.go checksif n16 < ep.StartPortafter the end port is parsed and returnsinvalidDefinitionError(fields, "start port cannot be greater than end port"). Service names are resolved to numbers before this comparison, soUDP/HTTPS-HTTP(443 to 80) is also rejected. Single-port rules (TCP/443) and equal start and end ports are not affected, because the start port equals the parsed end port.ValidateEndpointListConfigOptionin endpoints.go returns the error fromParseEndpoints, so the rule settings surface the error.ParseEndpointsskips invalid entries and keeps the other rules, so existing profiles are not broken. Test cases+ * TCP/443-80and- * UDP/HTTPS-HTTPwere added toTestEndpointParsingaccording to the PR description and the summary. The base revision of endpoint.go could not be read (blob unavailable), so the before-state is inferred from the issue text and the +3/-0 summary. I did not run the tests.
Full details: Out of Scope Changes check
-
Explanation
The whole-PR change set, per the summary, touches only service/profile/endpoints/endpoint.go (+3 lines, the reversed-range check) and service/profile/endpoints/endpoint_test.go (+13 lines, the new
testParsingFailscases). Both changes implement the objective of#2304. No unrelated files or behavior changes appear in the supplied evidence. The base-side diff could not be read, so completeness of the file list relies on the supplied summary.
-
-
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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 @coderabbitai help to get the list of available commands.
Fixes #2304
Summary
A rule such as
- * TCP/8000-80was accepted, but its start port is greater than its end port.matchesPPPchecksDstPort < StartPort || DstPort > EndPort, which is true for every port, so the rule never matched. A block rule written this way silently did nothing.parsePPPnow rejects a range whose end port is lower than its start port, with the error "start port cannot be greater than end port". The rule settings show this error throughValidateEndpointListConfigOption, as they already do forTCP/0-80.Profiles that already contain such a rule keep the rest of their rules:
ParseEndpointsskips invalid entries. The skipped rule matched nothing before, so the firewall behaves the same way.Testing
testParsingFailscases for+ * TCP/443-80and- * UDP/HTTPS-HTTPtoTestEndpointParsing.go test -run 'TestEndpointParsing|TestEndpointFormat' ./service/profile/endpoints/fails without the fix and passes with it.gofmt -landgo vet ./service/profile/endpoints/are clean.Summary by CodeRabbit