fix: use constant-time sync admin key check#4196
Conversation
|
Welcome to RustChain! Thanks for your first pull request. Before we review, please make sure:
Bounty tiers: Micro (1-10 RTC) | Standard (20-50) | Major (75-100) | Critical (100-150) A maintainer will review your PR soon. Thanks for contributing! |
cerredz
left a comment
There was a problem hiding this comment.
Sync admin timing fix review.
I verified this locally on the PR branch. The change is narrowly scoped to the require_admin decorator and preserves the existing reject/accept behavior while routing non-empty supplied keys through hmac.compare_digest().
Validation performed:
python -m pytest node\tests\test_rustchain_sync_endpoints.py -q=> 1 passedpython -m py_compile node\rustchain_sync_endpoints.py node\tests\test_rustchain_sync_endpoints.pygit diff --check origin/main...HEAD
No blocking findings from my review.
|
💰 PAID — 10 RTC pending, will confirm in 24h.
What workedSync admin decorator hardened correctly + the new test hits real endpoint behavior, not just source text. Solid second contribution from @0oAstro — the test pattern (real endpoint, real auth path) is the gold standard. — auto-triage 2026-05-10 |
Summary
Fixes #3226 by replacing the sync admin decorator's timing-unsafe API key comparison with
hmac.compare_digest().This is intentionally scoped to one issue and two files, following the branch-contamination closure guidance on earlier broad timing-fix PRs.
Root cause
register_sync_endpoints(...).require_admincompared the providedX-Admin-Key/X-API-Keyto the configured sync admin key with!=. The same module already useshmac.compare_digest()for sync signatures, but the admin decorator did not.Changes
hmac.compare_digest(key, admin_key)for sync admin auth./api/sync/statuscallshmac.compare_digestand still rejects/accepts invalid/valid keys correctly.Validation
Passed:
Bounty
Claiming bug bounty for #3226.
RTC wallet:
RTC5268f16391bcdff87c43cd8694fca3be9d995359