-
Notifications
You must be signed in to change notification settings - Fork 617
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
handle indeterminate length proxy chains - fixes #449 #453
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -165,11 +165,11 @@ func TestAccessRules_AccessDeniedHTTP(t *testing.T) { | |
denied bool | ||
}{ | ||
{ | ||
desc: "denied xff and allowed remote addr", | ||
desc: "single denied xff and allowed remote addr", | ||
target: &Target{ | ||
Opts: map[string]string{"allow": "ip:10.0.0.0/8,ip:192.168.0.0/24"}, | ||
}, | ||
xff: "1.1.1.2, 10.11.12.13, 10.11.12.14", | ||
xff: "10.11.12.13, 1.1.1.2, 10.11.12.14", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason the order changed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not particularly, the result is the same regardless of the order. I can’t remember why it was changed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ohh, the old code only checked the first element. I moved it to ensure it was looping over the elements and still denying on a middle element. |
||
remote: "10.11.12.1:65500", | ||
denied: true, | ||
}, | ||
|
@@ -183,13 +183,13 @@ func TestAccessRules_AccessDeniedHTTP(t *testing.T) { | |
denied: true, | ||
}, | ||
{ | ||
desc: "allowed xff and allowed remote addr", | ||
desc: "single allowed xff and allowed remote addr", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment doesn't match the result since the behavior changed. Can you double check? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only a single element of the XFF is allowed. The others are denied. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the old code this was allowed as it only checked the first element. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I thought that because the XFF address and the remote address are allowed the request should be allowed. But 1.2.3.4 isn't whitelisted. This wasn't obvious to me. I'll clean up the comments after the merge. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that was part of the new behavior. If any one of the addresses presented in the XFF fail to match an allow/whitelist rule the request is denied. If any one of the addresses match a deny/blacklist rule the request is denied. |
||
target: &Target{ | ||
Opts: map[string]string{"allow": "ip:10.0.0.0/8,ip:192.168.0.0/24"}, | ||
}, | ||
xff: "10.11.12.13, 1.2.3.4", | ||
remote: "192.168.0.12:65500", | ||
denied: false, | ||
denied: true, | ||
}, | ||
{ | ||
desc: "denied xff and denied remote addr", | ||
|
@@ -200,6 +200,15 @@ func TestAccessRules_AccessDeniedHTTP(t *testing.T) { | |
remote: "200.17.18.20:65500", | ||
denied: true, | ||
}, | ||
{ | ||
desc: "all allowed xff and allowed remote addr", | ||
target: &Target{ | ||
Opts: map[string]string{"allow": "ip:10.0.0.0/8,ip:192.168.0.0/24"}, | ||
}, | ||
xff: "10.11.12.13, 10.110.120.130", | ||
remote: "192.168.0.12:65500", | ||
denied: false, | ||
}, | ||
} | ||
|
||
for i, tt := range tests { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't you need to continue here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The behavior of
denyByIP
is to immediately return false when passed anil
... so it is effectively doing a continue. However, I can see the point that adding a continue would be more explicit and be more future proof should additional code be added between this statement and thedenyByIP
call.