Skip to content

Conversation

@p-r-a-v-i-n
Copy link
Contributor

@p-r-a-v-i-n p-r-a-v-i-n commented Dec 2, 2025

Trac ticket number

ticket-36546

Branch description

This PR addresses the first phase of cleanup for ticket-36546 by refactoring Django's internal codebase.

The existing wrapper functiondjango.utils.crypto.constant_time_compare()is redundant for internal Django use. It was also using force_bytes which not needed .
This change replaces all internal calls with secrets.compare_digest().

  • The definition of the original constant_time_compare() function remains untouched to maintain backwards compatibility for external libraries that rely on its current type-coercion behavior (as discussed following the revert in ticket-36572).

Checklist

  • This PR targets the main branch.
  • The commit message is written in past tense, mentions the ticket number, and ends with a period.
  • I have checked the "Has patch" ticket flag in the Trac system.
  • I have added or updated relevant tests.
  • I have added or updated relevant docs, including release notes if applicable.
  • I have attached screenshots in both light and dark modes for any UI changes.

@jacobtylerwalls jacobtylerwalls changed the title Refs #36546 – Replaced internal usage of constant_time_compare() with secrets.compare_digest() Refs #36546 -- Replaced internal usage of constant_time_compare() with secrets.compare_digest() Dec 3, 2025
@timgraham timgraham changed the title Refs #36546 -- Replaced internal usage of constant_time_compare() with secrets.compare_digest() Refs #36546 -- Replaced usage of constant_time_compare() with hmac.compare_digest(). Dec 9, 2025
@timgraham
Copy link
Member

Please use hmac.compare_digest() instead of secrets. The latter is an alias of the former.

@p-r-a-v-i-n
Copy link
Contributor Author

Hi @timgraham , Thanks for the feedback. I have replaced with hmac now.

@github-actions
Copy link

github-actions bot commented Dec 9, 2025

📊 Coverage Report for Changed Files

-------------
Diff Coverage
Diff: origin/main...HEAD, staged and unstaged changes
-------------
django/contrib/auth/__init__.py (100%)
django/contrib/auth/hashers.py (100%)
django/contrib/auth/tokens.py (100%)
django/core/signing.py (100%)
django/middleware/csrf.py (100%)
-------------
Total:   17 lines
Missing: 0 lines
Coverage: 100%
-------------


Note: Missing lines are warnings only. Some lines may not be covered by SQLite tests as they are database-specific.

For more information about code coverage on pull requests, see the contributing documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants