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

Split real_ip_header value when it contains multiple IPs #1241

Merged
merged 1 commit into from
Mar 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ https://github.com/elastic/beats/compare/v1.1.2...master[Check the HEAD diff]
- Allow PF_RING sniffer type to be configured using pf_ring or pfring {pull}671[671]
- Create a proper BPF filter when ICMP is the only enabled protocol {issue}757[757]
- Check column length in pgsql parser. {issue}565{565
- Split real_ip_header value when it contains multiple IPs {pull}1241[1241]

*Topbeat*
- Fix issue with cpu.system_p being greater than 1 on Windows {pull}1128[1128]
Expand Down
4 changes: 3 additions & 1 deletion packetbeat/protos/http/http_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,9 @@ func (parser *parser) parseHeader(m *message, data []byte) (bool, bool, int) {
m.connection = headerVal
}
if len(config.RealIPHeader) > 0 && bytes.Equal(headerName, []byte(config.RealIPHeader)) {
m.RealIP = headerVal
if ips := bytes.SplitN(headerVal, []byte{','}, 2); len(ips) > 0 {
m.RealIP = trim(ips[0])
}
}

if config.SendHeaders {
Expand Down
Binary file not shown.
17 changes: 17 additions & 0 deletions packetbeat/tests/system/test_0008_realip.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,20 @@ def test_x_forward_for(self):

assert o["real_ip"] == "89.247.39.104"
assert o["client_location"] == "52.528503, 13.410904"

def test_x_forwarded_for_multiple_ip(self):
self.render_config_template(
http_ports=[80],
http_real_ip_header="X-Forwarded-For",
http_send_all_headers=True,
geoip_paths=["geoip_city.dat"]
)
self.copy_files(["geoip_city.dat"])
self.run_packetbeat(pcap="http_x_forwarded_for.pcap", debug_selectors=["http"])

objs = self.read_output()
assert len(objs) == 1
o = objs[0]

assert o["real_ip"] == "89.247.39.104"
assert o["client_location"] == "52.528503, 13.410904"