Summary
A broken authentication check in pytonapi's TonapiWebhookDispatcher lets custom webhook endpoints skip Authorization header validation.
If a webhook handler is registered with a documented custom path, bearer tokens are never associated with that path, so unauthenticated remote attackers can POST forged payloads to victim-defined handlers.
A broken authentication check in pytonapi's TonapiWebhookDispatcher lets custom webhook endpoints skip Authorization header validation.
If a webhook handler is registered with a documented custom path, bearer tokens are never associated with that path, so unauthenticated remote attackers can POST forged payloads to victim-defined handlers.
Affected context
This vulnerability affects applications that use pytonapi versions 2.0.0 through 2.2.0 and register webhook handlers with a non-default, documented path argument on TonapiWebhookDispatcher.
Under these conditions, the dispatcher's setup() logic stores bearer tokens only for default suffix paths and omits the custom path from its internal token map.
As a result, requests targeting the custom webhook route are treated as if no authentication were configured, even though the application developer may assume bearer token protection is in place.
This vulnerability affects applications that use pytonapi versions 2.0.0 through 2.2.0 and register webhook handlers with a non-default, documented path argument on TonapiWebhookDispatcher.
Under these conditions, the dispatcher's setup() logic stores bearer tokens only for default suffix paths and omits the custom path from its internal token map.
As a result, requests targeting the custom webhook route are treated as if no authentication were configured, even though the application developer may assume bearer token protection is in place.
Exploit preconditions
- Attack surface: Publicly reachable HTTP endpoint exposed by TonapiWebhookDispatcher for webhook delivery
- Required access: Network access to the webhook URL; no valid Authorization token is required for the vulnerable custom paths
- Trigger point: HTTP POST (or relevant method) to the registered custom webhook path with arbitrary payload data
- Why exploitation is possible: The dispatcher only associates bearer tokens with default suffix paths; for handlers registered using the documented
pathargument,self._tokens.get(path)returnsNone, causing the authentication guard to be bypassed and requests to be processed as authenticated.
- Attack surface: Publicly reachable HTTP endpoint exposed by TonapiWebhookDispatcher for webhook delivery
- Required access: Network access to the webhook URL; no valid Authorization token is required for the vulnerable custom paths
- Trigger point: HTTP POST (or relevant method) to the registered custom webhook path with arbitrary payload data
- Why exploitation is possible: The dispatcher only associates bearer tokens with default suffix paths; for handlers registered using the documented
pathargument,self._tokens.get(path)returnsNone, causing the authentication guard to be bypassed and requests to be processed as authenticated.
Why this happens
The core issue is a logic flaw in the authentication mapping within TonapiWebhookDispatcher.
The setup() routine records bearer tokens only for a fixed set of default webhook paths, but does not add entries for user-specified paths supplied via the documented path argument.
When a request arrives, the dispatcher checks the Authorization header only if it finds a token configured for that path; for custom paths, the lookup returns None, so the guard is effectively disabled.
This pattern maps to CWE-287: Improper Authentication, where a component fails to correctly enforce authentication controls on all relevant code paths, leading to assumptions of protection that are not actually enforced.
The core issue is a logic flaw in the authentication mapping within TonapiWebhookDispatcher.
The setup() routine records bearer tokens only for a fixed set of default webhook paths, but does not add entries for user-specified paths supplied via the documented path argument.
When a request arrives, the dispatcher checks the Authorization header only if it finds a token configured for that path; for custom paths, the lookup returns None, so the guard is effectively disabled.
This pattern maps to CWE-287: Improper Authentication, where a component fails to correctly enforce authentication controls on all relevant code paths, leading to assumptions of protection that are not actually enforced.
Potential impact
- Remote attackers could invoke victim-defined webhook handlers without providing any credentials.
- Application workflows relying on authenticated webhooks may be spoofed or manipulated.
- Downstream systems that trust webhook content could be fed forged or malicious data.
- Business logic triggered by webhooks (e.g., transactions, notifications, or account changes) could be executed under false pretenses.
- Remote attackers could invoke victim-defined webhook handlers without providing any credentials.
- Application workflows relying on authenticated webhooks may be spoofed or manipulated.
- Downstream systems that trust webhook content could be fed forged or malicious data.
- Business logic triggered by webhooks (e.g., transactions, notifications, or account changes) could be executed under false pretenses.
General mitigation guidance
Effective mitigation focuses on ensuring that authentication is consistently applied to all webhook endpoints and that path-based routing does not implicitly skip security checks.
Common defensive patterns include:
- Centralizing authentication logic so that all routes, including custom webhook paths, are protected uniformly rather than relying on per-path token maps.
- Treating "no configured token for this path" as a security failure that results in request rejection, rather than silently skipping authentication.
- Using explicit configuration or declarative security policies to bind authentication requirements to paths, handlers, or route groups.
- Applying the principle of least privilege to webhook handlers so that any single endpoint has limited capability if misused.
- Documenting and reviewing all externally exposed webhook URLs, avoiding assumptions that a "registered handler" is automatically authenticated.
Effective mitigation focuses on ensuring that authentication is consistently applied to all webhook endpoints and that path-based routing does not implicitly skip security checks.
Common defensive patterns include:
- Centralizing authentication logic so that all routes, including custom webhook paths, are protected uniformly rather than relying on per-path token maps.
- Treating "no configured token for this path" as a security failure that results in request rejection, rather than silently skipping authentication.
- Using explicit configuration or declarative security policies to bind authentication requirements to paths, handlers, or route groups.
- Applying the principle of least privilege to webhook handlers so that any single endpoint has limited capability if misused.
- Documenting and reviewing all externally exposed webhook URLs, avoiding assumptions that a "registered handler" is automatically authenticated.
How teams detect issues like this
Identifying this type of issue generally involves a combination of code analysis and behavioral testing:
- Static analysis / code review: Look for authentication structures that use path-to-token maps or conditional checks where a missing token results in authentication being skipped instead of failing closed.
- Configuration review: Inspect webhook registration points to confirm that custom
patharguments are tied to concrete authentication rules, and verify that default paths and custom paths follow the same security model. - Dynamic testing: Use integration or security tests to send unauthenticated requests to all registered webhook endpoints and confirm that they are rejected when authentication is expected.
- Automated tooling: Employ API security testing, fuzzing, and CI checks that enumerate routes and validate the presence of authentication guards, especially on webhook and callback endpoints.
Identifying this type of issue generally involves a combination of code analysis and behavioral testing:
- Static analysis / code review: Look for authentication structures that use path-to-token maps or conditional checks where a missing token results in authentication being skipped instead of failing closed.
- Configuration review: Inspect webhook registration points to confirm that custom
patharguments are tied to concrete authentication rules, and verify that default paths and custom paths follow the same security model. - Dynamic testing: Use integration or security tests to send unauthenticated requests to all registered webhook endpoints and confirm that they are rejected when authentication is expected.
- Automated tooling: Employ API security testing, fuzzing, and CI checks that enumerate routes and validate the presence of authentication guards, especially on webhook and callback endpoints.

