Skip to content

Commit 30311df

Browse files
committed
fix(webhooks): return 401 when requireAuth is true but no token configured
If a user explicitly sets requireAuth: true, they expect auth to be enforced. Returning 401 when no token is configured is the correct behavior — this is an intentional improvement over the original code which silently allowed unauthenticated access in this case.
1 parent d6ab7ca commit 30311df

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

apps/sim/lib/webhooks/providers/generic.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@ export const genericHandler: WebhookProviderHandler = {
1414
verifyAuth({ request, requestId, providerConfig }: AuthContext) {
1515
if (providerConfig.requireAuth) {
1616
const configToken = providerConfig.token as string | undefined
17-
if (configToken) {
18-
const secretHeaderName = providerConfig.secretHeaderName as string | undefined
19-
if (!verifyTokenAuth(request, configToken, secretHeaderName)) {
20-
return new NextResponse('Unauthorized - Invalid authentication token', { status: 401 })
21-
}
17+
if (!configToken) {
18+
return new NextResponse('Unauthorized - Authentication required but no token configured', {
19+
status: 401,
20+
})
21+
}
22+
23+
const secretHeaderName = providerConfig.secretHeaderName as string | undefined
24+
if (!verifyTokenAuth(request, configToken, secretHeaderName)) {
25+
return new NextResponse('Unauthorized - Invalid authentication token', { status: 401 })
2226
}
2327
}
2428

0 commit comments

Comments
 (0)