Skip to content

security/add correct token behavior - #93

Open
pablo-schmeiser wants to merge 19 commits into
HaDiNet:masterfrom
pablo-schmeiser:security/add-correct-token-behavior
Open

security/add correct token behavior#93
pablo-schmeiser wants to merge 19 commits into
HaDiNet:masterfrom
pablo-schmeiser:security/add-correct-token-behavior

Conversation

@pablo-schmeiser

Copy link
Copy Markdown
Collaborator

Description
This PR introduces robust security enhancements for token-based authentication flows (password reset and email confirmation), mitigating risks related to token guessing, brute-forcing, and replay attacks.

Security Mitigations (CWEs)

Key Changes

  • Security Validator (TokenSecurityValidator): Added a centralized security validator to comprehensively check tokens, manage rate limits, and safely mark tokens as used.
  • Rate Limiting & Logging:
    • Added new models (FailedTokenAttempt, TokenUsageLog) to track failed validation attempts and successful token usage.
  • Enhanced View Protections:
    • PasswordResetConfirmView: Integrated the TokenSecurityValidator to check rate limits before token validation and correctly mark tokens as used.
    • ConfirmEMailView: Updated to handle and log invalid UID/token attempts and mark confirmation links as used. Client IPs are extracted and logged appropriately.
  • Configuration: Added tuning parameters to local_settings.sample.py (and default settings.py) to easily control max failed attempts and time windows (e.g., TOKEN_SECURITY_MAX_FAILED_ATTEMPTS_PER_IP, TOKEN_SECURITY_MAX_TOKEN_LENGTH).
  • Testing: Includes comprehensive unit tests (test_token_security.py) to verify the new token security logic and rate limits, alongside updates to existing user and password view tests.

NOTE TO REVIEWERS

This should be merged after #92

- Add non-field error handling and improve already present error handling in shift creation
- Remove green hghlighting for valid, but optional form fields and removing green checkmark from optional form select fields
This is a combination of 5 commits.
- chore: Create Mixins for shared, inherited behavior
- chore: Refactor shared membership inheritance
- chore: Register models to admin view in helper function
- chore: Refactor URL patterns to use shared organization CRUD helper
- chore: Refactor URL patterns to utilize organization_crud_paths for events and shifts
This is a combination of 3 commits.
- fix: Group details were not reachable due to same url
- fix: Correct inheritance order for OrganizationCreateUpdateMixin
- fix: Refactor delete view classes to fix inheritance issue
This is a combination of 3 commits.
- chore: Refactor form templates to use shared remove/restore button component
- chore: Refactor often reused buttons to deduplicate code and fix modal backdrop behavior
	NOTE: Modal is now top-level to correct behavior. Temporary patch for iOS was removed and should be tested on iOS in the future.
- chore: Refactor modal trigger components to reduce duplication and improve maintainability
This is a combination of 9 commits.
- chore: Add coverage configuration and update dependencies for testing
- test: Add set_language to tests
- test: Add unit tests for user and membership forms to improve coverage
- test: Add unit tests for user authentication and email confirmation flows
- fix: Update SSO login condition to check if OAUTH is enabled
- test: Add unit tests for SSO login and protected content views
- test: Consolidate DOM manipulation tests and improve structure
	- Introduced a new `dom-harness.cjs` file to centralize DOM-related utilities for testing.
	- Created various test files for different components, including formset, modal handlers, navigation, sliders, save and restore functionality, and theme toggle.
	- Refactored class list and element creation logic to reduce duplication across tests.
	- Enhanced test setups to better simulate user interactions and DOM events.
	- Improved assertions for clarity and accuracy in testing expected behaviors.
- test: Add unit tests for BaseMixin and permission handling in views
- docs: Add Testing Quality Scorecard documentation
- Removed member_shift_summary template and integrated its functionality into shift_users_summary.
- Updated templates to use shift_users_summary for displaying user shifts.
- Added non-org participants to summary.
- Introduced tests for shift_users_summary functionality and filtering behavior.
@pablo-schmeiser pablo-schmeiser self-assigned this Aug 2, 2026
@pablo-schmeiser pablo-schmeiser added the bug Something isn't working label Aug 2, 2026

@pablo-schmeiser pablo-schmeiser left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Added a review and found some stuff to improve

Comment thread src/shiftings/accounts/views/password.py Outdated

if ip_attempts >= self.max_failed_attempts_per_ip:
logger.warning(
f'Rate limit exceeded for IP {ip_address}: '

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

IP addresses are PII and should not be logged directly (logging a hash may be sufficient) or only in combination with a data retention policy.

Comment thread src/shiftings/accounts/views/user.py Outdated
Comment thread src/shiftings/accounts/views/user.py
Comment thread src/shiftings/accounts/views/user.py Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant