Skip to content
This repository has been archived by the owner on Apr 11, 2021. It is now read-only.

Include remote address in request header #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

TheHackerDev
Copy link
Contributor

@TheHackerDev TheHackerDev commented May 23, 2017

Includes the remote address in the request, following RFC 7239, section 4.

This is not going to be exact for every case, because http.Request.RemoteAddr has no defined format (see https://golang.org/src/net/http/request.go#L260). However, http.Server sets the address to IP:port, so it is safe to go with that.

NOTE: I was unable to check this with an IPv6 source address. Please do so before merging, to confirm that IPv6 source addresses get transformed to look like the following header:

Forwarded: For="[2001:db8:cafe::17]"

I was mostly unsure as to whether the http.Server set the remoteAddr value for IPv6 addresses with square brackets or not. The assumption in the code's logic right now is that it does not.

Cheers,
Aaron (insp3ctre)

@TheHackerDev TheHackerDev changed the title Fixes #18 Include remote address in request header May 23, 2017
@yanc0 yanc0 self-requested a review May 24, 2017 05:55
@yanc0
Copy link
Owner

yanc0 commented May 24, 2017

Thanks Aaron !

@TheHackerDev
Copy link
Contributor Author

No problem, Yann!

Cheers,
Aaron (insp3ctre)

@yanc0
Copy link
Owner

yanc0 commented Jul 6, 2017

Hi Aaron,

I've just fetch your PR locally and bound Beeping on an IPv6 address. It almost works, I get the header but with too much surround brackets:

Forwarded: for="[[2002:c000:203::1]]"

There is no need to add brackets when you split IP:PORT, they are apparently already there in the request.RemoteAddr

The fix could be:

-               srcIP := "["
+               var srcIP string
                for index := 0; index < len(srcSlice)-2; index++ {
                        srcIP += fmt.Sprintf("%s:", srcSlice[index])
                }
-               srcIP += fmt.Sprintf("%s]", srcSlice[len(srcSlice)-2])
+               srcIP += fmt.Sprintf("%s", srcSlice[len(srcSlice)-2])
                req.Header.Set("Forwarded", fmt.Sprintf("for=\"%s\"", srcIP))

Here are my tests on Debian:
Create HTTP bin on https://requestb.in

$ sudo ip -6 addr add 2002:c000:203::1/64 dev wlan0
$ ./beeping -listen "[2002:c000:203::1]"
$ curl -6 '[2002:c000:203::1]:8080/check' -d '{"url": "https://requestb.in/15qre161"}'

Thanks Aaron !
Cheers,
Yann

@yanc0 yanc0 mentioned this pull request Jul 7, 2017
Merged
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants