Skip to content

fix: use constant-time comparison for webhook HMAC signatures - #360

Merged
Justin Hammond (Justintime50) merged 3 commits into
masterfrom
secure_compare
Dec 4, 2026
Merged

Justin Hammond (Justintime50) merged 3 commits into
masterfrom
secure_compare

Conversation

@Justintime50

@Justintime50 Justin Hammond (Justintime50) commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

Description

validate_webhook compared signatures with ==, which can leak timing information. It now uses a private secure_compare helper that calls OpenSSL.secure_compare, or falls back to a constant-time byte compare on Ruby 2.7, whose bundled openssl (2.1.x) doesn't have it. A TODO: marks the fallback for removal once we only support Ruby 3.0+.

The other six libs already use constant-time compares. Bumps the version to 7.8.3 with a dated changelog header.

Closes #359

Testing

  • just lint passes, and the full spec suite passes (212 examples, 0 failures).
  • Adds a spec for a same-length, one-character signature mismatch on the Ruby 2.7 fallback, with a TODO: to remove it along with the fallback. Ruby 2.7 isn't installed locally, so CI's 2.7 job covers the fallback natively.

Pull Request Type

  • Bug fix (non-breaking change which fixes an issue)

validate_webhook compared the computed and provided signatures with ==, which can leak timing information. Use OpenSSL.secure_compare, with a constant-time byte fallback for Ruby 2.7, whose bundled openssl does not have it.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The Ruby 2.7 compatibility path lacks a same-length mismatch test, leaving regressions in its bytewise XOR comparison undetected.

1 open issue
What changed in this PR

Updates webhook HMAC validation to use constant-time signature comparison, including Ruby 2.7 compatibility, and releases version 7.8.3.

Changes:

  • Added secure comparison with a constant-time fallback.
  • Updated version and changelog entries.
File Description
VERSION Bumps the library version to 7.8.3.
lib/​easypost/​util.rb Secures webhook signature validation.
CHANGELOG.md Documents the security fix.

Review effort: Lite

Comment thread lib/easypost/util.rb Resolved
@Justintime50
Justin Hammond (Justintime50) merged commit 328b9be into master Dec 4, 2026
12 checks passed
@Justintime50
Justin Hammond (Justintime50) deleted the secure_compare branch December 4, 2026 18:17
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.

HMAC verification should use constant-time comparison

3 participants