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

Feature - making X-Real-IP configurable #70

Merged
merged 2 commits into from
Mar 1, 2023
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ In the event of a missing configuration file, HellPot will attempt to place it's
bind_addr = "127.0.0.1"
bind_port = "8080"

# header name containing clients real IP, for reverse proxy deployments
real_ip_header = 'X-Real-IP'

# this contains a list of blacklisted useragent strings. (case sensitive)
# clients with useragents containing any of these strings will receive "Not found" for any requests.
uagent_string_blacklist = ["Cloudflare-Traffic-Manager", "curl"]
Expand Down
1 change: 1 addition & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ func processOpts() {
stringOpt := map[string]*string{
"http.bind_addr": &HTTPBind,
"http.bind_port": &HTTPPort,
"http.real_ip_header": &HeaderName,
"logger.directory": &logDir,
"deception.server_name": &FakeServerName,
}
Expand Down
1 change: 1 addition & 0 deletions internal/config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ var defOpts = map[string]map[string]interface{}{
"unix_socket_permissions": "0666",
"bind_addr": "127.0.0.1",
"bind_port": "8080",
"real_ip_header": "X-Real-IP",

"router": map[string]interface{}{
"catchall": false,
Expand Down
4 changes: 4 additions & 0 deletions internal/config/globals.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ var (
HTTPBind string
// HTTPPort is defined via our toml configuration file. It is the port that HellPot listens on.
HTTPPort string
// HeaderName is defined via our toml configuration file. It is the HTTP Header containing the original IP of the client,
// in traditional reverse Proxy deplyoments.
HeaderName string

// Paths are defined via our toml configuration file. These are the paths that HellPot will present for "robots.txt"
// These are also the paths that HellPot will respond for. Other paths will throw a warning and will serve a 404.
Paths []string
Expand Down
2 changes: 1 addition & 1 deletion internal/http/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
var log *zerolog.Logger

func getRealRemote(ctx *fasthttp.RequestCtx) string {
xrealip := string(ctx.Request.Header.Peek("X-Real-IP"))
xrealip := string(ctx.Request.Header.Peek(config.HeaderName))
if len(xrealip) > 0 {
return xrealip
}
Expand Down