-
Notifications
You must be signed in to change notification settings - Fork 2
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
1493 ruff format #1498
base: devel
Are you sure you want to change the base?
1493 ruff format #1498
Conversation
if file: | ||
try: | ||
validate_file(file) | ||
except ValidationError as e: | ||
raise serializers.ValidationError({'file': e}) | ||
raise serializers.ValidationError({"file": e}) |
Check warning
Code scanning / CodeQL
Information exposure through an exception Medium
Stack trace information
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI about 17 hours ago
To fix the problem, we should modify the code to log the detailed exception information on the server and return a generic error message to the user. This approach ensures that sensitive information is not exposed to the end user while still allowing developers to access the detailed error information for debugging purposes.
- Import the
logging
module to log the exception details. - Replace the direct use of the exception
e
in theserializers.ValidationError
with a generic error message. - Log the detailed exception information using the
logging
module.
-
Copy modified line R17 -
Copy modified lines R592-R593
@@ -16,2 +16,3 @@ | ||
from vitrina.tasks.models import Task | ||
import logging | ||
|
||
@@ -590,3 +591,4 @@ | ||
except ValidationError as e: | ||
raise serializers.ValidationError({"file": e}) | ||
logging.error("Validation error occurred: %s", e) | ||
raise serializers.ValidationError({"file": _("An error occurred while validating the file.")}) | ||
if file and url: |
if file: | ||
try: | ||
validate_file(file) | ||
except ValidationError as e: | ||
raise serializers.ValidationError({'file': e}) | ||
raise serializers.ValidationError({"file": e}) |
Check warning
Code scanning / CodeQL
Information exposure through an exception Medium
Stack trace information
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix AI about 17 hours ago
To fix the problem, we should ensure that the exception message does not expose sensitive information to the end user. Instead of passing the exception e
directly, we can log the detailed exception on the server and return a generic error message to the user.
- Modify the
validate
method in thePostDatasetStructureSerializer
class to log the exception and raise a generic error message. - Add necessary imports for logging if not already present.
-
Copy modified lines R673-R678
@@ -672,3 +672,8 @@ | ||
except ValidationError as e: | ||
raise serializers.ValidationError({"file": e}) | ||
# Log the detailed exception | ||
import logging | ||
logger = logging.getLogger(__name__) | ||
logger.error("File validation error: %s", e) | ||
# Raise a generic error message | ||
raise serializers.ValidationError({"file": _("Invalid file format.")}) | ||
return data |
Separate PR to clean code with two
ruff
commands:poetry run ruff format .
poetry run ruff check . --fix