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

User: Make email required at all times, password required for new users #10938

Merged
merged 3 commits into from
Sep 20, 2024

Conversation

Maffooch
Copy link
Contributor

Creating local users is not the best experience. To accommodate a flow that supports sending temporary passwords to user, and forcing them to login again, we need to make the password field and email field required attributes for new users

[sc-7616]

Copy link

dryrunsecurity bot commented Sep 19, 2024

DryRun Security Summary

The pull request focuses on improving the security and robustness of the user management functionality by enforcing email and password requirements, restricting password updates, validating password strength, implementing least privilege, and improving test coverage.

Expand for full summary

Summary:

The code changes in this pull request focus on improving the security and robustness of the user management functionality in the application. The changes include:

  1. Enforcing Email and Password Requirements: The changes ensure that email and password fields are required when creating or editing user accounts, which helps to maintain better user identification and authentication.

  2. Restricting Password Updates: The changes disallow password updates through the API, forcing users to update their passwords through a more secure and user-controlled process, such as a web interface or a dedicated password reset functionality.

  3. Validating Password Strength: The changes include tests to ensure that the application properly validates the strength of user passwords, preventing the use of weak passwords that could lead to security vulnerabilities.

  4. Implementing Least Privilege: The changes include tests to ensure that users are only granted the minimum required permissions based on their roles and responsibilities, following the principle of least privilege.

  5. Improving Test Coverage: The changes introduce new test cases to cover various security-related aspects of the user management functionality, such as user creation, password validation, and permission management. This helps to ensure the overall security and reliability of the application.

Files Changed:

  • unittests/test_apiv2_notifications.py: The changes add an email field to the user creation payload in the test case, which is a common requirement for user registration. The changes also ensure that the test environment is properly cleaned up after the tests are completed.
  • dojo/forms.py: The changes make the email field required and the password field required in the user creation and editing forms, which improves the overall security of the user management functionality.
  • tests/user_test.py: The changes introduce a new user with a strong password and the "Writer" global role. While the password used in the test case is strong, the code should avoid directly setting passwords and instead use hashed and salted passwords to protect against password-related attacks.
  • dojo/api_v2/serializers.py: The changes require the email field in the UserSerializer and restrict password updates through the API, which are positive security enhancements.
  • unittests/test_apiv2_user.py: The changes include tests for user creation with strong and weak passwords, as well as tests for password update restrictions, which help to ensure the security of the User API endpoint.
  • unittests/test_rest_framework.py: The changes introduce new test cases to ensure that users can only be created with the appropriate permissions, which helps to prevent unauthorized access and privilege escalation.

Code Analysis

We ran 9 analyzers against 6 files and 1 analyzer had findings. 8 analyzers had no findings.

Analyzer Findings
Authn/Authz Analyzer 4 findings

Riskiness

🟢 Risk threshold not exceeded.

View PR in the DryRun Dashboard.

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

Copy link
Contributor

@cneill cneill left a comment

Choose a reason for hiding this comment

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

Just a small comment about one of the tests

response = self.client.post(self.url, payload)
self.assertEqual(201, response.status_code, response.content[:1000])
self.assertEqual(self.endpoint_model.objects.count(), length + 1)

def test_create_user_with_non_configuration_permissions(self):
Copy link
Contributor

@cneill cneill Sep 20, 2024

Choose a reason for hiding this comment

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

I guess test_create_user_with_non_configuration_permissions will fail with both object does not exist and a message about the user missing a password, but seems like we should supply the password just to make it clearer what's supposed to fail here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure thing

@mtesauro mtesauro merged commit cdee30b into DefectDojo:bugfix Sep 20, 2024
73 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