Skip to content

fix(dynamicpathdetector): :0 wildcard port no longer contaminates unrelated ports#21

Merged
entlein merged 1 commit intomainfrom
fix/endpoint-wildcard-port-overbroaden
Apr 29, 2026
Merged

fix(dynamicpathdetector): :0 wildcard port no longer contaminates unrelated ports#21
entlein merged 1 commit intomainfrom
fix/endpoint-wildcard-port-overbroaden

Conversation

@entlein
Copy link
Copy Markdown

@entlein entlein commented Apr 29, 2026

Summary

  • Drops the global wildcardPort detection in AnalyzeEndpoints that broadcast a single :0 entry across the whole slice — [":0/health", ":443/login"] no longer collapses to [":0/health", ":0/login"].
  • Each endpoint is now analyzed under its own port. Cross-port folding is the explicit job of MergeDuplicateEndpoints and only fires for same-(path, direction) siblings of an explicit :0 entry.
  • MergeDuplicateEndpoints made order-symmetric: a wildcard arriving after its specific-port siblings now sweeps seen and absorbs them (previously only the specific-after-wildcard direction worked).

Why

Flagged by Matthias on upstream kubescape#316 — single :0 entries were silently widening captured endpoints into unrelated concrete ports.

Tests

  • 3 new regression tests, all of which fail against the buggy code:
    • TestAnalyzeEndpoints_WildcardDoesNotContaminateUnrelatedPaths
    • TestAnalyzeEndpoints_OnlyMatchingPathsFoldIntoWildcard
    • TestMergeDuplicateEndpoints_SpecificFirstThenWildcard
  • Pre-existing TestAnalyzeEndpoints/Test_with_0_port updated — it had encoded the buggy behavior as expected output.
  • Full pkg/registry/file/... suite still passes (consumers: applicationprofile / containerprofile processors).

Test plan

  • Component Tests CI green
  • Performance Benchmark — quality gate green (no allocation regression vs. cdbf491)
  • Manual Integration Tests green on the matching fix/endpoint-wildcard-port-overbroaden branch in node-agent

🤖 Generated with Claude Code

… longer contaminates unrelated ports

A single :0 (wildcard-port) entry was forcing every other endpoint in
the slice through `rewritePort` and being analyzed under the wildcard
sub-tree, even when its concrete port was unrelated. Result: input like
[":0/health", ":443/login"] collapsed to [":0/health", ":0/login"],
silently widening the captured surface area.

Fix: drop the global wildcardPort detection. Each endpoint is now
analyzed under its own port; cross-port folding is the explicit job of
MergeDuplicateEndpoints, which only merges same-(path, direction)
specific-port siblings into an explicit :0 entry. The merge is now
symmetric — wildcard-after-specific sweeps `seen` and absorbs prior
specific-port entries; specific-after-wildcard folds in as before.

Tests:
  - 3 new regression tests for the contamination + reverse-order paths
  - existing "Test with 0 port" updated to encode correct behavior

Flagged in upstream review on kubescape#316.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

Summary:

  • License scan: failure
  • Credentials scan: skipped
  • Vulnerabilities scan: skipped
  • Unit test: success
  • Go linting: failure

@entlein entlein merged commit 54e7179 into main Apr 29, 2026
4 checks passed
entlein added a commit to k8sstormcenter/node-agent that referenced this pull request Apr 29, 2026
…e036602) (#34)

Picks up k8sstormcenter/storage#21:
fix(dynamicpathdetector): :0 wildcard port no longer contaminates
unrelated concrete-port endpoints.

Sibling branch on node-agent so the matrix CI can validate the fix
end-to-end before either side merges.

Co-authored-by: Entlein <eineintlein@gmail.com>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
entlein added a commit that referenced this pull request Apr 29, 2026
…eEndpoints (#22)

The table-driven TestAnalyzeEndpoints shared one PathAnalyzer across
all subtests. Because AnalyzeEndpoints mutates the analyzer trie,
expected outputs of later subtests were silently coupled to the trie
state left by earlier ones — running any case in isolation would have
exercised a different state and could mask regressions.

Move the analyzer construction inside the t.Run loop so each subtest
starts from a fresh trie. Restore the 'Test with 0 port' expected
output to its order-independent shape (the :80 entry stays as
:80/users/⋯/posts/101 because no other input reaches the trie's
dynamic-collapse threshold within that case).

Addresses CodeRabbit review on #21.

Co-authored-by: Entlein <eineintlein@gmail.com>
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.

1 participant