Skip to content

Add Binxtils::Secure for constant-time secret comparison - #24

Merged
sethherr merged 1 commit into
mainfrom
compare
Aug 5, 2026
Merged

Add Binxtils::Secure for constant-time secret comparison#24
sethherr merged 1 commit into
mainfrom
compare

Conversation

@sethherr

@sethherr sethherr commented Aug 4, 2026

Copy link
Copy Markdown
Member

Adds a functionable Binxtils::Secure module for comparing a value against an expected secret (API tokens, webhook signatures) without leaking length or content through timing.

  • compare?(value, expected) — returns false unless expected is present, then defers to ActiveSupport::SecurityUtils.secure_compare. Both sides are to_s'd, so a non-string secret (e.g. an integer from config) compares rather than raising NoMethodError on bytesize.
  • lib/binxtils.rb requires active_support/security_utils explicitly — the existing active_support/core_ext require doesn't pull it in.
  • Specs cover match, length mismatch, single-character mismatch, non-string value/expected, and blank expected.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011yBbeP6HZZkEwWK4jiikTr
@sethherr
sethherr merged commit 3109b45 into main Aug 5, 2026
4 checks passed
@sethherr
sethherr deleted the compare branch August 5, 2026 15:19
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.

1 participant