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

Trimming whitespace in XFF for IP whitelisting #3971

Merged
merged 1 commit into from
Oct 3, 2018

Conversation

olmoser
Copy link
Contributor

@olmoser olmoser commented Oct 2, 2018

What does this PR do?

Trims whitespace from X-Forwarded-For header values.

Motivation

In case there are multiple comma-separated values for the XFF header, there might be trailing whitespace after the comma e.g.

X-Forwarded-For: 1.2.3.4, 1.1.1.1, 8.8.8.8

If that's the case, then net.parseIP will return nil and the whitelist check will fail.

This situation was not caught by the test since the fixture:

{
	desc:                "allow UseXForwardedFor, remoteAddr not in range, UseXForwardedFor in range (compact XFF)",
	whiteList:           []string{"1.2.3.4/24"},
	allowXForwardedFor:  true,
	remoteAddr:          "10.2.3.1:123",
	xForwardedForValues: []string{"1.2.3.1, 10.2.3.1"},
	authorized:          true,
},

listed the matching IP as the first value in the comma separated value, hence not testing the second value (10.2.3.1) which contains the whitespace.

More

  • Added/updated tests
  • Added/updated documentation

Additional Notes

Copy link
Member

@juliens juliens left a comment

Choose a reason for hiding this comment

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

Good catch 👏

whitelist/ip.go Outdated Show resolved Hide resolved
Copy link
Member

@juliens juliens left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@jbdoumenjou jbdoumenjou left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@ldez ldez left a comment

Choose a reason for hiding this comment

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

LGTM

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

Successfully merging this pull request may close these issues.

6 participants