Skip to content

[Enhancement] Add automatic cleanup for expired authentication nonces #452

Description

@giwaov

Description

Expired authentication nonces accumulate in the database over time, potentially causing storage bloat and performance degradation.

Current Behavior

  • Nonces are created for each SIWE authentication attempt
  • Nonces expire after 5 minutes
  • Used and expired nonces remain in the database indefinitely

Expected Behavior

  • Expired and used nonces should be automatically cleaned up
  • Database should not accumulate stale authentication data

Impact

  • Database storage grows unnecessarily
  • Potential performance impact on nonce lookups
  • Stale data in production database

Suggested Solution

A management command has been proposed in PR #450 that provides:

# Clean up nonces expired more than 1 hour ago
python manage.py cleanup_nonces

# Preview what would be deleted
python manage.py cleanup_nonces --dry-run

# Custom age threshold
python manage.py cleanup_nonces --hours 24

This should be scheduled to run periodically (daily recommended) via:

  • Cron job
  • Django-celery-beat
  • AWS CloudWatch Events (for App Runner deployments)

Code Location

  • Model: backend/ethereum_auth/models.py - Nonce class
  • Views: backend/ethereum_auth/views.py - nonce creation/validation

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions