Skip to content

fix(gatewayapi): return 500 for route rules with invalid filters - #10454

Open
vshalpnjabi wants to merge 2 commits into
envoyproxy:mainfrom
vshalpnjabi:fix-httproute-filter-error-directresponse
Open

vshalpnjabi wants to merge 2 commits into
envoyproxy:mainfrom
vshalpnjabi:fix-httproute-filter-error-directresponse

Conversation

@vshalpnjabi

Copy link
Copy Markdown

What this PR does / why we need it:
Gateway API says implementations SHOULD treat a route rule with an invalid filter combination or order as invalid. Today an HTTPRoute filter error still leaves a RequestRedirect on the IR next to the 500, and GRPCRoute skips the 500 entirely if a filter already set DirectResponse or Redirect.

This follows the direction agreed on #9460 (thanks @Aias00): for both HTTPRoute and GRPCRoute, a filter-processing error discards any redirect, replaces a filter-set direct response, and programs 500. Accepted=False (or PartiallyInvalid when some rules are still valid) is unchanged. Destination and no-ready-endpoint handling is left as-is; the spec text is about filters, not backends.

Which issue(s) this PR fixes:
Fixes #9454


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: go test and go test -race on ./internal/gatewayapi/, make lint.golint, gofmt, the release-notes filename check, and yamllint and codespell on the changed files all pass. The new goldens fail on main and pass with the fix. I didn't run make generate gen-check or the full make lint locally, since there are no API or generated changes.
  • Tests added/updated: Added httproute-with-invalid-filter-and-redirect and grpcroute-with-invalid-filter-and-directresponse translator goldens, and dropped the leftover redirect from httproutefilter-with-grpc-json-transcoder-and-url-rewrite.
  • Docs: N/A: no docs change.
  • Release notes: Added release-notes/current/bug_fixes/9454-invalid-filter-rule-500.md.
  • Generated files committed: N/A: no generated files.
  • Scope & compatibility: Scoped to the filter-error path. An invalid GRPCRoute rule that had a filter-set direct response now returns 500 instead of that response, which is the spec behavior this PR is for.
  • Codex review: Requested a Codex review and addressed all of its comments.
  • Copilot review: Requested a Copilot review and addressed all of its comments.

Follows the Gateway API guidance that implementations SHOULD treat a
route rule with an invalid filter combination or order as invalid.
Filter-processing errors now discard any redirect and install a 500
DirectResponse on both HTTPRoute and GRPCRoute, matching the
direction agreed on envoyproxy#9460.

Signed-off-by: Vishal Punjabi <10079537+vshalpnjabi@users.noreply.github.com>
@vshalpnjabi
vshalpnjabi requested a review from a team as a code owner October 29, 2026 22:33
@netlify

netlify Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

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

Name Link
🔨 Latest commit cdfec4a
🔍 Latest deploy log https://app.netlify.com/projects/cerulean-figolla-1f9435/deploys/6ae4c29983cb940346adabf4
😎 Deploy Preview https://deploy-preview-10454--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 Oct 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-30T16:20:52.142743Z cdfec4a 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: f0344a30d1

ℹ️ 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".


switch {
// return 500 if any filter processing error occurred
// Invalid filters make the rule invalid: return 500 and drop any redirect.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Validate filters after terminal direct responses

When a DirectResponse ExtensionRef precedes the bad filter, ProcessHTTPFilters and ProcessGRPCFilters stop on the existing direct response at filters.go:142-145 and filters.go:269-272, leaving processFilterError nil, so this new 500 path is never run. Reversing the two filters in either new fixture therefore still serves the configured 418/404 and reports the rule as valid; continue validating later filters (while suppressing their effects) so filter order cannot bypass the invalid-rule response.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for pointing this out. Filters after a DirectResponse are now still validated without applying their effects, so an invalid filter later in the list returns 500. Added HTTPRoute and GRPCRoute tests for that order.

@codecov

codecov Bot commented Oct 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.27%. Comparing base (bab8da5) to head (f0344a3).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10454      +/-   ##
==========================================
- Coverage   82.28%   82.27%   -0.01%     
==========================================
  Files         277      277              
  Lines       43617    43617              
==========================================
- Hits        35891    35887       -4     
- Misses       7725     7729       +4     
  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.

A valid DirectResponse stopped later filter processing, so listing it
before an invalid filter still served 418/404 and left the rule accepted.
Keep validating remaining filters without applying their IR effects so
filter order cannot bypass the invalid-rule 500.

Signed-off-by: Vishal Punjabi <10079537+vshalpnjabi@users.noreply.github.com>

@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: cdfec4aff2

ℹ️ 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 on lines +133 to +137
return &HTTPFiltersContext{
ParentRef: ctx.ParentRef,
Route: ctx.Route,
RuleIdx: ctx.RuleIdx,
HTTPFilterIR: &HTTPFilterIR{},

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve state across post-DirectResponse validation

The prior terminal break is gone, but this helper creates a brand-new empty HTTPFilterIR for every filter after a DirectResponse. If a valid RequestMirror (or gRPC JSON transcoder) follows that response, its state is discarded before the post-loop incompatibility checks in ProcessHTTPFilters, so the pair is accepted and the configured response is served; the same filters in reverse order are rejected. Keep one cumulative validation context containing the earlier terminal state while suppressing only emitted effects.

Useful? React with 👍 / 👎.

Comment on lines +1611 to 1613
irRoute.Redirect = nil
irRoute.DirectResponse = &ir.CustomResponse{
StatusCode: new(uint32(500)),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Attach 500 routes for all-invalid GRPCRoutes

When this is the only invalid GRPCRoute rule, the 500 built here never reaches xDS: processGRPCRouteParentRefs sets Accepted=False and takes the lines 1458-1460 continue before processHTTPRouteParentRefListener. Both new GRPC fixtures add a second valid rule specifically to avoid that path, so a normal single-rule route still has no matching 500 even though the added release note promises a 500 while Accepted remains false. Attach these generated error routes before the all-rules-invalid short-circuit, as the HTTPRoute flow already does.

Useful? React with 👍 / 👎.

Comment on lines +393 to 396
irRoute.Redirect = nil
irRoute.DirectResponse = &ir.CustomResponse{
StatusCode: new(uint32(500)),
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Remove stale DirectResponse headers from generated 500s

When a DirectResponse with contentType or header precedes the bad filter, applyHTTPFiltersContextToIRRoute has already copied those values into irRoute.AddResponseHeaders; this branch replaces only the DirectResponse object and clears Redirect. The new httproute-with-directresponse-then-invalid-filter.out.yaml golden therefore emits Content-Type: text/plain on the generated 500, and arbitrary DirectResponse headers such as Set-Cookie would likewise survive even though that response was rejected. Remove the old DirectResponse header mutations when installing the error response.

Useful? React with 👍 / 👎.

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.

HTTP route rule processing does not check for DirectResponse or Redirect when filter processing has an error

1 participant