Skip to content

Handle lists with and without spaces in XFF#3610

Merged
mattklein123 merged 5 commits into
envoyproxy:masterfrom
rgs1:fix-handling-of-http-lists
Jun 13, 2018
Merged

Handle lists with and without spaces in XFF#3610
mattklein123 merged 5 commits into
envoyproxy:masterfrom
rgs1:fix-handling-of-http-lists

Conversation

@rgs1
Copy link
Copy Markdown
Member

@rgs1 rgs1 commented Jun 12, 2018

Currently, Utility::getLastAddressFromXFF() only handles lists that
use a comma plus a space as the separator.

Per https://tools.ietf.org/html/rfc7239#section-7.1, spaces are allowed
around commas — so we should handle that too.

This fixes #3607.

Signed-off-by: Raul Gutierrez Segales rgs@pinterest.com

Currently, `Utility::getLastAddressFromXFF()` only handles lists that
use a comma plus a space as the separator.

Per https://tools.ietf.org/html/rfc7239#section-7.1, spaces are allowed
around commas — so we should handle that too.

This fixes envoyproxy#3607.

Signed-off-by: Raul Gutierrez Segales <rgs@pinterest.com>
@mattklein123
Copy link
Copy Markdown
Member

@rgs1 we are going to merge the revert to try to get master into a good state after some issues. Can you potentially re-apply #3609 in this PR and then @alyssawilk can help review?

@rgs1
Copy link
Copy Markdown
Member Author

rgs1 commented Jun 12, 2018

@mattklein123 sure, but do we really need to revert #3609? it's generating valid XFF headers...

@mattklein123
Copy link
Copy Markdown
Member

It is, but when Envoys are paired together, it will no longer work correctly, and I'm sure this will break people in a mesh configuration (including Lyft). I think it's better to revert and reapply as a set.

@rgs1
Copy link
Copy Markdown
Member Author

rgs1 commented Jun 12, 2018

@mattklein123 ah true

@rgs1
Copy link
Copy Markdown
Member Author

rgs1 commented Jun 12, 2018

i'll add #3609 in a follow-up commit

@alyssawilk
Copy link
Copy Markdown
Contributor

Having the utility fix in the same PR as the change to headers doesn't actually help if you don't roll everything out at once.

I'd honestly be inclined to roll back #3609, check this in, and wait [a month | a full release] before reapplying given there's 0 urgency on removing the whitespace. Alternately we could call it out much more clearly in the release notes that you must replace your upstream Envoys (which allow whitespace and no-whitespace) before replacing downstream Envoys (which change how the header looks) but that seems more dicey.

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.

Either way this LGTM (modulo nit) - thanks for both debugging and sorting out a fix so quickly!

Comment thread source/common/http/utility.cc Outdated
xff_string = xff_string.substr(last_comma + seperator.size());
}

// ignore the whitespace, since they are allowed in HTTP lists (see rfc7239)
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.

nit: ignore -> Ignore

Signed-off-by: Raul Gutierrez Segales <rgs@pinterest.com>
@mattklein123
Copy link
Copy Markdown
Member

I'd honestly be inclined to roll back #3609, check this in, and wait [a month | a full release] before reapplying given there's 0 urgency on removing the whitespace. Alternately we could call it out much more clearly in the release notes that you must replace your upstream Envoys (which allow whitespace and no-whitespace) before replacing downstream Envoys (which change how the header looks) but that seems more dicey.

This is a good point. Sorry, didn't think about this very much when I mentioned to roll it together. Agre let's apply this first then wait a month or so for the other one. Can we open a tracking issue for that?

mattklein123
mattklein123 previously approved these changes Jun 12, 2018
Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Nice, thank you!


// Ignore the whitespace, since they are allowed in HTTP lists (see RFC7239#section-7.1).
xff_string = StringUtil::ltrim(xff_string);
xff_string = StringUtil::rtrim(xff_string);
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.

Sorry, just noticed. Do we have a test that covers the need for rtrim?

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.

@mattklein123 no... only ltrim(). Lemme modify the case I added so that it has space at both sides...

Copy link
Copy Markdown
Member Author

@rgs1 rgs1 Jun 12, 2018

Choose a reason for hiding this comment

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

@mattklein123 is it fine if I use this test string which should exercise ltrim(), rtrim() and no trim():

"192.0.2.10, 192.0.2.1 ,10.0.0.1"

Or you rather have it broken up in subtests, and be explicit about what path i am exercising?

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.

i guess the above string with comments near each EXPECT call should be clear enough... Let me push what I have and lmk what you think.

Copy link
Copy Markdown
Member Author

@rgs1 rgs1 Jun 12, 2018

Choose a reason for hiding this comment

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

@mattklein123 hold it, my comments are in the wrong place, fixing...

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.

@mattklein123 should be good now, sorry about that!

@mattklein123 mattklein123 dismissed their stale review June 12, 2018 22:50

another question

Also, comment about which space trimming case is being tested.

Signed-off-by: Raul Gutierrez Segales <rgs@pinterest.com>
mattklein123
mattklein123 previously approved these changes Jun 12, 2018
Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

great, thanks!

@mattklein123 mattklein123 self-assigned this Jun 12, 2018
Comments were referring to the wrong test case.

Signed-off-by: Raul Gutierrez Segales <rgs@pinterest.com>
mattklein123
mattklein123 previously approved these changes Jun 12, 2018

// No space trimming.
ret = Utility::getLastAddressFromXFF(request_headers, 2);
EXPECT_EQ(first_address, ret.address_->ip()->addressAsString());
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 think this test would have passed with the previous PR, because we assumed "X, Y" The problem is X,Y with no whitespace on either side.

Can we add one more address in this test with no whitespace before the comma on either side?

Signed-off-by: Raul Gutierrez Segales <rgs@pinterest.com>
@rgs1
Copy link
Copy Markdown
Member Author

rgs1 commented Jun 13, 2018

@alyssawilk added — thanks!

@rgs1
Copy link
Copy Markdown
Member Author

rgs1 commented Jun 13, 2018

@alyssawilk hmm, do we also need an integration test to check that xff is handled correctly from envoy to envoy (e.g.: something that would have caught the problem with 035a816)?

@alyssawilk
Copy link
Copy Markdown
Contributor

I'd love that, but I don't think we have the ability to set up multi-Envoy integration tests. It's definitely on my list though! I think the best we can do today is an integration test for A,B,C (no whitespace) if you're up for it.

@mattklein123
Copy link
Copy Markdown
Member

Ah thanks @alyssawilk nice catch on the test.

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.

Should getLastAddressFromXFF() handle comma-separated lists without spaces too?

3 participants