Skip to content
This repository was archived by the owner on Oct 2, 2020. It is now read-only.

Commit 6b1eea7

Browse files
committed
Accept X-Real-IP from localhost
1 parent 7a58add commit 6b1eea7

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,5 @@ something like this:
5454

5555
location /hook {
5656
proxy_pass http://localhost:8000;
57+
proxy_set_header X-Real-IP $remote_addr;
5758
}

hooks.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,16 @@ def hook_publish():
6363
hook = matches[0]
6464

6565
allow = False
66+
remote = request.remote_addr
67+
if remote == "127.0.0.1" and "X-Real-IP" in request.headers:
68+
remote = request.headers.get("X-Real-IP")
6669
for ip in hook.valid_ips.split(","):
6770
parts = ip.split("/")
6871
range = 32
6972
if len(parts) != 1:
7073
range = int(parts[1])
7174
addr = networkMask(parts[0], range)
72-
if addressInNetwork(dottedQuadToNum(request.remote_addr), addr):
75+
if addressInNetwork(dottedQuadToNum(remote), addr):
7376
allow = True
7477
if not allow:
7578
return "Hook rejected: unauthorized IP", 403

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
url="https://github.com/SirCmpwn/hooks",
66
description="Executes commands based on Github hooks",
77
license="MIT",
8-
version="1.0",
8+
version="1.1",
99
scripts=["ghhooks"],
1010
py_modules=["hooks"],
1111
install_requires=["Flask"])

0 commit comments

Comments
 (0)