Repository navigation
Description
Title: oauth2 filter: browser blocks BearerToken cookie because its size too large
Description:
I expected the cookie for BearerToken to be set on the response when forward_bearer_token: true. Instead, the browser (Chrome Version 114.0.5735.106) returns an error message on the attempt:
The attempt to set a cookie via a Set-Cookie header was blocked because the cookie was too large. The combined size of the name and value must be less than or equal to 4096 characters.
Then, the behavior is similar to #21819, where the browser enters a 302 redirect loop.
It would be an improvement if the oauth2 filter could do anyone of the following:
- Log a warning if the cookie size is too large
- Allow one to only set the Authorization header and not use cookies
- Set multiple cookies, each less than the max size, for a large BearerToken, e.g. splitting it up into parts that could be reassembled by the consumer
Repro steps:
With auth_scopes set to only openid, the id token is a reasonable size. With cloud providers such as Azure, when adding additional scopes for Microsoft applications, e.g. https://cognitiveservices.azure.com/.default, the access token returned seems to return a list of groups, which for some users can be quite large. Microsoft doesn't seem to allow customization of this token.
Config:
Using envoy:v1.26.1
- name: envoy.filters.http.oauth2
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.oauth2.v3.OAuth2
config:
token_endpoint:
cluster: <omitted>
uri: https://login.microsoftonline.com/<omitted>/oauth2/v2.0/token
timeout: 10s
authorization_endpoint: https://login.microsoftonline.com/<omitted>/oauth2/v2.0/authorize
redirect_uri: "https://%REQ(:authority)%/callback"
redirect_path_matcher:
path:
prefix: /callback
pass_through_matcher:
name: authorization
present_match: true
signout_path:
path:
exact: /signout
forward_bearer_token: true
credentials:
client_id: "<omitted>"
token_secret:
name: token
sds_config:
resource_api_version: V3
path_config_source:
path: "/etc/envoy/token-secret.yaml"
hmac_secret:
name: hmac
sds_config:
resource_api_version: V3
path_config_source:
path: "/etc/envoy/hmac-secret.yaml"
auth_scopes:
- openid
- <any scope for a Microsoft application>
Logs:
The 302 redirect loop will eventually end with:
[2023-06-08 13:09:06.628][51][debug][oauth2] [source/extensions/filters/http/oauth2/oauth_client.cc:88] Oauth response body: {"error":"invalid_grant","error_description":"AADSTS54005: OAuth2 Authorization code was already redeemed, please retry with a new valid code or use an existing refresh token.\r\nTrace ID: <omitted>r\nCorrelation ID: <omitted>\r\nTimestamp: 2023-06-08 13:09:06Z","error_codes":[54005],"timestamp":"2023-06-08 13:09:06Z","trace_id":"<omitted>","correlation_id":"<omitted>"}
Activity
ravenblackx commentedon Jun 8, 2023
cc @derekargueta
github-actions commentedon Jul 8, 2023
This issue has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in the next 7 days unless it is tagged "help wanted" or "no stalebot" or other activity occurs. Thank you for your contributions.
github-actions commentedon Jul 15, 2023
This issue has been automatically closed because it has not had activity in the last 37 days. If this issue is still valid, please ping a maintainer and ask them to label it as "help wanted" or "no stalebot". Thank you for your contributions.
kanurag94 commentedon Aug 3, 2023
@phlax, @mattklein123, I wish to work on this, may you please help reopen the issue?
derekargueta commentedon Aug 22, 2023
#28728 seems somewhat related in that the fix for that issue will result in a shorter token which may resolve this issue as well
11 remaining items
shashankram commentedon Jan 19, 2026
@kanurag94 are you still working on this? Please see #27875 (comment)
shashankram commentedon Jan 23, 2026
I opened a PR to enable chunking for large token cookies #43135
kanurag94 commentedon Jan 23, 2026
@shashankram I was of the opinion with the new knobs being added that the community might want to handle this case differently. Will check the PR. Thanks!
oauth2: chunk large token cookies
oauth2: chunk large token cookies
oauth2: chunk large token cookies
oauth2: chunk large token cookies
github-actions commentedon Feb 22, 2026
This issue has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in the next 7 days unless it is tagged "help wanted" or "no stalebot" or other activity occurs. Thank you for your contributions.
oauth2: add token_cookie_chunking to split large token cookies (#48086)