Skip to content

test(security): add webhook auth and token management tests#499

Open
marcoscaceres wants to merge 5 commits intomainfrom
test/security
Open

test(security): add webhook auth and token management tests#499
marcoscaceres wants to merge 5 commits intomainfrom
test/security

Conversation

@marcoscaceres
Copy link
Copy Markdown
Collaborator

@marcoscaceres marcoscaceres commented Apr 25, 2026

Summary

  • 11 specs for HMAC webhook signature verification (valid sig, invalid sig, missing header, tampered body, wrong secret, empty sig, wrong-length sig, non-ASCII sig, ping events)
  • 11 specs for GitHub token masking and cycling (getToken, updateRateLimit, getLimits masking/length/prefix/exposure)
  • Fixed timing-attack vulnerability in webhook auth (=== → timingSafeEqual with Buffer length check)
  • Fixed token leakage in secureToken() (leaked first 10 chars → now masks all but last 4)
  • Avoided GH_TOKEN leakage in Jasmine failure diffs (Copilot fix)

Closes #384

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR strengthens security around GitHub integrations by hardening webhook signature verification and improving GitHub token masking, with new Jasmine specs to lock in the behavior.

Changes:

  • Updated webhook signature validation to use crypto.timingSafeEqual() instead of === for comparison.
  • Updated token masking in getLimits() to hide all but the last 4 characters.
  • Added new Jasmine test suites covering webhook auth and token masking/rate-limit storage behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
utils/auth-github-webhook.ts Switches signature comparison to timingSafeEqual() and adds basic header/length checks.
tests/utils/auth-github-webhook.test.js Adds webhook authenticator/verifier tests covering valid/invalid signatures and ping handling.
routes/github/lib/utils/tokens.ts Changes token masking logic used by getLimits() to avoid leaking token prefixes.
tests/routes/github/lib/utils/tokens.test.js Adds tests for getToken(), updateRateLimit(), and token masking behavior in getLimits().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/routes/github/lib/utils/tokens.test.js
Comment thread utils/auth-github-webhook.ts Outdated
Comment thread routes/github/lib/utils/tokens.ts Outdated
Comment thread tests/routes/github/lib/utils/tokens.test.js Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds automated test coverage for GitHub webhook HMAC authentication and GitHub token masking, while hardening signature verification to mitigate timing attacks and reducing token leakage in rate-limit reporting.

Changes:

  • Update webhook signature verification to use timingSafeEqual instead of ===.
  • Add Jasmine specs covering webhook verification behavior (valid/invalid/missing signatures and ping events).
  • Fix token masking in getLimits() to hide all but the last 4 characters, and add specs validating non-leakage.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
utils/auth-github-webhook.ts Switches webhook signature comparison to a constant-time primitive.
routes/github/lib/utils/tokens.ts Updates token masking logic to avoid leaking token prefixes.
tests/utils/auth-github-webhook.test.js Adds webhook authenticator and verifier behavior tests.
tests/routes/github/lib/utils/tokens.test.js Adds tests for token retrieval, rate-limit storage, and masking behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread utils/auth-github-webhook.ts Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR strengthens webhook authentication and GitHub token handling by adding targeted security-focused tests and hardening comparisons/masking to avoid timing attacks and token leakage.

Changes:

  • Switch GitHub webhook signature verification to a constant-time comparison (timingSafeEqual) and add comprehensive verifier middleware specs.
  • Fix token masking in getLimits() to avoid leaking token prefixes and add tests covering masking/rotation/rate-limit updates.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
utils/auth-github-webhook.ts Uses timingSafeEqual for signature verification and adds missing-header handling.
tests/utils/auth-github-webhook.test.js Adds a new test suite covering webhook verifier behavior and failure modes.
routes/github/lib/utils/tokens.ts Updates token masking to hide all but the last 4 characters (or fully mask short tokens).
tests/routes/github/lib/utils/tokens.test.js Adds tests for token retrieval, rate-limit tracking, and masked-key behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread utils/auth-github-webhook.ts Outdated
Comment thread tests/routes/github/lib/utils/tokens.test.js Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens GitHub-related security utilities by making webhook signature verification constant-time and by ensuring GitHub tokens are properly masked when surfaced via rate-limit reporting, with accompanying Jasmine specs.

Changes:

  • Use crypto.timingSafeEqual() for GitHub webhook HMAC signature comparisons.
  • Add a new test suite covering webhook authentication behavior and edge cases.
  • Fix token masking in getLimits() to avoid leaking token prefixes, with tests for masking/cycling and rate-limit updates.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
utils/auth-github-webhook.ts Switches signature check to constant-time comparison and adds basic header presence/length guards.
tests/utils/auth-github-webhook.test.js Adds webhook authenticator specs (valid/invalid signature, ping handling, tampering, missing header).
routes/github/lib/utils/tokens.ts Updates token masking logic to hide all but the last 4 characters (or all for very short tokens).
tests/routes/github/lib/utils/tokens.test.js Adds specs for token cycling, rate-limit storage, and masking guarantees (no full token/prefix exposure).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread utils/auth-github-webhook.ts Outdated
Comment thread tests/utils/auth-github-webhook.test.js
Comment thread tests/routes/github/lib/utils/tokens.test.js Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR strengthens security around GitHub webhook authentication and GitHub token handling, and adds regression tests to cover signature verification and token masking/rate-limit bookkeeping.

Changes:

  • Use constant-time comparison (timingSafeEqual) for webhook HMAC signature verification.
  • Add a dedicated test suite covering webhook signature verification behavior (valid/invalid/missing signatures and ping events).
  • Fix token masking in getLimits() to avoid leaking token prefixes and add tests for masking + rate-limit storage.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
utils/auth-github-webhook.ts Replaces === signature check with timingSafeEqual for webhook auth.
tests/utils/auth-github-webhook.test.js Adds webhook authenticator specs (signature validity, tampering, missing header, ping).
routes/github/lib/utils/tokens.ts Updates secureToken() masking logic to hide everything except the last 4 chars.
tests/routes/github/lib/utils/tokens.test.js Adds specs for token retrieval/rotation, rate-limit updates, and masking guarantees.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread utils/auth-github-webhook.ts Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds test coverage for GitHub webhook authentication and GitHub token masking/rate-limit bookkeeping, alongside security hardening of signature comparison and token redaction behavior.

Changes:

  • Switch webhook signature verification from === to timingSafeEqual to reduce timing-attack risk.
  • Add a new Jasmine suite covering webhook signature verification outcomes (valid/invalid/missing/tampered/ping).
  • Update token masking in getLimits() to avoid leaking token prefixes; add tests for masking and rate-limit storage.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
utils/auth-github-webhook.ts Harden signature comparison using constant-time equality.
tests/utils/auth-github-webhook.test.js Add webhook authenticator verification tests using request/response mocks.
routes/github/lib/utils/tokens.ts Fix token masking to reveal at most the last 4 characters.
tests/routes/github/lib/utils/tokens.test.js Add tests for token retrieval/rotation, rate-limit updates, and masking properties.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread utils/auth-github-webhook.ts Outdated
@marcoscaceres marcoscaceres requested a review from Copilot April 26, 2026 04:33
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR strengthens GitHub integration security by hardening webhook signature verification against timing attacks and improving GitHub token masking, with new Jasmine specs to validate both behaviors.

Changes:

  • Replace === signature comparison with timingSafeEqual in GitHub webhook authentication.
  • Update token masking to hide everything except the last 4 characters.
  • Add new test suites covering webhook auth behavior and token masking/rate-limit tracking.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
utils/auth-github-webhook.ts Uses timingSafeEqual for webhook signature verification.
tests/utils/auth-github-webhook.test.js Adds specs for webhook signature validation and ping handling.
routes/github/lib/utils/tokens.ts Fixes token masking to avoid leaking token prefixes.
tests/routes/github/lib/utils/tokens.test.js Adds specs for token cycling, rate-limit storage, and masking guarantees.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread utils/auth-github-webhook.ts Outdated
Comment thread tests/routes/github/lib/utils/tokens.test.js
@marcoscaceres marcoscaceres requested a review from Copilot April 27, 2026 00:11
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR strengthens security around GitHub integrations by hardening webhook signature verification against timing attacks and by preventing GitHub token prefix leakage when exposing rate-limit state.

Changes:

  • Replace direct string comparison of webhook signatures with timingSafeEqual in isValidGithubSignature().
  • Add a new Jasmine test suite covering webhook verifier behaviors (valid/invalid/missing signature, ping event, tampered body, etc.).
  • Fix token masking in getLimits() to reveal at most the last 4 characters (and add tests validating masking behavior).

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
utils/auth-github-webhook.ts Switches signature comparison to constant-time comparison.
tests/utils/auth-github-webhook.test.js Adds webhook authentication/verifier tests.
routes/github/lib/utils/tokens.ts Fixes token masking to avoid leaking token prefix.
tests/routes/github/lib/utils/tokens.test.js Adds tests for token retrieval, rate-limit updates, and masking behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread utils/auth-github-webhook.ts Outdated
Comment thread utils/auth-github-webhook.ts Outdated
Comment thread tests/routes/github/lib/utils/tokens.test.js Outdated
Add comprehensive test suites for two security-critical modules:

- utils/auth-github-webhook: 8 tests covering valid HMAC verification,
  invalid/missing/empty signatures, body tampering, and wrong secrets.
- routes/github/lib/utils/tokens: 9 tests covering token cycling, rate
  limit tracking, and token masking in getLimits() output.

Fix two security issues discovered during testing:

1. Webhook signature comparison used === (timing-attack vulnerable).
   Now uses crypto.timingSafeEqual() with explicit length check and
   early return for missing headers.

2. Token masking in getLimits() replaced only the last 30 chars with 2
   asterisks, leaking up to 10 prefix characters of a 40-char GitHub
   token. Now masks all but the last 4 characters with per-character
   asterisks, preserving output length.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR strengthens GitHub-related security behavior and adds regression tests to ensure webhook HMAC verification is constant-time and GitHub token masking no longer leaks sensitive prefixes.

Changes:

  • Updated GitHub webhook signature verification to use timingSafeEqual with explicit length checks.
  • Added a new webhook authenticator test suite covering valid/invalid/missing/tampered signatures and ping handling.
  • Updated token masking in getLimits() and added tests to ensure only the last 4 characters are ever exposed.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
utils/auth-github-webhook.ts Replaces === signature comparison with timingSafeEqual and length checks for safer HMAC verification.
tests/utils/auth-github-webhook.test.js Adds comprehensive unit tests for the webhook authenticator middleware behavior.
routes/github/lib/utils/tokens.ts Fixes token masking to hide all but the last 4 characters (or fully mask very short tokens).
tests/routes/github/lib/utils/tokens.test.js Adds tests verifying token retrieval, rate limit storage, and strict masking/no-prefix leakage.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/utils/auth-github-webhook.test.js Outdated
…tokens

Fix non-ASCII signature test to pass { body, headers } object
instead of positional args. Add explicit test for wrong-length
X-Hub-Signature. Guard masking test against GH_TOKEN shorter
than 4 characters.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR strengthens GitHub integration security by making webhook signature verification resistant to timing attacks and ensuring GitHub tokens are properly masked, with new Jasmine specs covering both areas.

Changes:

  • Use timingSafeEqual for webhook HMAC signature comparison instead of ===.
  • Fix token masking in getLimits() to avoid leaking token prefixes (mask all but last 4 chars).
  • Add new test suites for webhook auth behavior and GitHub token masking/rate-limit tracking.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
utils/auth-github-webhook.ts Switches signature comparison to timingSafeEqual with length guarding.
routes/github/lib/utils/tokens.ts Updates secureToken() masking logic to prevent token-prefix leakage.
tests/utils/auth-github-webhook.test.js Adds webhook signature verification test coverage (valid/invalid/missing/tampered/ping, etc.).
tests/routes/github/lib/utils/tokens.test.js Adds tests for token retrieval, rate limit updates, and masking guarantees.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/utils/auth-github-webhook.test.js
Comment thread tests/routes/github/lib/utils/tokens.test.js
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@marcoscaceres
Copy link
Copy Markdown
Collaborator Author

@copilot please resolve and fix any unaddressed comment

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 27, 2026

@copilot please resolve and fix any unaddressed comment

Done in 553b29d. Addressed the two remaining unresolved threads:

  1. Token leakage in test assertions (tokens.test.js:20-23 and tokens.test.js:84-89): Replaced expect(token).toBe(process.env.GH_TOKEN) with a type + length check (so a failure diff won't print the raw secret), and replaced expect(key).not.toBe(fullToken) with expect(key).toContain("*") (same benefit).

  2. Spec count in PR description: Updated to reflect the actual 11 specs per suite (was incorrectly listed as 8 and 9).

All 62 tests still pass.

@marcoscaceres
Copy link
Copy Markdown
Collaborator Author

@copilot Can you review this and fix any issues that come up?

@marcoscaceres marcoscaceres marked this pull request as ready for review May 5, 2026 14:03
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.

3 participants