Skip to content

Expand the @guildpass/webhook-utils test suite with signature edge cases #256

Description

@Lakes41

Difficulty: Intermediate
Type: Test

Background
packages/webhook-utils implements HMAC-SHA256 signature verification with replay protection via a tolerance window, as documented in its README (verifySignature/generateSignature, t=<timestamp>,v1=<hmac> format). The package advertises timing-attack resistance and replay protection as headline features, which means its edge-case behavior deserves thorough test coverage.

Problem
The documented behaviors — tolerance: 0 disabling timestamp checks, malformed signature headers, missing v1= or t= segments, non-numeric timestamps, and clock-skew scenarios (timestamp slightly in the future) — are the kind of edge cases most likely to be under-tested, since the README frames them as "not recommended for production" or troubleshooting notes rather than guaranteed, tested behavior.

Expected outcome
A comprehensive test file covering: valid signature acceptance, invalid HMAC rejection, expired timestamp rejection (outside tolerance), future-timestamp handling, tolerance: 0 behavior, malformed header formats (missing t=, missing v1=, extra segments, empty string), and confirmation that verification timing does not vary meaningfully between a correct-length-wrong-value signature and a valid one (timing-safety smoke test).

Suggested implementation

  • Add test cases to the existing webhook-utils test suite (run via pnpm test:webhook-utils).
  • Use generateSignature to construct valid signatures, then deliberately corrupt/truncate/rearrange them for negative test cases.
  • For the timing-safety check, this can be a best-effort smoke test (e.g. asserting the library uses a constant-time comparison function internally) rather than a precise timing measurement, since timing tests are inherently flaky in CI-like environments.

Acceptance criteria

  • New tests exist for: valid signature, wrong secret, expired timestamp, future timestamp, tolerance: 0, and at least three malformed-header shapes.
  • All new and existing tests pass via pnpm test:webhook-utils.
  • Test names clearly describe the scenario under test.
  • No changes to the public API of verifySignature/generateSignature are required — this is test-only unless a bug is discovered, in which case it should be filed as a separate issue.

Likely affected files/directories
packages/webhook-utils/ (test directory/file alongside the source), packages/webhook-utils/README.md (only if a documented behavior turns out to be inaccurate and needs a correction note).

Metadata

Metadata

Assignees

Labels

GrantFox OSSGrantFox Open Source Sponsorship program tagMaybe RewardedIssue may qualify for a reward upon successful completion per campaign rulesOfficial Campaign | FWC26Official FWC26 campaign issue — eligible for campaign scoring and rewardsgood first issueGood for newcomerssecuritySecurity-related fix, hardening, audit, or vulnerability remediationtestTest coverage additions, test fixes, or test infrastructure work

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions