-
Notifications
You must be signed in to change notification settings - Fork 213
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
test: print ip address #14693
base: main
Are you sure you want to change the base?
test: print ip address #14693
Conversation
f""" | ||
ip: {flask.request.remote_addr}, | ||
forwared-ip: {flask.request.environ.get("HTTP_X_FORWARDED_FOR")}, | ||
remote-ip: {flask.request.environ.get("REMOTE_ADDR")} | ||
""" |
Check warning
Code scanning / CodeQL
Reflected server-side cross-site scripting Medium
user-provided value
Cross-site scripting vulnerability due to a
user-provided value
Cross-site scripting vulnerability due to a
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI 7 days ago
To fix the problem, we need to escape the user-provided input before including it in the response. The html.escape()
function from the standard library can be used to escape special characters in the user input, making it safe to include in the HTML response.
We will modify the testip
function to use html.escape()
to sanitize the user-provided input before including it in the response. This will prevent any potential XSS attacks by ensuring that special characters are properly escaped.
-
Copy modified lines R1228-R1231 -
Copy modified lines R1234-R1236
@@ -1227,7 +1227,11 @@ | ||
def testip(): | ||
from html import escape | ||
remote_addr = escape(flask.request.remote_addr or "") | ||
forwarded_ip = escape(flask.request.environ.get("HTTP_X_FORWARDED_FOR", "")) | ||
remote_ip = escape(flask.request.environ.get("REMOTE_ADDR", "")) | ||
resp = flask.Response( | ||
f""" | ||
ip: {flask.request.remote_addr}, | ||
forwared-ip: {flask.request.environ.get("HTTP_X_FORWARDED_FOR")}, | ||
remote-ip: {flask.request.environ.get("REMOTE_ADDR")} | ||
ip: {remote_addr}, | ||
forwared-ip: {forwarded_ip}, | ||
remote-ip: {remote_ip} | ||
""" |
Done