Skip to content

fix: use consistent URL validation pattern in IncomingWebhook - #2725

Open
dajiaohuang wants to merge 3 commits into
slackapi:mainfrom
dajiaohuang:fix/incoming-webhook-url-validation
Open

fix: use consistent URL validation pattern in IncomingWebhook#2725
dajiaohuang wants to merge 3 commits into
slackapi:mainfrom
dajiaohuang:fix/incoming-webhook-url-validation

Conversation

@dajiaohuang

Copy link
Copy Markdown

Summary

The URL validation in IncomingWebhook used if (url === undefined) which only catches undefined values. Meanwhile, WebhookTrigger in the same package uses the more robust if (!url) which catches undefined, null, and empty string.

Problem

At line 74 in IncomingWebhook.ts:

if (url === undefined) {
  throw new Error('Incoming webhook URL is required');
}

This check would not catch null or empty string "" values.

Fix

Changed to use the same pattern as WebhookTrigger.ts:

if (!url) {
  throw new Error('Incoming webhook URL is required');
}

This ensures consistent validation across the webhook package and catches all falsy values.

Testing

  • Run existing tests: npm test --workspace=packages/webhook

…ponse

The JSON.parse at line 802 was not wrapped in a try-catch, which could
cause an unhandled exception if the response body is not valid JSON.
This is inconsistent with the similar operation at line 811 which is
properly wrapped.

Added try-catch to handle parse failures gracefully, returning
{ ok: false, error: <error message> } instead of throwing.
Before this fix, the code assumed `e` is an Error object and accessed
`e.message` directly. If `e` was a primitive value or undefined,
this could result in undefined being passed to GenerateInstallUrlError.

Now we use the same pattern as line 289 in this file:
`e instanceof Error ? e.message : String(e)`

This ensures a valid string is always passed to GenerateInstallUrlError.
The URL validation in IncomingWebhook used `if (url === undefined)`
which only catches undefined values. WebhookTrigger.ts uses the more
robust `if (!url)` which catches undefined, null, and empty string.

For consistency and better validation, updated IncomingWebhook to use
the same pattern as WebhookTrigger.ts.
@dajiaohuang
dajiaohuang requested a review from a team as a code owner September 2, 2026 10:07
@changeset-bot

changeset-bot Bot commented Sep 2, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: f49dc74

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@salesforce-cla

salesforce-cla Bot commented Sep 2, 2026

Copy link
Copy Markdown

Thanks for the contribution! Before we can merge this, we need @dajiaohuang to sign the Salesforce Inc. Contributor License Agreement.

@zimeg

zimeg commented Sep 2, 2026

Copy link
Copy Markdown
Member

👋 Hey @dajiaohuang! Before we review this PR I'm wondering if it'd be possible to sign the CLA above? 🏛️ ✨

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants