Skip to content

feat(backend): Add event_attributes to Webhook type #6162

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jaredpiedt
Copy link

@jaredpiedt jaredpiedt commented Jun 19, 2025

Description

This adds the event_attributes property to webhook events.

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Summary by CodeRabbit

  • New Features
    • Webhook events now include additional information about the originating HTTP request, such as client IP and user agent, providing more context for each event.

Copy link

changeset-bot bot commented Jun 19, 2025

🦋 Changeset detected

Latest commit: cd2ea92

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 11 packages
Name Type
@clerk/backend Patch
@clerk/agent-toolkit Patch
@clerk/astro Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/nextjs Patch
@clerk/nuxt Patch
@clerk/react-router Patch
@clerk/remix Patch
@clerk/tanstack-react-start Patch
@clerk/testing Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Jun 19, 2025

@jaredpiedt is attempting to deploy a commit to the Clerk Production Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Jun 19, 2025

📝 Walkthrough

Walkthrough

The changes introduce a new field, event_attributes, to the Webhook entity within the @clerk/backend package. The Webhook type is updated to include this property, which contains HTTP request metadata such as client_ip and user_agent, structured under an http_request object. The verifyWebhook function is modified to include the event_attributes from the webhook payload in its returned event object. No other logic or public API signatures are altered, and the update is categorized as a patch.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🔭 Outside diff range comments (1)
packages/backend/src/webhooks.ts (1)

83-85: Critical: Fix inverted signature verification logic.

The signature verification logic is inverted. Currently, it throws an error when the constructed signature IS found in the svix signature list, which means it rejects valid signatures and accepts invalid ones. This is a critical security vulnerability.

Apply this fix:

-  if (svixSignature.split(' ').includes(constructedSignature)) {
+  if (!svixSignature.split(' ').includes(constructedSignature)) {
     return errorThrower.throw('Incoming webhook does not have a valid signature');
   }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 545999c and cd2ea92.

📒 Files selected for processing (3)
  • .changeset/sixty-regions-camp.md (1 hunks)
  • packages/backend/src/api/resources/Webhooks.ts (1 hunks)
  • packages/backend/src/webhooks.ts (1 hunks)
🔇 Additional comments (3)
packages/backend/src/api/resources/Webhooks.ts (2)

16-21: Well-structured type definition for HTTP request metadata.

The WebhookEventAttributes type properly encapsulates HTTP request information with appropriate nesting under http_request.


23-23: Verify backward compatibility for required event_attributes property.

Adding event_attributes as a required property to the Webhook type could be a breaking change if existing webhook payloads don't include this field. Consider making it optional initially or ensure all webhook sources provide this field.

#!/bin/bash
# Description: Search for existing Webhook type usage to assess potential breaking changes
# Expected: Find usages that might be affected by the new required property

echo "Searching for Webhook type usage patterns..."
rg -A 3 -B 3 "Webhook<" --type ts

echo -e "\nSearching for webhook payload parsing..."
rg -A 5 -B 5 "JSON\.parse.*payload|payload.*JSON\.parse" --type ts

echo -e "\nSearching for webhook event creation/construction..."
rg -A 5 -B 5 "type.*event.*object.*data" --type ts
.changeset/sixty-regions-camp.md (1)

1-6: Changeset documentation looks good.

The changeset correctly documents this as a patch-level change with a clear description.

@@ -90,5 +90,6 @@ export async function verifyWebhook(request: Request, options: VerifyWebhookOpti
type: payload.type,
object: 'event',
data: payload.data,
event_attributes: payload.event_attributes,
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add null safety for event_attributes extraction.

The code assumes payload.event_attributes exists, but it should handle cases where this property might be missing from older webhook payloads to maintain backward compatibility.

Apply this diff to add null safety:

-    event_attributes: payload.event_attributes,
+    event_attributes: payload.event_attributes || { http_request: { client_ip: '', user_agent: '' } },

Or make the property optional in the type definition if it's acceptable for it to be undefined.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
event_attributes: payload.event_attributes,
event_attributes: payload.event_attributes || { http_request: { client_ip: '', user_agent: '' } },
🤖 Prompt for AI Agents
In packages/backend/src/webhooks.ts at line 93, the code accesses
payload.event_attributes without checking if it exists, which can cause errors
with older webhook payloads. To fix this, add a null check or use optional
chaining when extracting event_attributes to safely handle cases where it might
be undefined. Alternatively, update the type definition to make event_attributes
optional if that aligns with the expected data structure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants