Skip to content

Commit 40b8813

Browse files
authored
Add debug endpoint to help inspect what headers and IP address CTFd sees (CTFd#2546)
* Add the `/debug` endpoint that will show what headers CTFd sees as well as the user's IP address. * `/debug` will only be available when `SAFE_MODE` is enabled
1 parent eaaf5ae commit 40b8813

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

CTFd/views.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
unserialize,
6666
)
6767
from CTFd.utils.uploads import get_uploader, upload_file
68-
from CTFd.utils.user import authed, get_current_team, get_current_user, is_admin
68+
from CTFd.utils.user import authed, get_current_team, get_current_user, get_ip, is_admin
6969

7070
views = Blueprint("views", __name__)
7171

@@ -557,6 +557,23 @@ def healthcheck():
557557
return "OK", 200
558558

559559

560+
@views.route("/debug")
561+
def debug():
562+
if app.config.get("SAFE_MODE") is True:
563+
ip = get_ip()
564+
headers = dict(request.headers)
565+
# Remove Cookie item
566+
headers.pop("Cookie", None)
567+
resp = ""
568+
resp += f"IP: {ip}\n"
569+
for k, v in headers.items():
570+
resp += f"{k}: {v}\n"
571+
r = make_response(resp)
572+
r.mimetype = "text/plain"
573+
return r
574+
abort(404)
575+
576+
560577
@views.route("/robots.txt")
561578
def robots():
562579
text = get_config("robots_txt", "User-agent: *\nDisallow: /admin\n")

0 commit comments

Comments
 (0)