Skip to content

oauth2: fix passthrough logic to avoid modifying request when skipping filter#40718

Merged
wbpcode merged 3 commits intoenvoyproxy:mainfrom
ggmoy:oauth2-fix-passthrough-logic
Aug 26, 2025
Merged

oauth2: fix passthrough logic to avoid modifying request when skipping filter#40718
wbpcode merged 3 commits intoenvoyproxy:mainfrom
ggmoy:oauth2-fix-passthrough-logic

Conversation

@ggmoy
Copy link
Copy Markdown
Contributor

@ggmoy ggmoy commented Aug 14, 2025

Description

This PR fixes a bug introduced in PR #40228, where OAuth2 cookies were removed for requests matching the pass_through_matcher configuration. This broke setups with multiple OAuth2 filter instances using different pass_through_matcher configurations, because the first matching instance removed the OAuth2 cookies--even when a passthrough was intended--impacting subsequent filters that still needed those cookies.

The changes in this PR realign the filter behavior with the documentation, which states that pass_through_matcher provides an interface for users to specify header matching criteria such that, when applicable, the OAuth flow is entirely skipped. When this occurs, only the oauth_passthrough metric is incremented; no cookies or request headers are modified, and no OAuth success is recorded.

In summary, when the pass_through_matcher configuration matches, the filter should simply skip processing and leave the request untouched.


Commit Message: oauth2: fix passthrough logic to avoid modifying request when skipping filter
Risk Level: Low
Testing: Unit test added and single page app test fixed by envoyproxy/examples PR #819
Docs Changes: N/A
Release Notes: Added
Platform Specific Features: N/A

@mathetake
Copy link
Copy Markdown
Member

@zhaohuabing could you take a look?

@mathetake
Copy link
Copy Markdown
Member

@ggmoy you need to write a unit test for this to prevent this from being resurfaced again.

@ggmoy
Copy link
Copy Markdown
Contributor Author

ggmoy commented Aug 15, 2025

@mathetake, the unit test has just been added.

@ggmoy
Copy link
Copy Markdown
Contributor Author

ggmoy commented Aug 15, 2025

@mathetake , I'm just looking into the verify_examples failing test.

@ggmoy
Copy link
Copy Markdown
Contributor Author

ggmoy commented Aug 15, 2025

@mathetake, envoyproxy/examples PR #814 has been created to fix the issue with the verify_examples test.

@mathetake
Copy link
Copy Markdown
Member

you can ignore the verify_examples CI for now -- it's not mandatory for PRs as long as they don't touch them

@phlax
Copy link
Copy Markdown
Member

phlax commented Aug 15, 2025

would be good to get signoff from @zhaohuabing here and in examples repo

preferably dont land with examples broken as it will break examples for all ci

Copy link
Copy Markdown
Member

@zhaohuabing zhaohuabing left a comment

Choose a reason for hiding this comment

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

This PR looks good to me. Thanks for fixing this!

@ggmoy ggmoy force-pushed the oauth2-fix-passthrough-logic branch from 5fc7245 to 337e4cf Compare August 19, 2025 14:22
@ggmoy
Copy link
Copy Markdown
Contributor Author

ggmoy commented Aug 19, 2025

@phlax / @zhaohuabing / @wbpcode , all tests ran successfully now that envoyproxy/examples PR #819 is merged.

Copy link
Copy Markdown
Member

@wbpcode wbpcode left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution. Thought it looks goold to me. ping @zhaohuabing for a second check to this for the logic change.

@wbpcode
Copy link
Copy Markdown
Member

wbpcode commented Aug 22, 2025

/wait-any

@zhaohuabing
Copy link
Copy Markdown
Member

zhaohuabing commented Aug 22, 2025

Thanks for the contribution. Thought it looks goold to me. ping @zhaohuabing for a second check to this for the logic change.

The PR makes sense as multiple OAuth2 filters may exist in the same HCM filter chain, and each has its own PassThroughMatcher.

@zhaohuabing
Copy link
Copy Markdown
Member

zhaohuabing commented Aug 22, 2025

@ggmoy Can you rebase this PR based on the lastest main branch?

@ggmoy ggmoy force-pushed the oauth2-fix-passthrough-logic branch from 7823b58 to 7b2726d Compare August 24, 2025 00:18
ggmoy added 3 commits August 25, 2025 15:04
Signed-off-by: Gustavo Moyano <gustavo.g.moyano@gmail.com>
Signed-off-by: Gustavo Moyano <gustavo.g.moyano@gmail.com>
Signed-off-by: Gustavo Moyano <gustavo.g.moyano@gmail.com>
@ggmoy ggmoy force-pushed the oauth2-fix-passthrough-logic branch from 7b2726d to 5d05e37 Compare August 25, 2025 15:05
@ggmoy
Copy link
Copy Markdown
Contributor Author

ggmoy commented Aug 25, 2025

@ggmoy Can you rebase this PR based on the lastest main branch?

@zhaohuabing, done!

Copy link
Copy Markdown
Member

@wbpcode wbpcode left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks.

@wbpcode wbpcode merged commit d9e0412 into envoyproxy:main Aug 26, 2025
24 checks passed
melginaldi pushed a commit to melginaldi/envoy that referenced this pull request Aug 26, 2025
…g filter (envoyproxy#40718)

### Description

This PR fixes a bug introduced in PR envoyproxy#40228, where OAuth2 cookies were
removed for requests matching the `pass_through_matcher` configuration.
This broke setups with multiple OAuth2 filter instances using different
`pass_through_matcher` configurations, because the first matching
instance removed the OAuth2 cookies--even when a passthrough was
intended--impacting subsequent filters that still needed those cookies.

The changes in this PR realign the filter behavior with the
documentation, which states that `pass_through_matcher` provides an
interface for users to specify header matching criteria such that, when
applicable, the OAuth flow is entirely skipped. When this occurs, only
the `oauth_passthrough` metric is incremented; no cookies or request
headers are modified, and no OAuth success is recorded.

In summary, when the `pass_through_matcher` configuration matches, the
filter should simply skip processing and leave the request untouched.

---

**Commit Message:** oauth2: fix passthrough logic to avoid modifying
request when skipping filter
**Risk Level:** Low
**Testing:** Unit test added and single page app test fixed by
[envoyproxy/examples PR
envoyproxy#819](envoyproxy/examples#819)
**Docs Changes:** N/A
**Release Notes:** Added
**Platform Specific Features:** N/A

---------

Signed-off-by: Gustavo Moyano <gustavo.g.moyano@gmail.com>
Signed-off-by: Melissa Ginaldi <mginaldi@google.com>
wtzhang23 pushed a commit to wtzhang23/envoy that referenced this pull request Aug 27, 2025
…g filter (envoyproxy#40718)

### Description

This PR fixes a bug introduced in PR envoyproxy#40228, where OAuth2 cookies were
removed for requests matching the `pass_through_matcher` configuration.
This broke setups with multiple OAuth2 filter instances using different
`pass_through_matcher` configurations, because the first matching
instance removed the OAuth2 cookies--even when a passthrough was
intended--impacting subsequent filters that still needed those cookies.

The changes in this PR realign the filter behavior with the
documentation, which states that `pass_through_matcher` provides an
interface for users to specify header matching criteria such that, when
applicable, the OAuth flow is entirely skipped. When this occurs, only
the `oauth_passthrough` metric is incremented; no cookies or request
headers are modified, and no OAuth success is recorded.

In summary, when the `pass_through_matcher` configuration matches, the
filter should simply skip processing and leave the request untouched.

---

**Commit Message:** oauth2: fix passthrough logic to avoid modifying
request when skipping filter
**Risk Level:** Low
**Testing:** Unit test added and single page app test fixed by
[envoyproxy/examples PR
envoyproxy#819](envoyproxy/examples#819)
**Docs Changes:** N/A
**Release Notes:** Added
**Platform Specific Features:** N/A

---------

Signed-off-by: Gustavo Moyano <gustavo.g.moyano@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.

5 participants