-
Notifications
You must be signed in to change notification settings - Fork 0
adding auto-instrumentation changes for django+circus package set up #84
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
base: main
Are you sure you want to change the base?
Conversation
| metadata['queue_name'] = path_parts[0] | ||
|
|
||
| # Extract region from AWS hostname | ||
| if parsed.hostname and 'amazonaws.com' in parsed.hostname: |
Check failure
Code scanning / CodeQL
Incomplete URL substring sanitization High
amazonaws.com
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 5 days ago
In general, the fix is to avoid using substring checks on the hostname and instead validate that the hostname structurally matches the expected AWS SQS domain. Here, we only need to identify real AWS SQS hosts, so we should check that the hostname either equals amazonaws.com with the right prefix parts, or ends with .amazonaws.com and has sqs as the first label, then extract the region from the second label. This preserves existing behavior for valid SQS URLs while avoiding accidental matches like malicious-amazonaws.com.
Concretely, in python/django-runscript/hello/tracing.py within extract_queue_metadata, replace the condition if parsed.hostname and 'amazonaws.com' in parsed.hostname: with a stricter suffix-based test. We can compute a boolean like is_aws_hostname = parsed.hostname == "amazonaws.com" or parsed.hostname.endswith(".amazonaws.com"), then only perform region extraction if this is true. Inside, we keep the existing split and hostname_parts[0] == 'sqs' and region extraction logic. No new imports are required because urllib.parse.urlparse is already imported within the function, and the fix is entirely contained in this method.
-
Copy modified lines R139-R148
| @@ -136,10 +136,16 @@ | ||
| metadata['queue_name'] = path_parts[0] | ||
|
|
||
| # Extract region from AWS hostname | ||
| if parsed.hostname and 'amazonaws.com' in parsed.hostname: | ||
| hostname_parts = parsed.hostname.split('.') | ||
| if len(hostname_parts) >= 3 and hostname_parts[0] == 'sqs': | ||
| metadata['region'] = hostname_parts[1] | ||
| if parsed.hostname: | ||
| # Ensure we only treat real AWS SQS hosts as AWS, not arbitrary hostnames | ||
| is_aws_hostname = ( | ||
| parsed.hostname == "amazonaws.com" | ||
| or parsed.hostname.endswith(".amazonaws.com") | ||
| ) | ||
| if is_aws_hostname: | ||
| hostname_parts = parsed.hostname.split('.') | ||
| if len(hostname_parts) >= 3 and hostname_parts[0] == 'sqs': | ||
| metadata['region'] = hostname_parts[1] | ||
|
|
||
| return metadata | ||
| except Exception as e: |
| return JsonResponse({ | ||
| 'error': str(e) | ||
| }, status=500) |
Check warning
Code scanning / CodeQL
Information exposure through an exception Medium
Stack trace information
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 5 days ago
In general, to fix this class of problem you should avoid sending raw exception messages or stack traces back to the client. Instead, log detailed error information on the server (for operators and developers) and return a generic, non-sensitive error message to the user, optionally with a simple error code that can be correlated with logs.
For this specific view, the best fix is to keep the detailed logging (logger.error(..., exc_info=True)) but change the HTTP response so it no longer includes str(e). We can replace it with a stable generic message like "An internal error occurred while sending the SQS message." or simply "Internal server error". This preserves the status code and JSON structure ({"error": ...}) while removing the sensitive content. The change is localized to the except block in send_sqs_message (lines 83–87). We do not need new imports or helpers; a literal string is sufficient.
-
Copy modified line R86
| @@ -83,7 +83,7 @@ | ||
| except Exception as e: | ||
| logger.error(f"Failed to send SQS message: {e}", exc_info=True) | ||
| return JsonResponse({ | ||
| 'error': str(e) | ||
| 'error': 'An internal error occurred while sending the SQS message.' | ||
| }, status=500) | ||
|
|
||
|
|
| return JsonResponse({ | ||
| 'error': str(e) | ||
| }, status=500) |
Check warning
Code scanning / CodeQL
Information exposure through an exception Medium
Stack trace information
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 5 days ago
In general, to fix this kind of issue, exception details should be logged server-side and replaced with a generic, user-safe error message in responses. The server logs retain enough information for debugging, while the client only sees a high-level indication that an error occurred.
For this specific case in python/django-runscript/hello/views.py, we should keep the logging line as-is (it already logs the exception and stack trace) and change the JSON response in the except block of get_queue_info to avoid including str(e). Instead, we can return a generic message like "Failed to get queue information" or "An internal error has occurred" that does not depend on the exception content. No new imports or helpers are required; we only need to modify lines 127–129 so that the error field is a constant string and no longer derived from e.
-
Copy modified line R128
| @@ -125,5 +125,5 @@ | ||
| except Exception as e: | ||
| logger.error(f"Failed to get queue info: {e}", exc_info=True) | ||
| return JsonResponse({ | ||
| 'error': str(e) | ||
| 'error': 'Failed to get queue information. Please try again later.' | ||
| }, status=500) |
No description provided.