Skip to content

fix(profile): reject rules with a reversed port range - #2305

Open
RaphaelFakhri wants to merge 1 commit into
safing:developmentfrom
RaphaelFakhri:fix/endpoint-reversed-port-range
Open

RaphaelFakhri wants to merge 1 commit into
safing:developmentfrom
RaphaelFakhri:fix/endpoint-reversed-port-range

Conversation

@RaphaelFakhri

@RaphaelFakhri RaphaelFakhri commented Oct 25, 2026 •

Copy link
Copy Markdown

Fixes #2304

Summary

A rule such as - * TCP/8000-80 was accepted, but its start port is greater than its end port. matchesPPP checks DstPort < StartPort || DstPort > EndPort, which is true for every port, so the rule never matched. A block rule written this way silently did nothing.

parsePPP now 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 through ValidateEndpointListConfigOption, as they already do for TCP/0-80.

Profiles that already contain such a rule keep the rest of their rules: ParseEndpoints skips invalid entries. The skipped rule matched nothing before, so the firewall behaves the same way.

Testing

  • Added testParsingFails cases for + * TCP/443-80 and - * UDP/HTTPS-HTTP to TestEndpointParsing.
  • go test -run 'TestEndpointParsing|TestEndpointFormat' ./service/profile/endpoints/ fails without the fix and passes with it.
  • gofmt -l and go vet ./service/profile/endpoints/ are clean.

Summary by CodeRabbit

  • Bug Fixes
    • Endpoint configuration now rejects TCP and UDP port ranges when the ending port is lower than the starting port, and reports that the start port cannot exceed the end port. Ranges with identical start and end ports remain valid. This ensures reversed ranges are reported as invalid instead of being accepted during parsing.

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.
@coderabbitai

coderabbitai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0f89a67e-083f-4233-85b6-f2d2553c8828
Commits

Reviewing files that changed from the base of the PR and between cc164c7 and 4cc0cc1.

Files selected for processing: 2
  • service/profile/endpoints/endpoint.go
  • service/profile/endpoints/endpoint_test.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Walkthrough

Port range parsing now rejects ranges whose end port is lower than the start port. Tests check reversed TCP port and UDP service-name ranges.

Changes: Port Range Validation

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: Normal

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: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed 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, w…
Linked Issues check Passed Issue #2304 requires that a rule with a reversed port range (start port greater than end port, for example - * TCP/8000-80 or - * UDP/HTTPS-HTTP) be rejected with a validation error, as TCP/0-80…
Out of Scope Changes check Passed 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 `te…
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 #2304 requires that a rule with a reversed port range (start port greater than end port, for example - * TCP/8000-80 or - * UDP/HTTPS-HTTP) be rejected with a validation error, as TCP/0-80 already is. At the reviewed head, parsePPP in service/profile/endpoints/endpoint.go checks if n16 &lt; ep.StartPort after the end port is parsed and returns invalidDefinitionError(fields, "start port cannot be greater than end port"). Service names are resolved to numbers before this comparison, so UDP/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. ValidateEndpointListConfigOption in endpoints.go returns the error from ParseEndpoints, so the rule settings surface the error. ParseEndpoints skips invalid entries and keeps the other rules, so existing profiles are not broken. Test cases + * TCP/443-80 and - * UDP/HTTPS-HTTP were added to TestEndpointParsing according 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 testParsingFails cases). 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@CLAassistant

CLAassistant commented Oct 25, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rules with a reversed port range are accepted but never match

2 participants