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

Prefetch Serialization: Add a preference during mapping #10933

Merged
merged 1 commit into from
Sep 20, 2024

Conversation

Maffooch
Copy link
Contributor

@Maffooch Maffooch commented Sep 18, 2024

When prefetching via the API, the serializer to user is dynamically fetched. There are cases where there is more than one ModelSerializer on defined, and the wrong one is selected. This PR adds a dict to specify the preferred serializer to user a per model basis

The motivation for this PR is when prefetching a finding with files. Before this PR, a 500 error would be generated

[sc-6061]

Copy link

DryRun Security Summary

The pull request optimizes the serialization process in the prefetcher.py file by adding a preferred_serializers dictionary and modifying the _build_serializers method, which does not appear to introduce any obvious security vulnerabilities but requires careful management to prevent unintended consequences.

Expand for full summary

Summary:

The code changes in this pull request are focused on optimizing the serialization process in the prefetcher.py file. The key changes include the addition of a preferred_serializers dictionary to map the FileUpload model to the FileSerializer serializer, and the modification of the _build_serializers method to use the preferred serializer if available.

From an application security perspective, these changes do not appear to introduce any obvious security vulnerabilities. The optimizations can potentially improve the performance of the application, which is a positive security measure. However, it's important to ensure that the use of the "preferred serializers" dictionary is carefully managed to prevent any unintended consequences, such as using an outdated or insecure serializer. Additionally, the code's use of the inspect module and dynamic class loading should be reviewed to ensure that input is properly sanitized and validated to prevent potential injection attacks.

Overall, the changes in this code appear to be focused on performance optimization and do not introduce any obvious security vulnerabilities. Nevertheless, it's essential to maintain a vigilant approach to security and regularly review the code for potential issues.

Files Changed:

  • dojo/api_v2/prefetch/prefetcher.py: The changes in this file are focused on optimizing the serialization process. A preferred_serializers dictionary has been added to map the FileUpload model to the FileSerializer serializer, and the _build_serializers method has been modified to use the preferred serializer if available. These changes do not appear to introduce any obvious security vulnerabilities, but the use of the "preferred serializers" dictionary should be carefully managed to prevent any unintended consequences.

Code Analysis

We ran 9 analyzers against 1 file and 0 analyzers had findings. 9 analyzers had no findings.

Riskiness

🟢 Risk threshold not exceeded.

View PR in the DryRun Dashboard.

@github-actions github-actions bot added the apiv2 label Sep 18, 2024
Copy link
Contributor

@mtesauro mtesauro left a comment

Choose a reason for hiding this comment

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

Approved

@mtesauro mtesauro merged commit aadf96b into DefectDojo:bugfix Sep 20, 2024
72 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants