Skip to content

http: tighten handling of non-{100,101} 1xx and multiple 100 headers. - #12037

Merged
htuch merged 6 commits into
envoyproxy:masterfrom
htuch:multi-100-contiune-3
Jul 23, 2020
Merged

htuch merged 6 commits into
envoyproxy:masterfrom
htuch:multi-100-contiune-3

Conversation

@htuch

@htuch htuch commented Jul 10, 2020 •

Copy link
Copy Markdown
Member

This PR provides intentional semantics for:

  • Multiple-100 headers; these are always coalesced to a single 100 header when proxying.
  • 101 headers: these are always passed to decodeHeaders().
  • Non-{100,101} 1xx headers, e.g. 102/103, are always ignored by Envoy.

UpstreamRequest is responsible for guaranteeing that HCM observes the above properties. Codecs should pass 100 headers to decode100ContinueHeaders and all other 1xx to decodeHeaders.

This PR follows the discussion in #11433 (comment).

Risk level: Medium
Testing: Unit tests for codecs and UpstreamRequest added. Integration tests for non-101 and multiple 101 headers added.

Fixes OSS-fuzz issue https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=21628.
Fixes #11433

Signed-off-by: Harvey Tuch [email protected]

This revisits envoyproxy#11448
in light of
envoyproxy#11433 (comment).

There's still some outstanding questions in envoyproxy#11433 to resolve.

Risk level: Medium
Testing: Will write more unit/integration tests once we the approach is
  settled.

Signed-off-by: Harvey Tuch <[email protected]>
@htuch
htuch force-pushed the multi-100-contiune-3 branch from 838157a to a25d927 Compare July 17, 2020 11:44
@htuch htuch changed the title [WiP] http: fix handling of multiple 100-continue headers. http: tighten handling of multiple 1xx headers. Jul 17, 2020
@htuch htuch changed the title http: tighten handling of multiple 1xx headers. http: tighten handling of non-101 and multiple 1xx headers. Jul 17, 2020
@htuch htuch changed the title http: tighten handling of non-101 and multiple 1xx headers. http: tighten handling of non-{100,101} and multiple 1xx headers. Jul 17, 2020
@htuch htuch changed the title http: tighten handling of non-{100,101} and multiple 1xx headers. http: tighten handling of non-{100,101} and multiple 100 headers. Jul 17, 2020
@htuch htuch changed the title http: tighten handling of non-{100,101} and multiple 100 headers. http: tighten handling of non-{100,101} 1xx and multiple 100 headers. Jul 17, 2020
@htuch
htuch requested a review from mattklein123 July 17, 2020 11:54
@htuch

htuch commented Jul 17, 2020

Copy link
Copy Markdown
Member Author

@alyssawilk @mattklein123 this is now ready for review. Do you think we should runtime guard?

enum class StreamState { PendingHeaders, PendingDataOrTrailers, Closed };
enum class StreamState {
PendingHeaders,
PendingNonInformationalHeaders,

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.

@asraa FYI for fuzzing.

Signed-off-by: Harvey Tuch <[email protected]>
@mattklein123 mattklein123 self-assigned this Jul 17, 2020

@mattklein123 mattklein123 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

At a high level this LGTM but I would prefer that @alyssawilk reviews on Monday. Also needs a master merge.

/wait

@alyssawilk alyssawilk left a comment

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.

Thanks again for tackling this! Some thoughts below.

Comment thread docs/root/version_history/current.rst Resolved
Comment thread source/common/http/conn_manager_impl.cc Resolved
Comment thread source/common/http/conn_manager_impl.h Resolved
Comment thread source/common/http/http1/codec_impl.cc Resolved
Comment thread source/common/http/http2/codec_impl.cc Resolved
Comment thread source/common/http/http2/codec_impl.cc Resolved
// We can continue to receive 1xx, we forward to HCM and allow it to coalesce.
stream->decodeHeaders(true);
} else {
ASSERT(stream->remote_end_stream_);

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.

So if a non-nghttp2 codec sends
100
200 (with body)
100

will nghttp2 force end stream or will this assert fail? Unit test maybe?

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.

Looking at nghttp2 source code, it appears that nghttp2 rejects pseudo-headers including :status in trailers, see https://github.com/nghttp2/nghttp2/blob/bb519154fe62f7ff7e5eb7269e05043dec6d3682/lib/nghttp2_http.c#L117.

Looks like we can do an encode sequence like this, so I can add a simple unit test to show.

@htuch

htuch commented Jul 22, 2020

Copy link
Copy Markdown
Member Author

@alyssawilk updated, PTAL.

@alyssawilk alyssawilk left a comment

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.

Looking better and better!

Comment thread source/common/http/http1/codec_impl.cc Resolved
Comment thread source/common/router/router.cc Resolved

@alyssawilk alyssawilk left a comment

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.

Thanks for all the iterations - I think the last change especially made this much easier to read!

@htuch

htuch commented Jul 23, 2020

Copy link
Copy Markdown
Member Author

TSAN failure is xds_fuzz_test; @samflattery FYI. Will merge.

@htuch
htuch merged commit 8d4e705 into envoyproxy:master Jul 23, 2020
KBaichoo pushed a commit to KBaichoo/envoy that referenced this pull request Jul 30, 2020
envoyproxy#12037)

This PR provides intentional semantics for:

Multiple-100 headers; these are always coalesced to a single 100 header when proxying.
101 headers: these are always passed to decodeHeaders().
Non-{100,101} 1xx headers, e.g. 102/103, are always ignored by Envoy.
UpstreamRequest is responsible for guaranteeing that HCM observes the above properties. Codecs should pass 100 headers to decode100ContinueHeaders and all other 1xx to decodeHeaders.

This PR follows the discussion in envoyproxy#11433 (comment).

Risk level: Medium
Testing: Unit tests for codecs and UpstreamRequest added. Integration tests for non-101 and multiple 101 headers added.

Fixes OSS-fuzz issue https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=21628.
Fixes envoyproxy#11433

Signed-off-by: Harvey Tuch <[email protected]>
Signed-off-by: Kevin Baichoo <[email protected]>
chaoqin-li1123 pushed a commit to chaoqin-li1123/envoy that referenced this pull request Aug 7, 2020
envoyproxy#12037)

This PR provides intentional semantics for:

Multiple-100 headers; these are always coalesced to a single 100 header when proxying.
101 headers: these are always passed to decodeHeaders().
Non-{100,101} 1xx headers, e.g. 102/103, are always ignored by Envoy.
UpstreamRequest is responsible for guaranteeing that HCM observes the above properties. Codecs should pass 100 headers to decode100ContinueHeaders and all other 1xx to decodeHeaders.

This PR follows the discussion in envoyproxy#11433 (comment).

Risk level: Medium
Testing: Unit tests for codecs and UpstreamRequest added. Integration tests for non-101 and multiple 101 headers added.

Fixes OSS-fuzz issue https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=21628.
Fixes envoyproxy#11433

Signed-off-by: Harvey Tuch <[email protected]>
Signed-off-by: chaoqinli <[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.

Proxying multiple 100-continue headers

3 participants