Skip to content

Commit

Permalink
Adding a setting to configure the source ip header if a proxy sets it…
Browse files Browse the repository at this point in the history
… as a different value to x-real-ip while keeping it as the default value
  • Loading branch information
mosslilley authored and nickrohrbs committed Oct 30, 2023
1 parent 69bc760 commit 43620aa
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions canarytokens/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class SwitchboardSettings(BaseSettings):
REDIS_PORT: Port = Port(6379)
REDIS_DB: str = "0"

REAL_IP_HEADER: str = "x-real-ip"

WG_PRIVATE_KEY_SEED: str
WG_PRIVATE_KEY_N: str = "1000"

Expand Down
5 changes: 4 additions & 1 deletion canarytokens/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from twisted.web.http import Request
from twisted.web.util import redirectTo

from canarytokens.settings import SwitchboardSettings

from canarytokens import canarydrop, queries
from canarytokens.constants import (
CANARYTOKEN_ALPHABET,
Expand Down Expand Up @@ -67,6 +69,7 @@

g_template_dir: Optional[str]

switchboard_settings = SwitchboardSettings()

def set_template_env(template_dir):
global g_template_dir
Expand Down Expand Up @@ -261,7 +264,7 @@ def _log4_shell(matches: Match[AnyStr]) -> dict[str, dict[str, str]]:
def _grab_http_general_info(request: Request):
""""""
useragent = request.getHeader("User-Agent") or "(no user-agent specified)"
src_ip = request.getHeader("x-real-ip") or request.client.host
src_ip = request.getHeader(switchboard_settings.REAL_IP_HEADER) or request.client.host
# DESIGN/TODO: this makes a call to third party ensure we happy with fails here
# and have default.
is_tor_relay = queries.is_tor_relay(src_ip)
Expand Down
1 change: 1 addition & 0 deletions switchboard/switchboard.env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ CANARY_SWITCHBOARD_SCHEME=http
#CANARY_REDIS_HOST=
#CANARY_REDIS_PORT=
#CANARY_REDIS_DB=
#CANARY_REAL_IP_HEADER=

CANARY_WG_PRIVATE_KEY_SEED=vk/GD+frlhve/hDTTSUvqpQ/WsQtioKAri0Rt5mg7dw=
#CANARY_WG_PRIVATE_KEY_N=
Expand Down

0 comments on commit 43620aa

Please sign in to comment.