Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

quiche: handle multiple cookies and multiple set-cookie headers #14969

Merged
merged 11 commits into from
Mar 2, 2021

Conversation

danzh2010
Copy link
Contributor

@danzh2010 danzh2010 commented Feb 6, 2021

Signed-off-by: Dan Zhang [email protected]

Commit Message: fix some issues around duplicated http headers:
Quiche doesn't coalesce duplicated headers, so we need to coalesce them in Envoy. Cookie headers after coalescing are semi-colon separated, while Set-Cookie headers shouldn't be coalesced.

Risk Level: low
Testing: added unit tests and integration tests.

Part of #2557

Signed-off-by: Dan Zhang <[email protected]>
@danzh2010
Copy link
Contributor Author

/retest

@repokitteh-read-only
Copy link

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #14969 (comment) was created by @danzh2010.

see: more, trace.

@danzh2010
Copy link
Contributor Author

/assign @alyssawilk

Copy link
Contributor

@antoniovicente antoniovicente 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 continued effort to add QUIC support to Envoy.

include/envoy/http/header_map.h Outdated Show resolved Hide resolved
source/common/http/header_map_impl.cc Outdated Show resolved Hide resolved
Copy link
Contributor

@alyssawilk alyssawilk 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 catching this one - cookie headers are easy to screw up!

include/envoy/http/header_map.h Outdated Show resolved Hide resolved
source/common/http/header_map_impl.cc Outdated Show resolved Hide resolved
@alyssawilk
Copy link
Contributor

alyssawilk commented Feb 9, 2021 via email

@danzh2010
Copy link
Contributor Author

I think adding multiple entries is a fine behavior for the cookie header. Is there a reason you want to inline?

Multiple cookie headers are allowed according to the RFC, but H2 codec seems reconstitute them into a single header with semi-colon separated values. QUICHE is a bit different here. It splits all the cookie headers even if the client sends them in a single header. I want to coalesce them just because H2 does that.

@alyssawilk
Copy link
Contributor

I don't mind us coalescing HTTP/3 if that keeps HTTP/2 and HTTP/3 closer, but my concern is I believe you're also changing HTTP/1, with no runtime guards or recourse which I don't think is a viable change (unless I'm wrong and something in http parser also coalesces cookie headers - you're welcome to test my assumptions here!)

Signed-off-by: Dan Zhang <[email protected]>
Signed-off-by: Dan Zhang <[email protected]>
@danzh2010
Copy link
Contributor Author

I don't mind us coalescing HTTP/3 if that keeps HTTP/2 and HTTP/3 closer, but my concern is I believe you're also changing HTTP/1, with no runtime guards or recourse which I don't think is a viable change (unless I'm wrong and something in http parser also coalesces cookie headers - you're welcome to test my assumptions here!)

I added runtime guard to change in HeaderMapImpl. And also moved the change from insertByKey() to appendCopy(). PTAL!

Copy link
Contributor

@alyssawilk alyssawilk left a comment

Choose a reason for hiding this comment

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

This looks much safer, thanks for the iteration!
It looks like the other 2 call sites for appendToHeader only apply to inline headers but I wouldn't mind a double check from @snowp
I also wonder if it's worth just making that argument non-optional and from those 2 call sites calling it for kDelimiterForInlineHeaders with a comment on definition that all inline headers use comma delimiter. Possibly overkill so I'll say that's 100% optional :-P

@@ -89,6 +89,7 @@ constexpr const char* runtime_features[] = {
"envoy.reloadable_features.unify_grpc_handling",
"envoy.reloadable_features.upstream_http2_flood_checks",
"envoy.restart_features.use_apple_api_for_dns_lookups",
"envoy.reloadable_features.header_map_coalesce_cookie_headers",
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this will result in cookies coalescing, but in correctly coalescing cookies. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

renamed it!

// TODO(danzh): Avoid copy by referencing entry as header_list is already validated by QUIC.
headers->addCopy(Http::LowerCaseString(entry.first), entry.second);
auto key = Http::LowerCaseString(entry.first);
if (!Runtime::runtimeFeatureEnabled(
Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW I don't think you need to runtime guard QUIC code if youdon't want to as it's still alpha

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point! Removed the runtime guard here but still checks it in tests.

@danzh2010
Copy link
Contributor Author

/retest

@repokitteh-read-only
Copy link

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #14969 (comment) was created by @danzh2010.

see: more, trace.

@danzh2010
Copy link
Contributor Author

This looks much safer, thanks for the iteration!
It looks like the other 2 call sites for appendToHeader only apply to inline headers but I wouldn't mind a double check from @snowp
I also wonder if it's worth just making that argument non-optional and from those 2 call sites calling it for kDelimiterForInlineHeaders with a comment on definition that all inline headers use comma delimiter. Possibly overkill so I'll say that's 100% optional :-P

It's hard to tell if the following interface are used anywhere with a delimiter different from comma:

#define DEFINE_INLINE_HEADER_STRING_FUNCS(name)      
  ...
  void append##name(absl::string_view data, absl::string_view delimiter) 

Signed-off-by: Dan Zhang <[email protected]>
@danzh2010
Copy link
Contributor Author

/retest

@repokitteh-read-only
Copy link

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #14969 (comment) was created by @danzh2010.

see: more, trace.

@danzh2010
Copy link
Contributor Author

Ping?

Copy link
Contributor

@alyssawilk alyssawilk left a comment

Choose a reason for hiding this comment

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

code LGTM.

Let's add release notes in docs/root/version_history/current.rst
(bug fix, include the runtime guard)

and a header map impl test, and I think you're good to go.

Copy link
Contributor

@snowp snowp left a comment

Choose a reason for hiding this comment

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

It looks like the other 2 call sites for appendToHeader only apply to inline headers but I wouldn't mind a double check from @snowp

This seems right to me, can't find any use cases besides the ones applying to inlined headers.

test/common/http/header_map_impl_test.cc Show resolved Hide resolved
Signed-off-by: Dan Zhang <[email protected]>
@danzh2010
Copy link
Contributor Author

code LGTM.

Let's add release notes in docs/root/version_history/current.rst
(bug fix, include the runtime guard)

and a header map impl test, and I think you're good to go.

Updated current.rst. There is a new header map unit test for the new feature. What else need to be tested?

Signed-off-by: Dan Zhang <[email protected]>
@danzh2010
Copy link
Contributor Author

/retest

@repokitteh-read-only
Copy link

Retrying Azure Pipelines:
Check envoy-presubmit isn't fully completed, but will still attempt retrying.
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #14969 (comment) was created by @danzh2010.

see: more, trace.

alyssawilk
alyssawilk previously approved these changes Feb 22, 2021
@danzh2010
Copy link
Contributor Author

/retest

@repokitteh-read-only
Copy link

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #14969 (comment) was created by @danzh2010.

see: more, trace.

@danzh2010
Copy link
Contributor Author

/retest

@repokitteh-read-only
Copy link

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #14969 (comment) was created by @danzh2010.

see: more, trace.

@alyssawilk
Copy link
Contributor

Argh - CI passed but there's conflicts. Needs a main merge :-/

Signed-off-by: Dan Zhang <[email protected]>
Signed-off-by: Dan Zhang <[email protected]>
@danzh2010
Copy link
Contributor Author

Argh - CI passed but there's conflicts. Needs a main merge :-/

Done with main merge. PTAL

@danzh2010
Copy link
Contributor Author

/retest

@repokitteh-read-only
Copy link

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #14969 (comment) was created by @danzh2010.

see: more, trace.

@danzh2010
Copy link
Contributor Author

sync'ed with upstream. PTAL!

Copy link
Contributor

@snowp snowp left a comment

Choose a reason for hiding this comment

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

Thanks, this LGTM.

Seems like this PR no longer contains any changes to how we handle set-cookie? Do we no longer need to make any changes to properly support that in with QUIC?

@danzh2010
Copy link
Contributor Author

Thanks, this LGTM.

Seems like this PR no longer contains any changes to how we handle set-cookie? Do we no longer need to make any changes to properly support that in with QUIC?

set-cookie was handled correctly before. This change add tests for it.

@danzh2010
Copy link
Contributor Author

Any other thoughts on this change? @alyssawilk

@alyssawilk alyssawilk merged commit 3cc0ca0 into envoyproxy:main Mar 2, 2021
alyssawilk pushed a commit that referenced this pull request Aug 10, 2021
Commit Message: ensure that the inline cookie header will be folded correctly
Additional Description:

This PR is a supplement to #17330 and #14969 and will finally close #17234. This PR mainly did following works:

update insertByKey to choose suitable delimiter for inline header.
update parseCookie to avoid unnecessary iteration for parsing cookie value.
Risk Level: Low.
Testing: Add.
Docs Changes: N/A.
Release Notes: N/A.
Signed-off-by: wbpcode <[email protected]>
leyao-daily pushed a commit to leyao-daily/envoy that referenced this pull request Sep 30, 2021
…roxy#17560)

Commit Message: ensure that the inline cookie header will be folded correctly
Additional Description:

This PR is a supplement to envoyproxy#17330 and envoyproxy#14969 and will finally close envoyproxy#17234. This PR mainly did following works:

update insertByKey to choose suitable delimiter for inline header.
update parseCookie to avoid unnecessary iteration for parsing cookie value.
Risk Level: Low.
Testing: Add.
Docs Changes: N/A.
Release Notes: N/A.
Signed-off-by: wbpcode <[email protected]>
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