Skip to content

oauth2 filter: handle large size cookies - #28799

Closed
kanurag94 wants to merge 11 commits into
envoyproxy:mainfrom
kanurag94:oauth2-cookie-size
Closed

kanurag94 wants to merge 11 commits into
envoyproxy:mainfrom
kanurag94:oauth2-cookie-size

Conversation

@kanurag94

@kanurag94 kanurag94 commented Aug 3, 2023 •

Copy link
Copy Markdown
Member

Commit Message: oauth2 filter: handle setting large sized cookies for response tokens
Additional Description: if forward_bearer_token is set to true, the user expects to use the token in further flows. If cookie size is greater than 4096, most modern browsers will reject it. Thus in this PR, we split the cookie in chunks of size 4000, and later recombine them during read
Risk Level: Low
Testing:
Docs Changes:
Release Notes:
Platform Specific Features:
[Optional Runtime guard:]
Fixes #27875
[Optional Fixes commit #PR or SHA]
[Optional Deprecated:]
[Optional API Considerations:]

This commit aims to handle
1. Logging for large size cookies
2. Split large cookies in multiple smaller parts

Signed-off-by: Anurag Aggarwal <[email protected]>
@repokitteh-read-only

Copy link
Copy Markdown

As a reminder, PRs marked as draft will not be automatically assigned reviewers,
or be handled by maintainer-oncall triage.

Please mark your PR as ready when you want it to be reviewed!

🐱

Caused by: #28799 was opened by kanurag94.

see: more, trace.

Signed-off-by: Anurag Aggarwal <[email protected]>
@kanurag94
kanurag94 force-pushed the oauth2-cookie-size branch from ee9ab6c to cae23c4 Compare August 4, 2023 10:56
Signed-off-by: Anurag Aggarwal <[email protected]>
@kanurag94
kanurag94 force-pushed the oauth2-cookie-size branch from cae23c4 to f9c1225 Compare August 4, 2023 11:05
Signed-off-by: Anurag Aggarwal <[email protected]>
}

void OAuth2Filter::setSplitCookie(Http::ResponseHeaderMap& headers, const std::string& key,
const std::string& data, size_t maxChunkSize = 4000) const {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

setting default to 4000 should be in the function declaration I think. Rather, should we make it configuration option?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Most modern browsers have 4096 as the limit, 4000 should suffice all cases. If we choose to take this utility function out to Http::Utility then probably we should have the configuration option, wdyt?

Signed-off-by: Anurag Aggarwal <[email protected]>
Signed-off-by: Anurag Aggarwal <[email protected]>
Signed-off-by: Anurag Aggarwal <[email protected]>
Signed-off-by: Anurag Aggarwal <[email protected]>
@kanurag94
kanurag94 marked this pull request as ready for review August 21, 2023 17:21
Signed-off-by: Anurag Aggarwal <[email protected]>
Signed-off-by: Anurag Aggarwal <[email protected]>
Signed-off-by: Anurag Aggarwal <[email protected]>
@kanurag94

Copy link
Copy Markdown
Member Author

gentle ping @derekargueta @mattklein123 (maintainers) for review

@RyanTheOptimist

Copy link
Copy Markdown
Contributor

/assign @mattklein123

@derekargueta

Copy link
Copy Markdown
Member

#28867 might inadvertently address this problem as well by producing shorter bearer tokens, so I'm thinking we try to get that merged in first and see if this additional complexity is even needed.

@kanurag94

Copy link
Copy Markdown
Member Author

thanks @derekargueta for mentioning the issue.

IIUC from the PR, I think this may still be an issue with forward_bearer_token where we wish to set the token as a part of cookie to be used by the end application. Also, we are using SHA256 so its not reversible to get the token back and set it in a header for upstream. Most of the encoding algorithms will not produce much smaller strings.

@mattklein123

Copy link
Copy Markdown
Member

Will wait to hear from @derekargueta to see if we should move forward with this PR or not.

/wait-any

@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in 7 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@github-actions github-actions Bot added the stale stalebot believes this issue/PR has not been touched recently label Sep 22, 2023
@github-actions

Copy link
Copy Markdown

This pull request has been automatically closed because it has not had activity in the last 37 days. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@spodobetsd

Copy link
Copy Markdown

The problem is still relevant. Our token contain a lot of groups. I tried to use latest envoy image (dev) with options

disable_id_token_set_cookie: true
disable_access_token_set_cookie: true
disable_refresh_token_set_cookie: true

but it didn't help me.
@derekargueta @mattklein123 could you please get back this PR to review?

@shashankram

Copy link
Copy Markdown

The problem is still relevant. Our token contain a lot of groups. I tried to use latest envoy image (dev) with options

disable_id_token_set_cookie: true
disable_access_token_set_cookie: true
disable_refresh_token_set_cookie: true

but it didn't help me. @derekargueta @mattklein123 could you please get back this PR to review?

@spodobetsd revived cookie chunking in #43135

@kanurag94

Copy link
Copy Markdown
Member Author

/reopen
/not-stale

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale stalebot believes this issue/PR has not been touched recently

Projects

None yet

Development

Successfully merging this pull request may close these issues.

oauth2 filter: browser blocks BearerToken cookie because its size too large

7 participants