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

test: print ip address #14693

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

test: print ip address #14693

wants to merge 7 commits into from

Conversation

samhotep
Copy link
Member

Done

  • Print IP address. Will de deployed to staging, and should print IP with additional changes to k8s ingress.

@webteam-app
Copy link

Comment on lines +1229 to +1233
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

Cross-site scripting vulnerability due to a
user-provided value
.
Cross-site scripting vulnerability due to a
user-provided value
.
Cross-site scripting vulnerability due to a
user-provided value
.

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.

Suggested changeset 1
webapp/app.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/webapp/app.py b/webapp/app.py
--- a/webapp/app.py
+++ b/webapp/app.py
@@ -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}
         """
EOF
@@ -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}
"""
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants