fix: return appropriate HTTP status codes in webhook responses#2086
Open
kaigritun wants to merge 1 commit intotelegraf:v4from
Open
fix: return appropriate HTTP status codes in webhook responses#2086kaigritun wants to merge 1 commit intotelegraf:v4from
kaigritun wants to merge 1 commit intotelegraf:v4from
Conversation
- Return 405 Method Not Allowed for non-POST requests - Return 404 Not Found for webhook path mismatches - Return 403 Forbidden for secret token mismatches (unchanged) Previously all rejection scenarios returned 403, which confused clients into thinking there was an authentication issue when the problem was actually a method or path mismatch. Fixes telegraf#2065
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes #2065 by returning appropriate HTTP status codes when webhook requests are rejected:
Previously, all rejection scenarios returned 403 Forbidden, which confused clients into thinking there was an authentication issue when the problem was actually a method or path mismatch.
Changes
src/core/network/webhook.ts: Added optionalWebhookOptionsparameter withpathproperty. The defaultnextcallback now determines the appropriate status code based on:src/telegraf.ts: UpdatedwebhookCallback()to pass the expected path togenerateCallback.test/telegraf.js: Added three test cases to verify the new status code behavior.Backward Compatibility
This change is backward compatible:
WebhookOptionsparameter is optionalwebhookFilterimplementations still work (they return boolean as before)Testing
All existing tests pass, plus 3 new tests for the status code behavior:
webhookCallback should return 405 for non-POST requestswebhookCallback should return 404 for path mismatchwebhookCallback should return 403 for secret token mismatch