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

[bug] ProxyHeaders XFF parsing handles whitespace incorrectly #227

Open
adam-p opened this issue Mar 27, 2022 · 0 comments · May be fixed by #228
Open

[bug] ProxyHeaders XFF parsing handles whitespace incorrectly #227

adam-p opened this issue Mar 27, 2022 · 0 comments · May be fixed by #228
Labels

Comments

@adam-p
Copy link

adam-p commented Mar 27, 2022

Describe the bug

The current code looks like this:

		s := strings.Index(fwd, ", ")
		if s == -1 {
			s = len(fwd)
		}
		addr = fwd[:s]

As can be seen in this playground, it doesn't handle whitespace around the comma properly. (The playground isn't working consistently, I think because of back-end weirdness. But the code works.)

If the header is like 1.1.1.1,2.2.2.2, 3.3.3.3, the resulting addr will be 1.1.1.1,2.2.2.2. If the header is like 1.1.1.1 , 2.2.2.2, the resulting addr will be 1.1.1.1<space>.

RFC 2616 states that there can be "linear white space" (LWS; space or tab) around the values and commas. For example:

each separated by one or more commas (",") and OPTIONAL linear white space (LWS). This makes the usual form of lists very easy; a rule such as
( *LWS element *( *LWS "," *LWS element ))

And:

Except where noted otherwise, linear white space (LWS) can be included between any two adjacent words (token or quoted-string), and between adjacent words and separators, without changing the interpretation of a field.

I will submit a PR shortly.

Versions
go1.18
master HEAD

Steps to Reproduce

Code here: https://go.dev/play/p/uTO1eaTRsbx

Expected behavior

Proper handling of whitespace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: 🏗 In progress
Development

Successfully merging a pull request may close this issue.

1 participant