Skip to content

http: only accept HTTP client magic at the start of buffer#8232

Merged
zuercher merged 7 commits intoenvoyproxy:masterfrom
zuercher:szuercher_fix_h2_inference
Sep 18, 2019
Merged

http: only accept HTTP client magic at the start of buffer#8232
zuercher merged 7 commits intoenvoyproxy:masterfrom
zuercher:szuercher_fix_h2_inference

Conversation

@zuercher
Copy link
Copy Markdown
Member

@zuercher zuercher commented Sep 13, 2019

Risk Level: low
Testing: added test case
Docs Changes: n/a
Release Notes: updated
Fixes: #8229

Signed-off-by: Stephan Zuercher zuercher@gmail.com

Risk Level: low
Testing: added test case
Docs Changes: n/a
Release Notes: n/a
Fixes: envoyproxy#8229

Signed-off-by: Stephan Zuercher <zuercher@gmail.com>
// us the first few bytes of the HTTP/2 prefix since in all public cases we use SSL/ALPN. For
// internal cases this should practically never happen.
if (-1 != data.search(Http2::CLIENT_MAGIC_PREFIX.c_str(), Http2::CLIENT_MAGIC_PREFIX.size(), 0)) {
if (0 == data.search(Http2::CLIENT_MAGIC_PREFIX.c_str(), Http2::CLIENT_MAGIC_PREFIX.size(), 0)) {
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.

This is no less performant than the previous, but we could avoid a lot of comparisons if we added a method to Buffer that implemented comparison at an exact spot, something like:

if (data.rangeEquals(0, Http2::Client_MAGIC_PERFIX.size(), Http2::CLIENT_MAGIC_PREFIX.c_str()) {
  return Http2::ALPN_STRING;
}

(I could also use linearize and memcmp, but would have to modify several callsites to pass a non-const Buffer reference to allow linearize to be called here).

What do folks think?

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.

How about using copyOut to a stack allocated char[] and compare with CLIENT_MAGIC_PREFIX? CLIENT_MAGIC_PREFIX is short so that shouldn't cost much.

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.

I wonder if we even need to handle arbitrary points, and can just have something like a prefix check. I suspect that's what we want most of the time.

Either way I'm happy with this change as an incremental improvement. My one request would be a release note (version history note, whaever) just because it fixes a bug on the data plane, and no one knows if someone is depending on this particular bug in production.

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.

Added Buffer::startsWith and switch to using that.

@junr03
Copy link
Copy Markdown
Member

junr03 commented Sep 13, 2019

@alyssawilk do you mind taking a look at this?

Signed-off-by: Stephan Zuercher <zuercher@gmail.com>
Signed-off-by: Stephan Zuercher <zuercher@gmail.com>
Signed-off-by: Stephan Zuercher <zuercher@gmail.com>
Signed-off-by: Stephan Zuercher <zuercher@gmail.com>
Copy link
Copy Markdown
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.

+1 to stringview, and one other nit but otherwise looks good!

Signed-off-by: Stephan Zuercher <zuercher@gmail.com>
Signed-off-by: Stephan Zuercher <zuercher@gmail.com>
@zuercher zuercher merged commit 166b0fa into envoyproxy:master Sep 18, 2019
@zuercher zuercher deleted the szuercher_fix_h2_inference branch September 18, 2019 17:04
danzh2010 pushed a commit to danzh2010/envoy that referenced this pull request Sep 24, 2019
…y#8232)

http: only accept HTTP client magic at the start of buffer

Risk Level: low
Testing: added test case
Docs Changes: n/a
Release Notes: updated
Fixes: envoyproxy#8229

Signed-off-by: Stephan Zuercher <zuercher@gmail.com>
danzh2010 pushed a commit to danzh2010/envoy that referenced this pull request Oct 4, 2019
…y#8232)

http: only accept HTTP client magic at the start of buffer

Risk Level: low
Testing: added test case
Docs Changes: n/a
Release Notes: updated
Fixes: envoyproxy#8229

Signed-off-by: Stephan Zuercher <zuercher@gmail.com>
danzh2010 pushed a commit to danzh2010/envoy that referenced this pull request Oct 4, 2019
…y#8232)

http: only accept HTTP client magic at the start of buffer

Risk Level: low
Testing: added test case
Docs Changes: n/a
Release Notes: updated
Fixes: envoyproxy#8229

Signed-off-by: Stephan Zuercher <zuercher@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.

HTTP codec auto may incorrectly select http/2

4 participants