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

endpoints to receive/forward hq invites #51

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

sravfeyn
Copy link
Member

user_token = request.data["user_token"]
invite_code = unquote_plus(callback_url)
try:
response = requests.post(callback_url, data={"invite_code": invite_code, "token": user_token})

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 4 days ago

To fix the SSRF vulnerability, we need to validate the callback_url to ensure it points to a trusted domain. One way to do this is to maintain a list of allowed domains and check if the callback_url belongs to one of these domains before making the request. This approach ensures that only URLs from trusted domains are used.

  1. Create a list of allowed domains.
  2. Parse the callback_url and extract the domain.
  3. Check if the extracted domain is in the list of allowed domains.
  4. If the domain is not allowed, return an error response.
  5. If the domain is allowed, proceed with the request.
Suggested changeset 1
users/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/users/views.py b/users/views.py
--- a/users/views.py
+++ b/users/views.py
@@ -3,3 +3,3 @@
 from secrets import token_hex
-from urllib.parse import quote_plus, unquote_plus
+from urllib.parse import quote_plus, unquote_plus, urlparse
 
@@ -459,2 +459,9 @@
         invite_code = unquote_plus(callback_url)
+        
+        # Validate the callback_url
+        allowed_domains = ["trusteddomain.com", "anothertrusteddomain.com"]
+        parsed_url = urlparse(unquote_plus(callback_url))
+        if parsed_url.netloc not in allowed_domains:
+            return JsonResponse({"error": "Invalid callback URL"}, status=400)
+        
         try:
EOF
@@ -3,3 +3,3 @@
from secrets import token_hex
from urllib.parse import quote_plus, unquote_plus
from urllib.parse import quote_plus, unquote_plus, urlparse

@@ -459,2 +459,9 @@
invite_code = unquote_plus(callback_url)

# Validate the callback_url
allowed_domains = ["trusteddomain.com", "anothertrusteddomain.com"]
parsed_url = urlparse(unquote_plus(callback_url))
if parsed_url.netloc not in allowed_domains:
return JsonResponse({"error": "Invalid callback URL"}, status=400)

try:
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
Collaborator

@calellowitz calellowitz left a comment

Choose a reason for hiding this comment

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

Couple small questions

authentication_classes = [ClientProtectedResourceAuth]

def post(self, request, *args, **kwargs):
callback_url = quote_plus(request.data["callback_url"])
Copy link
Collaborator

Choose a reason for hiding this comment

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

where does callback_url come from and point to?



class ConfirmHQInviteCallback(APIView):
authentication_classes = [ClientProtectedResourceAuth]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Who makes this call? Is this not from mobile?

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