-
Notifications
You must be signed in to change notification settings - Fork 113
merge #5
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
Conversation
fix 403!
Bumps [requests](https://github.com/psf/requests) from 2.31.0 to 2.32.2. - [Release notes](https://github.com/psf/requests/releases) - [Changelog](https://github.com/psf/requests/blob/main/HISTORY.md) - [Commits](psf/requests@v2.31.0...v2.32.2) --- updated-dependencies: - dependency-name: requests dependency-type: direct:production ... Signed-off-by: dependabot[bot] <[email protected]>
…sers and solutions for different chip architectures.
Bump requests from 2.31.0 to 2.32.2
Update the README file, add solutions for Mac users
|
This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation. |
| except Exception as e: | ||
| logger.error(f"Error handling request: {str(e)}") | ||
| return web.Response( | ||
| text=json.dumps({"error": str(e)}), |
Check warning
Code scanning / CodeQL
Information exposure through an exception Medium
Stack trace information
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 8 months ago
To fix the problem, we need to ensure that the detailed exception message is not sent back to the client. Instead, we should log the detailed error message on the server and return a generic error message to the client. This approach maintains the ability to debug issues using server logs while protecting sensitive information from being exposed to external users.
Steps to fix:
- Modify the exception handling block to log the detailed error message using
logger.error. - Return a generic error message to the client instead of the detailed exception message.
-
Copy modified line R87
| @@ -86,3 +86,3 @@ | ||
| return web.Response( | ||
| text=json.dumps({"error": str(e)}), | ||
| text=json.dumps({"error": "An internal error has occurred."}), | ||
| status=500, |
| except Exception as e: | ||
| logger.error(f"Error processing TTS request: {str(e)}") | ||
| return web.Response( | ||
| text=json.dumps({"error": str(e)}), |
Check warning
Code scanning / CodeQL
Information exposure through an exception Medium
Stack trace information
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 8 months ago
To fix the problem, we should ensure that detailed exception information is not exposed to the user. Instead, we should log the detailed error message on the server and return a generic error message to the user. This approach maintains the ability to debug issues using server logs while protecting sensitive information from being exposed to potential attackers.
- Modify the exception handling block to log the detailed error message.
- Return a generic error message to the user instead of the detailed exception message.
-
Copy modified line R170
| @@ -169,3 +169,3 @@ | ||
| return web.Response( | ||
| text=json.dumps({"error": str(e)}), | ||
| text=json.dumps({"error": "An internal error has occurred."}), | ||
| status=500, |
| full_path = Path(__file__).parent.parent / 'static' / file_path | ||
|
|
||
| # Check if file exists | ||
| if not full_path.exists(): |
Check failure
Code scanning / CodeQL
Uncontrolled data used in path expression High
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 8 months ago
To fix the problem, we need to ensure that the constructed file path is contained within a safe root directory. This can be achieved by normalizing the path using os.path.normpath and then checking that the normalized path starts with the root directory. This will prevent any attempts to access files outside the intended directory.
- Normalize the
full_pathusingos.path.normpath. - Check if the normalized
full_pathstarts with the intended root directory. - If the check fails, raise an exception or return a 403 Forbidden response.
-
Copy modified lines R210-R216 -
Copy modified line R219
| @@ -209,6 +209,12 @@ | ||
| # Construct full path - look in static directory | ||
| full_path = Path(__file__).parent.parent / 'static' / file_path | ||
| base_path = Path(__file__).parent.parent / 'static' | ||
| full_path = base_path / file_path | ||
| normalized_full_path = full_path.resolve() | ||
|
|
||
| # Check if the normalized path is within the base path | ||
| if not str(normalized_full_path).startswith(str(base_path)): | ||
| return web.Response(text="Forbidden", status=403) | ||
|
|
||
| # Check if file exists | ||
| if not full_path.exists(): | ||
| if not normalized_full_path.exists(): | ||
| return web.Response(text="Not found", status=404) |
| return web.Response(text="Not found", status=404) | ||
|
|
||
| # Read file | ||
| with open(full_path, 'rb') as f: |
Check failure
Code scanning / CodeQL
Uncontrolled data used in path expression High
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 8 months ago
To fix the problem, we need to ensure that the constructed file path is contained within a safe root directory. We can achieve this by normalizing the path using os.path.normpath and then checking that the normalized path starts with the root directory. This will prevent path traversal attacks and ensure that only files within the designated static directory can be accessed.
- Normalize the
full_pathusingos.path.normpath. - Check that the normalized
full_pathstarts with the static directory path. - If the check fails, return a 403 Forbidden response.
-
Copy modified lines R210-R216 -
Copy modified line R219
| @@ -209,6 +209,12 @@ | ||
| # Construct full path - look in static directory | ||
| full_path = Path(__file__).parent.parent / 'static' / file_path | ||
| static_dir = Path(__file__).parent.parent / 'static' | ||
| full_path = static_dir / file_path | ||
| normalized_full_path = full_path.resolve() | ||
|
|
||
| # Ensure the path is within the static directory | ||
| if not str(normalized_full_path).startswith(str(static_dir)): | ||
| return web.Response(text="Forbidden", status=403) | ||
|
|
||
| # Check if file exists | ||
| if not full_path.exists(): | ||
| if not normalized_full_path.exists(): | ||
| return web.Response(text="Not found", status=404) |
|
|
||
| except Exception as e: | ||
| logger.error(f"Error serving static file: {str(e)}") | ||
| return web.Response(text=str(e), status=500) No newline at end of file |
Check warning
Code scanning / CodeQL
Information exposure through an exception Medium
Stack trace information
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 8 months ago
To fix the problem, we should replace the detailed error message returned to the user with a generic error message. The detailed error message should be logged on the server for debugging purposes. This approach ensures that sensitive information is not exposed to external users while still allowing developers to access the necessary details for troubleshooting.
- Modify the exception handling block in the
handle_staticfunction to return a generic error message instead ofstr(e). - Ensure that the detailed error message is logged on the server.
-
Copy modified line R244
| @@ -243,2 +243,2 @@ | ||
| logger.error(f"Error serving static file: {str(e)}") | ||
| return web.Response(text=str(e), status=500) | ||
| return web.Response(text="An internal error has occurred.", status=500) |
| <link rel="stylesheet" href="styles.css"> | ||
| <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism-tomorrow.min.css"> | ||
| <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css"> | ||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/prism.min.js"></script> |
Check warning
Code scanning / CodeQL
Inclusion of functionality from an untrusted source Medium
| <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism-tomorrow.min.css"> | ||
| <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css"> | ||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/prism.min.js"></script> | ||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-python.min.js"></script> |
Check warning
Code scanning / CodeQL
Inclusion of functionality from an untrusted source Medium
| <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css"> | ||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/prism.min.js"></script> | ||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-python.min.js"></script> | ||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-json.min.js"></script> |
Check warning
Code scanning / CodeQL
Inclusion of functionality from an untrusted source Medium
| <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/prism.min.js"></script> | ||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-python.min.js"></script> | ||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-json.min.js"></script> | ||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-javascript.min.js"></script> |
Check warning
Code scanning / CodeQL
Inclusion of functionality from an untrusted source Medium
No description provided.