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

Canonical CLA integration #14296

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

Canonical CLA integration #14296

wants to merge 27 commits into from

Conversation

goulinkh
Copy link
Contributor

Done

  • [List of work items including drive-bys - remember to add the why and what of this work.]

QA

  • Check out this feature branch
  • Run the site using the command ./run serve or dotrun
  • View the site locally in your web browser at: http://0.0.0.0:8001/
    • Be sure to test on mobile, tablet and desktop screen sizes
  • [List additional steps to QA the new features or prove the bug has been resolved]

Issue / Card

Fixes #

Screenshots

[If relevant, please include a screenshot.]

Help

QA steps - Commit guidelines

@webteam-app
Copy link

webapp/canonical_cla/views.py Fixed Show fixed Hide fixed
webapp/canonical_cla/views.py Fixed Show resolved Hide resolved
error_response.cache_control.no_store = True
return error_response
else:
response = flask.make_response(api_service_response.content)

Check warning

Code scanning / CodeQL

Reflected server-side cross-site scripting Medium

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

Copilot Autofix AI 29 days ago

To fix the problem, we need to ensure that the content returned from the external API is properly sanitized before being sent to the client. This can be achieved by escaping the content to prevent any malicious scripts from being executed in the user's browser.

The best way to fix this issue is to use the html.escape() function from the html module to escape the content before returning it to the client. This will ensure that any potentially dangerous characters are converted to their corresponding HTML-safe sequences.

Suggested changeset 1
webapp/canonical_cla/views.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/canonical_cla/views.py b/webapp/canonical_cla/views.py
--- a/webapp/canonical_cla/views.py
+++ b/webapp/canonical_cla/views.py
@@ -162,3 +162,5 @@
     else:
-        response = flask.make_response(api_service_response.content)
+        from html import escape
+        escaped_content = escape(api_service_response.content.decode('utf-8'))
+        response = flask.make_response(escaped_content)
         response.headers["Content-Type"] = api_service_response.headers[
EOF
@@ -162,3 +162,5 @@
else:
response = flask.make_response(api_service_response.content)
from html import escape
escaped_content = escape(api_service_response.content.decode('utf-8'))
response = flask.make_response(escaped_content)
response.headers["Content-Type"] = api_service_response.headers[
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
Copy link
Contributor Author

@goulinkh goulinkh Oct 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We trust the API response as it's our service not a 3rd party service so this is risk doesn't apply in our case.

@goulinkh goulinkh changed the title Canonical cla Canonical CLA integration Oct 22, 2024
Comment on lines +132 to +141
api_service_response = requests.request(
timeout=10,
method=flask.request.method,
url=urlparse.urljoin(CANONICAL_CLA_API_URL, request_url),
headers={
"X-Custom-Forwarded-For": client_ip,
},
cookies=flask.request.cookies,
data=flask.request.data,
)

Check failure

Code scanning / CodeQL

Full server-side request forgery Critical

The full URL of this request depends on a
user-provided value
.

Copilot Autofix AI 29 days ago

To fix the problem, we need to validate the user-provided request_url to ensure it does not lead to an SSRF vulnerability. One way to do this is to maintain a list of allowed paths or domains and check the user input against this list. If the input is not in the allowed list, we should reject the request.

  • Add a list of allowed paths or domains.
  • Validate the request_url against this list before making the HTTP request.
  • If the request_url is not valid, return an error response.
Suggested changeset 1
webapp/canonical_cla/views.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/canonical_cla/views.py b/webapp/canonical_cla/views.py
--- a/webapp/canonical_cla/views.py
+++ b/webapp/canonical_cla/views.py
@@ -127,2 +127,8 @@
     request_url = base64.b64decode(encoded_request_url).decode("utf-8")
+    
+    # Validate the request_url against allowed paths
+    allowed_paths = ["/allowed/path1", "/allowed/path2"]
+    if not any(request_url.startswith(path) for path in allowed_paths):
+        return flask.abort(400, description="Invalid request URL")
+    
     client_ip = flask.request.headers.get(
EOF
@@ -127,2 +127,8 @@
request_url = base64.b64decode(encoded_request_url).decode("utf-8")

# Validate the request_url against allowed paths
allowed_paths = ["/allowed/path1", "/allowed/path2"]
if not any(request_url.startswith(path) for path in allowed_paths):
return flask.abort(400, description="Invalid request URL")

client_ip = flask.request.headers.get(
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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants