Skip to content

fix: reject unspecified backend endpoint addresses - #10657

Open
rajath201 wants to merge 3 commits into
envoyproxy:mainfrom
rajath201:backend-unspecified-ip
Open

rajath201 wants to merge 3 commits into
envoyproxy:mainfrom
rajath201:backend-unspecified-ip

Conversation

@rajath201

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:

validateIP in internal/gatewayapi/backend.go is what keeps a Backend from pointing at the proxy's own localhost (the Envoy admin interface listens on 127.0.0.1:19000), but it only checks IsLoopback(). The unspecified addresses 0.0.0.0 and :: (and the IPv4-mapped 0:0:0:0:0:ffff:0:0) match the CRD address pattern and pass that check, and on Linux a connect() to the unspecified address is delivered to the local host. A Backend endpoint of 0.0.0.0:19000 therefore reaches the loopback-only admin listener from any route that references it, outside the Host infrastructure where loopback is supposed to be rejected.

The fix treats unmapped unspecified addresses like loopback in validateIP, the same set isBlockedOIDCDiscoveryAddr already blocks for OIDC discovery. Keeping it in the validator covers every Backend reference path without touching the CRD pattern, and Host mode keeps its existing behavior. New cases in TestValidateIPRunningOnHost fail on main (0.0.0.0, :: and the mapped form are accepted) and pass with the change.

Which issue(s) this PR fixes:

N/A, no tracking issue.


PR Checklist

  • Authorship & ownership: Coding agents / AI assistants are welcome, but I have reviewed every change, understand how and why it works, can explain and maintain it, and take full responsibility for this PR. I have not submitted generated output I do not understand.
  • DCO: All commits are signed off (git commit -s). See DCO: Sign your work.
  • API agreed first: N/A: no API changes.
  • Required checks pass: make generate gen-check, make lint, and the unit-test/coverage build pass. (Flaky e2e failures are not considered breakages, but gen-check, lint, and coverage MUST pass.) Ran go test ./internal/gatewayapi/..., go vet and gofmt locally; relying on CI for make lint and gen-check.
  • Tests added/updated: New/changed code is covered by appropriate tests. N/A if this PR does not contain code changes.
  • Docs: N/A: the Backend docs already state that loopback addresses are forbidden; this aligns the validator with that.
  • Release notes: Added release-notes/current/security_updates/10638-backend-unspecified-ip.md.
  • Generated files committed: N/A: no API, helm chart or module changes.
  • Scope & compatibility: The PR is reasonably scoped (no unrelated changes) and preserves backward compatibility, or any breaking change is called out above and documented in release-notes/current/breaking_changes/.
  • Codex review: Requested a Codex review and addressed all of its comments.
  • Copilot review: Requested a Copilot review and addressed all of its comments.

Signed-off-by: RAJATH MOHARE <rajath@digiscrypt.com>
@rajath201
rajath201 requested a review from a team as a code owner November 18, 2026 11:08
@netlify

netlify Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for cerulean-figolla-1f9435 ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit e287ae4
🔍 Latest deploy log https://app.netlify.com/projects/cerulean-figolla-1f9435/deploys/6b12ed2eaa13e0e90f409c3a
😎 Deploy Preview https://deploy-preview-10657--cerulean-figolla-1f9435.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-04T16:43:23.583413Z e287ae4 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4da3a36ff0

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread internal/gatewayapi/backend.go Outdated
fmt.Errorf("IP address %s in the loopback range is only supported when using the Host infrastructure", epIP.Address),
status.RouteReasonInvalidAddress,
)
} else if ip.Unmap().IsUnspecified() && !runningOnHost {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Update the rejected egctl test endpoint

In the checked TestTranslate backend-endpoint case (internal/cmd/egctl/testdata/translate/in/backend-endpoint.yaml:45), the Translator is created with its zero-value RunningOnHost=false, but that fixture still uses 0.0.0.0 and the golden expects the Backend to be accepted. This branch therefore emits Accepted=False (and ResolvedRefs=False for the route), making the unconditional comparison at internal/cmd/egctl/translate_test.go:437 fail whenever go test ./internal/cmd/egctl runs; update the fixture and golden to use a permitted endpoint along with this validator change.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Moved that fixture endpoint to 1.1.1.1 (the address other Backend testdata uses) and regenerated backend-endpoint.all.yaml, so the Backend stays Accepted there and the rejection is only covered by TestValidateIPRunningOnHost. go test ./internal/cmd/egctl and gen-check are clean locally.

The egctl translate fixture used 0.0.0.0 as a Backend endpoint, which the
new check rejects, so TestTranslate/backend-endpoint and gen-check both
failed. Use a routable address there instead; the rejection is already
covered by TestValidateIPRunningOnHost.

gocritic flagged the three-branch if-else chain in validateIP, so it is a
switch now with no behavior change.

Signed-off-by: RAJATH MOHARE <rajath@digiscrypt.com>
@rajath201

Copy link
Copy Markdown
Contributor Author

Pushed fixes for the lint and gen-check/coverage-test failures: validateIP is a switch now (gocritic flagged the three-branch if-else) and the egctl backend-endpoint fixture no longer uses 0.0.0.0, with its golden regenerated. No behavior change to the validator itself.

@codecov

codecov Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.86%. Comparing base (2050544) to head (e287ae4).
⚠️ Report is 68 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff            @@
##             main   #10657    +/-   ##
========================================
  Coverage   82.86%   82.86%            
========================================
  Files         278      278            
  Lines       44597    44698   +101     
========================================
+ Hits        36954    37040    +86     
- Misses       7642     7657    +15     
  Partials        1        1            

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

return status.NewRouteStatusError(
fmt.Errorf("IP address %s is unspecified and connects to the loopback interface, which is only supported when using the Host infrastructure", epIP.Address),
status.RouteReasonInvalidAddress,
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we add a default case here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added one, so every path returns from the switch instead of falling through to a trailing return nil.

Signed-off-by: RAJATH MOHARE <rajath@digiscrypt.com>

This branch has not been deployed

No deployments
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.

2 participants