tai42-webhook-verifier-github 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tai42_webhook_verifier_github-0.1.0/LICENSE +202 -0
- tai42_webhook_verifier_github-0.1.0/MANIFEST.in +1 -0
- tai42_webhook_verifier_github-0.1.0/NOTICE +5 -0
- tai42_webhook_verifier_github-0.1.0/PKG-INFO +196 -0
- tai42_webhook_verifier_github-0.1.0/README.md +171 -0
- tai42_webhook_verifier_github-0.1.0/pyproject.toml +95 -0
- tai42_webhook_verifier_github-0.1.0/setup.cfg +4 -0
- tai42_webhook_verifier_github-0.1.0/src/tai42_webhook_verifier_github/__init__.py +19 -0
- tai42_webhook_verifier_github-0.1.0/src/tai42_webhook_verifier_github/py.typed +0 -0
- tai42_webhook_verifier_github-0.1.0/src/tai42_webhook_verifier_github/tai-plugin.yml +22 -0
- tai42_webhook_verifier_github-0.1.0/src/tai42_webhook_verifier_github/verifier.py +87 -0
- tai42_webhook_verifier_github-0.1.0/src/tai42_webhook_verifier_github.egg-info/PKG-INFO +196 -0
- tai42_webhook_verifier_github-0.1.0/src/tai42_webhook_verifier_github.egg-info/SOURCES.txt +14 -0
- tai42_webhook_verifier_github-0.1.0/src/tai42_webhook_verifier_github.egg-info/dependency_links.txt +1 -0
- tai42_webhook_verifier_github-0.1.0/src/tai42_webhook_verifier_github.egg-info/requires.txt +1 -0
- tai42_webhook_verifier_github-0.1.0/src/tai42_webhook_verifier_github.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
prune tests
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tai42-webhook-verifier-github
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: GitHub webhook-signature verifier plugin for the TAI ecosystem: a per-provider WebhookVerifier that checks each delivery's X-Hub-Signature-256 HMAC before the payload is dispatched.
|
|
5
|
+
Author-email: tai42 <oss@tai42.ai>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://tai42.ai
|
|
8
|
+
Project-URL: Repository, https://github.com/tai42ai/tai-webhook-verifier-github
|
|
9
|
+
Project-URL: Issues, https://github.com/tai42ai/tai-webhook-verifier-github/issues
|
|
10
|
+
Project-URL: Changelog, https://github.com/tai42ai/tai-webhook-verifier-github/blob/main/CHANGELOG.md
|
|
11
|
+
Keywords: tai,webhook,verifier,github,hmac,signature,security
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Topic :: Security
|
|
18
|
+
Classifier: Typing :: Typed
|
|
19
|
+
Requires-Python: >=3.13
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
License-File: NOTICE
|
|
23
|
+
Requires-Dist: tai42-contract<0.2,>=0.1
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
|
|
26
|
+
# tai42-webhook-verifier-github
|
|
27
|
+
|
|
28
|
+
[](https://github.com/tai42ai/tai-webhook-verifier-github/actions/workflows/ci.yml)
|
|
29
|
+
[](LICENSE)
|
|
30
|
+
|
|
31
|
+
The GitHub webhook-signature verifier plugin for the TAI ecosystem — a
|
|
32
|
+
per-provider `WebhookVerifier` that authenticates each inbound GitHub delivery
|
|
33
|
+
before the platform parses or dispatches its payload.
|
|
34
|
+
|
|
35
|
+
> A webhook door can bind a named verifier to a topic; this plugin supplies the
|
|
36
|
+
> `github` verifier.
|
|
37
|
+
|
|
38
|
+
GitHub signs every webhook delivery with an HMAC-SHA256 over the **exact raw
|
|
39
|
+
request body**, keyed by the shared secret, and sends it in the
|
|
40
|
+
`X-Hub-Signature-256` header as `"sha256=" + hexdigest`. `GitHubWebhookVerifier`
|
|
41
|
+
recomputes that HMAC over the raw bytes and compares it in constant time. It
|
|
42
|
+
returns `None` on success and raises `WebhookVerificationError` on any failure.
|
|
43
|
+
|
|
44
|
+
Its only tai-\* dependency is `tai42-contract` (the interface it registers
|
|
45
|
+
through); the HMAC work is pure standard library (`hmac` / `hashlib`). It
|
|
46
|
+
**never** imports the skeleton — the plugin is contract-facing.
|
|
47
|
+
|
|
48
|
+
## The TAI ecosystem
|
|
49
|
+
|
|
50
|
+
TAI is an open-source runtime for MCP tools, agents, and workflows. A trigger
|
|
51
|
+
fires a tool from an inbound event; a webhook verifier is the door's bouncer —
|
|
52
|
+
the per-provider check that authenticates a delivery before any hook runs. This
|
|
53
|
+
package is the GitHub verifier. The ecosystem is open-ended: any package can
|
|
54
|
+
supply a verifier, so this repo is this verifier's own full doc home, and the
|
|
55
|
+
documentation site covers the platform-level story:
|
|
56
|
+
|
|
57
|
+
- Triggers & webhooks concept: https://tai42.ai/concepts/triggers-and-webhooks
|
|
58
|
+
- Build a webhook verifier (author guide): https://tai42.ai/guides/authors/webhook-verifier
|
|
59
|
+
- Ecosystem catalog: https://tai42.ai/reference/catalog
|
|
60
|
+
|
|
61
|
+
## Install
|
|
62
|
+
|
|
63
|
+
Requires **Python 3.13+**. Nothing is on PyPI yet, so install from source — clone
|
|
64
|
+
this repo alongside your `tai42-skeleton` checkout and add it as an editable
|
|
65
|
+
dependency of the environment that runs the server:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
git clone https://github.com/tai42ai/tai-webhook-verifier-github
|
|
69
|
+
cd tai-skeleton # or your own app checkout
|
|
70
|
+
uv add --editable ../tai-webhook-verifier-github # once published: uv add tai42-webhook-verifier-github
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## How it loads — `lifecycle_modules`
|
|
74
|
+
|
|
75
|
+
The platform loads this plugin through the manifest's **`lifecycle_modules`**
|
|
76
|
+
field. That field is **import-only**: the host simply imports each listed module
|
|
77
|
+
to run its registration side effect. Importing `tai42_webhook_verifier_github`
|
|
78
|
+
calls `tai42_app.webhook_verifiers.register("github", GitHubWebhookVerifier())`,
|
|
79
|
+
binding the `github` verifier on the app handle.
|
|
80
|
+
|
|
81
|
+
```jsonc
|
|
82
|
+
{
|
|
83
|
+
// Import-only modules: loaded purely for their registration side effect.
|
|
84
|
+
// `lifecycle_modules` are imported WITHOUT going through the extension
|
|
85
|
+
// registry's validation — only `extensions_modules` run that. So this entry
|
|
86
|
+
// is a plain registration, not an extension.
|
|
87
|
+
"lifecycle_modules": ["tai42_webhook_verifier_github"]
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
`lifecycle_modules` entries are imported as-is, with no validation step —
|
|
92
|
+
only `extensions_modules` go through the extension registry's validation. This
|
|
93
|
+
entry is therefore a plain registration, not an extension.
|
|
94
|
+
|
|
95
|
+
## Configuration — the secret never leaves the environment
|
|
96
|
+
|
|
97
|
+
A verifier is bound to a topic with `{verifier, config}`. This plugin's `config`
|
|
98
|
+
holds only the **name** of the environment variable that carries the secret —
|
|
99
|
+
never the secret itself:
|
|
100
|
+
|
|
101
|
+
```json
|
|
102
|
+
{ "verifier": "github", "config": { "secret_env": "GITHUB_WEBHOOK_SECRET" } }
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
At verify time the secret is read from `os.environ[config["secret_env"]]`. A
|
|
106
|
+
**missing** env var raises loudly (`KeyError`) and an **empty** one raises
|
|
107
|
+
`ValueError` — verification fails **CLOSED**, so a misconfigured secret never
|
|
108
|
+
becomes a silently-unauthenticated door.
|
|
109
|
+
|
|
110
|
+
> **Secret hygiene.** The secret lives only in an environment variable. Never
|
|
111
|
+
> commit it to a file, a fixture, a manifest, or a URL. The example secret below
|
|
112
|
+
> (`It's a Secret to Everybody`) is GitHub's own published example — it is a
|
|
113
|
+
> placeholder for docs and tests, never a real secret.
|
|
114
|
+
|
|
115
|
+
## End-to-end
|
|
116
|
+
|
|
117
|
+
1. **Create the GitHub webhook.** In your repo → *Settings* → *Webhooks* → *Add
|
|
118
|
+
webhook*, set the *Payload URL* to your platform's public door, e.g.
|
|
119
|
+
`https://<your-host>/universal_webhook/github-events`, *Content type*
|
|
120
|
+
`application/json`, and a **Secret**. Store that same secret in the
|
|
121
|
+
environment as `GITHUB_WEBHOOK_SECRET` on the platform.
|
|
122
|
+
|
|
123
|
+
2. **List `tai42_webhook_verifier_github` in the manifest** under
|
|
124
|
+
`lifecycle_modules` (see above) so the `github` verifier is registered at
|
|
125
|
+
boot.
|
|
126
|
+
|
|
127
|
+
3. **Bind the verifier to the topic.** Through the skeleton's authenticated
|
|
128
|
+
route:
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
curl -X PUT https://<your-host>/api/hooks/topics/github-events/verifier \
|
|
132
|
+
-H "Authorization: Bearer $TAI_API_TOKEN" \
|
|
133
|
+
-H "Content-Type: application/json" \
|
|
134
|
+
-d '{"verifier": "github", "config": {"secret_env": "GITHUB_WEBHOOK_SECRET"}}'
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
4. **Register a hook** on the `github-events` topic that runs a demo tool (e.g. a
|
|
138
|
+
tool that logs the event). Now push to the repo → GitHub signs and POSTs the
|
|
139
|
+
delivery → the door verifies the `X-Hub-Signature-256` HMAC → the hook fires
|
|
140
|
+
and the tool runs. A delivery with a missing, malformed, or wrong signature is
|
|
141
|
+
rejected before any hook runs.
|
|
142
|
+
|
|
143
|
+
### Simulate a signed delivery locally
|
|
144
|
+
|
|
145
|
+
Compute the signature over the exact body with the same secret and POST it — this
|
|
146
|
+
is what a genuine GitHub delivery looks like on the wire:
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
# The secret lives only in the environment — never hard-coded here.
|
|
150
|
+
export GITHUB_WEBHOOK_SECRET="It's a Secret to Everybody" # GitHub's example placeholder
|
|
151
|
+
|
|
152
|
+
BODY='{"zen":"Keep it logically awesome."}'
|
|
153
|
+
SIG="sha256=$(printf '%s' "$BODY" \
|
|
154
|
+
| openssl dgst -sha256 -hmac "$GITHUB_WEBHOOK_SECRET" -r \
|
|
155
|
+
| cut -d ' ' -f1)"
|
|
156
|
+
|
|
157
|
+
curl -X POST http://127.0.0.1:8000/universal_webhook/github-events \
|
|
158
|
+
-H "Content-Type: application/json" \
|
|
159
|
+
-H "X-GitHub-Event: ping" \
|
|
160
|
+
-H "X-Hub-Signature-256: $SIG" \
|
|
161
|
+
--data-raw "$BODY"
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
`printf '%s'` (not `echo`) sends the body with no trailing newline, so the bytes
|
|
165
|
+
signed match the bytes POSTed exactly — the HMAC is over the raw body.
|
|
166
|
+
|
|
167
|
+
## Verification rules
|
|
168
|
+
|
|
169
|
+
`verify(body, headers, config)` is an `async` method — the caller awaits it. It
|
|
170
|
+
raises `WebhookVerificationError` when:
|
|
171
|
+
|
|
172
|
+
- the `X-Hub-Signature-256` header is **missing** (lookup is case-insensitive),
|
|
173
|
+
- the value is not prefixed exactly `sha256=` (e.g. a `sha1=` prefix),
|
|
174
|
+
- the hex after the prefix is not exactly **64** characters (wrong/truncated),
|
|
175
|
+
- the recomputed digest **does not match** (the final compare uses
|
|
176
|
+
`hmac.compare_digest` — constant-time).
|
|
177
|
+
|
|
178
|
+
A missing `secret_env` env var raises `KeyError` and an empty one raises
|
|
179
|
+
`ValueError` (fails closed), not `WebhookVerificationError`.
|
|
180
|
+
|
|
181
|
+
## Development
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
uv sync
|
|
185
|
+
uv run pytest -q
|
|
186
|
+
uv run ruff check .
|
|
187
|
+
uv run ruff format --check .
|
|
188
|
+
uv run pyright
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
`[tool.uv.sources]` resolves `tai42-contract` from a sibling checkout for local
|
|
192
|
+
development; the published wheel floors it from the index.
|
|
193
|
+
|
|
194
|
+
## License
|
|
195
|
+
|
|
196
|
+
Apache-2.0. See `LICENSE` and `NOTICE`.
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
# tai42-webhook-verifier-github
|
|
2
|
+
|
|
3
|
+
[](https://github.com/tai42ai/tai-webhook-verifier-github/actions/workflows/ci.yml)
|
|
4
|
+
[](LICENSE)
|
|
5
|
+
|
|
6
|
+
The GitHub webhook-signature verifier plugin for the TAI ecosystem — a
|
|
7
|
+
per-provider `WebhookVerifier` that authenticates each inbound GitHub delivery
|
|
8
|
+
before the platform parses or dispatches its payload.
|
|
9
|
+
|
|
10
|
+
> A webhook door can bind a named verifier to a topic; this plugin supplies the
|
|
11
|
+
> `github` verifier.
|
|
12
|
+
|
|
13
|
+
GitHub signs every webhook delivery with an HMAC-SHA256 over the **exact raw
|
|
14
|
+
request body**, keyed by the shared secret, and sends it in the
|
|
15
|
+
`X-Hub-Signature-256` header as `"sha256=" + hexdigest`. `GitHubWebhookVerifier`
|
|
16
|
+
recomputes that HMAC over the raw bytes and compares it in constant time. It
|
|
17
|
+
returns `None` on success and raises `WebhookVerificationError` on any failure.
|
|
18
|
+
|
|
19
|
+
Its only tai-\* dependency is `tai42-contract` (the interface it registers
|
|
20
|
+
through); the HMAC work is pure standard library (`hmac` / `hashlib`). It
|
|
21
|
+
**never** imports the skeleton — the plugin is contract-facing.
|
|
22
|
+
|
|
23
|
+
## The TAI ecosystem
|
|
24
|
+
|
|
25
|
+
TAI is an open-source runtime for MCP tools, agents, and workflows. A trigger
|
|
26
|
+
fires a tool from an inbound event; a webhook verifier is the door's bouncer —
|
|
27
|
+
the per-provider check that authenticates a delivery before any hook runs. This
|
|
28
|
+
package is the GitHub verifier. The ecosystem is open-ended: any package can
|
|
29
|
+
supply a verifier, so this repo is this verifier's own full doc home, and the
|
|
30
|
+
documentation site covers the platform-level story:
|
|
31
|
+
|
|
32
|
+
- Triggers & webhooks concept: https://tai42.ai/concepts/triggers-and-webhooks
|
|
33
|
+
- Build a webhook verifier (author guide): https://tai42.ai/guides/authors/webhook-verifier
|
|
34
|
+
- Ecosystem catalog: https://tai42.ai/reference/catalog
|
|
35
|
+
|
|
36
|
+
## Install
|
|
37
|
+
|
|
38
|
+
Requires **Python 3.13+**. Nothing is on PyPI yet, so install from source — clone
|
|
39
|
+
this repo alongside your `tai42-skeleton` checkout and add it as an editable
|
|
40
|
+
dependency of the environment that runs the server:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
git clone https://github.com/tai42ai/tai-webhook-verifier-github
|
|
44
|
+
cd tai-skeleton # or your own app checkout
|
|
45
|
+
uv add --editable ../tai-webhook-verifier-github # once published: uv add tai42-webhook-verifier-github
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## How it loads — `lifecycle_modules`
|
|
49
|
+
|
|
50
|
+
The platform loads this plugin through the manifest's **`lifecycle_modules`**
|
|
51
|
+
field. That field is **import-only**: the host simply imports each listed module
|
|
52
|
+
to run its registration side effect. Importing `tai42_webhook_verifier_github`
|
|
53
|
+
calls `tai42_app.webhook_verifiers.register("github", GitHubWebhookVerifier())`,
|
|
54
|
+
binding the `github` verifier on the app handle.
|
|
55
|
+
|
|
56
|
+
```jsonc
|
|
57
|
+
{
|
|
58
|
+
// Import-only modules: loaded purely for their registration side effect.
|
|
59
|
+
// `lifecycle_modules` are imported WITHOUT going through the extension
|
|
60
|
+
// registry's validation — only `extensions_modules` run that. So this entry
|
|
61
|
+
// is a plain registration, not an extension.
|
|
62
|
+
"lifecycle_modules": ["tai42_webhook_verifier_github"]
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
`lifecycle_modules` entries are imported as-is, with no validation step —
|
|
67
|
+
only `extensions_modules` go through the extension registry's validation. This
|
|
68
|
+
entry is therefore a plain registration, not an extension.
|
|
69
|
+
|
|
70
|
+
## Configuration — the secret never leaves the environment
|
|
71
|
+
|
|
72
|
+
A verifier is bound to a topic with `{verifier, config}`. This plugin's `config`
|
|
73
|
+
holds only the **name** of the environment variable that carries the secret —
|
|
74
|
+
never the secret itself:
|
|
75
|
+
|
|
76
|
+
```json
|
|
77
|
+
{ "verifier": "github", "config": { "secret_env": "GITHUB_WEBHOOK_SECRET" } }
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
At verify time the secret is read from `os.environ[config["secret_env"]]`. A
|
|
81
|
+
**missing** env var raises loudly (`KeyError`) and an **empty** one raises
|
|
82
|
+
`ValueError` — verification fails **CLOSED**, so a misconfigured secret never
|
|
83
|
+
becomes a silently-unauthenticated door.
|
|
84
|
+
|
|
85
|
+
> **Secret hygiene.** The secret lives only in an environment variable. Never
|
|
86
|
+
> commit it to a file, a fixture, a manifest, or a URL. The example secret below
|
|
87
|
+
> (`It's a Secret to Everybody`) is GitHub's own published example — it is a
|
|
88
|
+
> placeholder for docs and tests, never a real secret.
|
|
89
|
+
|
|
90
|
+
## End-to-end
|
|
91
|
+
|
|
92
|
+
1. **Create the GitHub webhook.** In your repo → *Settings* → *Webhooks* → *Add
|
|
93
|
+
webhook*, set the *Payload URL* to your platform's public door, e.g.
|
|
94
|
+
`https://<your-host>/universal_webhook/github-events`, *Content type*
|
|
95
|
+
`application/json`, and a **Secret**. Store that same secret in the
|
|
96
|
+
environment as `GITHUB_WEBHOOK_SECRET` on the platform.
|
|
97
|
+
|
|
98
|
+
2. **List `tai42_webhook_verifier_github` in the manifest** under
|
|
99
|
+
`lifecycle_modules` (see above) so the `github` verifier is registered at
|
|
100
|
+
boot.
|
|
101
|
+
|
|
102
|
+
3. **Bind the verifier to the topic.** Through the skeleton's authenticated
|
|
103
|
+
route:
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
curl -X PUT https://<your-host>/api/hooks/topics/github-events/verifier \
|
|
107
|
+
-H "Authorization: Bearer $TAI_API_TOKEN" \
|
|
108
|
+
-H "Content-Type: application/json" \
|
|
109
|
+
-d '{"verifier": "github", "config": {"secret_env": "GITHUB_WEBHOOK_SECRET"}}'
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
4. **Register a hook** on the `github-events` topic that runs a demo tool (e.g. a
|
|
113
|
+
tool that logs the event). Now push to the repo → GitHub signs and POSTs the
|
|
114
|
+
delivery → the door verifies the `X-Hub-Signature-256` HMAC → the hook fires
|
|
115
|
+
and the tool runs. A delivery with a missing, malformed, or wrong signature is
|
|
116
|
+
rejected before any hook runs.
|
|
117
|
+
|
|
118
|
+
### Simulate a signed delivery locally
|
|
119
|
+
|
|
120
|
+
Compute the signature over the exact body with the same secret and POST it — this
|
|
121
|
+
is what a genuine GitHub delivery looks like on the wire:
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
# The secret lives only in the environment — never hard-coded here.
|
|
125
|
+
export GITHUB_WEBHOOK_SECRET="It's a Secret to Everybody" # GitHub's example placeholder
|
|
126
|
+
|
|
127
|
+
BODY='{"zen":"Keep it logically awesome."}'
|
|
128
|
+
SIG="sha256=$(printf '%s' "$BODY" \
|
|
129
|
+
| openssl dgst -sha256 -hmac "$GITHUB_WEBHOOK_SECRET" -r \
|
|
130
|
+
| cut -d ' ' -f1)"
|
|
131
|
+
|
|
132
|
+
curl -X POST http://127.0.0.1:8000/universal_webhook/github-events \
|
|
133
|
+
-H "Content-Type: application/json" \
|
|
134
|
+
-H "X-GitHub-Event: ping" \
|
|
135
|
+
-H "X-Hub-Signature-256: $SIG" \
|
|
136
|
+
--data-raw "$BODY"
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
`printf '%s'` (not `echo`) sends the body with no trailing newline, so the bytes
|
|
140
|
+
signed match the bytes POSTed exactly — the HMAC is over the raw body.
|
|
141
|
+
|
|
142
|
+
## Verification rules
|
|
143
|
+
|
|
144
|
+
`verify(body, headers, config)` is an `async` method — the caller awaits it. It
|
|
145
|
+
raises `WebhookVerificationError` when:
|
|
146
|
+
|
|
147
|
+
- the `X-Hub-Signature-256` header is **missing** (lookup is case-insensitive),
|
|
148
|
+
- the value is not prefixed exactly `sha256=` (e.g. a `sha1=` prefix),
|
|
149
|
+
- the hex after the prefix is not exactly **64** characters (wrong/truncated),
|
|
150
|
+
- the recomputed digest **does not match** (the final compare uses
|
|
151
|
+
`hmac.compare_digest` — constant-time).
|
|
152
|
+
|
|
153
|
+
A missing `secret_env` env var raises `KeyError` and an empty one raises
|
|
154
|
+
`ValueError` (fails closed), not `WebhookVerificationError`.
|
|
155
|
+
|
|
156
|
+
## Development
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
uv sync
|
|
160
|
+
uv run pytest -q
|
|
161
|
+
uv run ruff check .
|
|
162
|
+
uv run ruff format --check .
|
|
163
|
+
uv run pyright
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
`[tool.uv.sources]` resolves `tai42-contract` from a sibling checkout for local
|
|
167
|
+
development; the published wheel floors it from the index.
|
|
168
|
+
|
|
169
|
+
## License
|
|
170
|
+
|
|
171
|
+
Apache-2.0. See `LICENSE` and `NOTICE`.
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "tai42-webhook-verifier-github"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "GitHub webhook-signature verifier plugin for the TAI ecosystem: a per-provider WebhookVerifier that checks each delivery's X-Hub-Signature-256 HMAC before the payload is dispatched."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.13"
|
|
11
|
+
license = "Apache-2.0"
|
|
12
|
+
license-files = ["LICENSE", "NOTICE"]
|
|
13
|
+
authors = [
|
|
14
|
+
{ name = "tai42", email = "oss@tai42.ai" },
|
|
15
|
+
]
|
|
16
|
+
keywords = ["tai", "webhook", "verifier", "github", "hmac", "signature", "security"]
|
|
17
|
+
classifiers = [
|
|
18
|
+
"Development Status :: 4 - Beta",
|
|
19
|
+
"Intended Audience :: Developers",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.13",
|
|
22
|
+
"Operating System :: OS Independent",
|
|
23
|
+
"Topic :: Security",
|
|
24
|
+
"Typing :: Typed",
|
|
25
|
+
]
|
|
26
|
+
dependencies = [
|
|
27
|
+
# The pure interface contract this verifier registers through (the global
|
|
28
|
+
# tai42_app handle and the WebhookVerifier / WebhookVerificationError types).
|
|
29
|
+
# The HMAC work is pure standard library (hmac / hashlib) — no other tai-*
|
|
30
|
+
# dependency is needed.
|
|
31
|
+
"tai42-contract>=0.1,<0.2",
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
[project.urls]
|
|
35
|
+
Homepage = "https://tai42.ai"
|
|
36
|
+
Repository = "https://github.com/tai42ai/tai-webhook-verifier-github"
|
|
37
|
+
Issues = "https://github.com/tai42ai/tai-webhook-verifier-github/issues"
|
|
38
|
+
Changelog = "https://github.com/tai42ai/tai-webhook-verifier-github/blob/main/CHANGELOG.md"
|
|
39
|
+
|
|
40
|
+
[dependency-groups]
|
|
41
|
+
# Public dev/test tooling (installed by default with `uv sync`).
|
|
42
|
+
dev = [
|
|
43
|
+
"pytest>=8",
|
|
44
|
+
"pytest-cov>=5",
|
|
45
|
+
"ruff>=0.6",
|
|
46
|
+
"pyright>=1.1.389",
|
|
47
|
+
# The plugin-spec test parses tai-plugin.yml.
|
|
48
|
+
"pyyaml>=6",
|
|
49
|
+
]
|
|
50
|
+
|
|
51
|
+
[tool.setuptools]
|
|
52
|
+
package-dir = { "" = "src" }
|
|
53
|
+
|
|
54
|
+
[tool.setuptools.packages.find]
|
|
55
|
+
where = ["src"]
|
|
56
|
+
include = ["tai42_webhook_verifier_github*"]
|
|
57
|
+
|
|
58
|
+
[tool.setuptools.package-data]
|
|
59
|
+
tai42_webhook_verifier_github = ["py.typed", "tai-plugin.yml"]
|
|
60
|
+
|
|
61
|
+
[tool.uv]
|
|
62
|
+
cache-keys = [{ file = "pyproject.toml" }]
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
# The version floors in [project] are the compatibility contract; these path
|
|
66
|
+
# sources resolve the sibling checkouts while the packages are unpublished.
|
|
67
|
+
# They are not part of wheel metadata.
|
|
68
|
+
[tool.uv.sources]
|
|
69
|
+
tai42-contract = { path = "../tai-contract", editable = true }
|
|
70
|
+
[tool.ruff]
|
|
71
|
+
src = ["src"]
|
|
72
|
+
target-version = "py313"
|
|
73
|
+
line-length = 120
|
|
74
|
+
|
|
75
|
+
[tool.ruff.lint]
|
|
76
|
+
select = ["E", "W", "F", "I", "UP", "B", "C4", "SIM", "PIE", "PT", "RUF", "TID"]
|
|
77
|
+
|
|
78
|
+
[tool.ruff.lint.flake8-tidy-imports.banned-api]
|
|
79
|
+
"tai42_skeleton".msg = "tai42-webhook-verifier-github is contract-facing: it never imports tai42-skeleton."
|
|
80
|
+
|
|
81
|
+
[tool.pytest.ini_options]
|
|
82
|
+
testpaths = ["tests"]
|
|
83
|
+
xfail_strict = true
|
|
84
|
+
filterwarnings = ["error"]
|
|
85
|
+
|
|
86
|
+
[tool.coverage.run]
|
|
87
|
+
source = ["tai42_webhook_verifier_github"]
|
|
88
|
+
|
|
89
|
+
[tool.coverage.report]
|
|
90
|
+
fail_under = 95
|
|
91
|
+
|
|
92
|
+
[tool.pyright]
|
|
93
|
+
include = ["src", "tests"]
|
|
94
|
+
pythonVersion = "3.13"
|
|
95
|
+
typeCheckingMode = "basic"
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""GitHub webhook-signature verifier plugin.
|
|
2
|
+
|
|
3
|
+
Importing this package registers a :class:`GitHubWebhookVerifier` under the name
|
|
4
|
+
``"github"`` on the app handle's ``webhook_verifiers`` facet, so a webhook door can
|
|
5
|
+
bind ``github`` to a topic. Import-only: loaded via the manifest's
|
|
6
|
+
``lifecycle_modules`` purely for the registration side effect. Depends only on
|
|
7
|
+
``tai42-contract``.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
from tai42_contract.app import tai42_app
|
|
13
|
+
|
|
14
|
+
from tai42_webhook_verifier_github.verifier import GitHubWebhookVerifier
|
|
15
|
+
|
|
16
|
+
# Registration side effect run on import; a duplicate name raises loudly.
|
|
17
|
+
tai42_app.webhook_verifiers.register("github", GitHubWebhookVerifier())
|
|
18
|
+
|
|
19
|
+
__all__ = ["GitHubWebhookVerifier"]
|
|
File without changes
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
spec_version: 1
|
|
2
|
+
namespace: tai42
|
|
3
|
+
name: webhook-verifier-github
|
|
4
|
+
package: tai42-webhook-verifier-github
|
|
5
|
+
version: 0.1.0
|
|
6
|
+
description: "GitHub webhook-signature verifier plugin for the TAI ecosystem: a per-provider WebhookVerifier that checks each delivery's X-Hub-Signature-256 HMAC before the payload is dispatched."
|
|
7
|
+
license: Apache-2.0
|
|
8
|
+
homepage: https://tai42.ai
|
|
9
|
+
repository: https://github.com/tai42ai/tai-webhook-verifier-github
|
|
10
|
+
contract: ">=0.1,<0.2"
|
|
11
|
+
categories: [webhooks, security]
|
|
12
|
+
tags: [webhooks, github, hmac, security]
|
|
13
|
+
permissions:
|
|
14
|
+
network: false
|
|
15
|
+
subprocess: false
|
|
16
|
+
filesystem: false
|
|
17
|
+
provides:
|
|
18
|
+
- kind: webhook-verifier
|
|
19
|
+
name: github
|
|
20
|
+
module: tai42_webhook_verifier_github
|
|
21
|
+
description: "Verify a GitHub webhook delivery's X-Hub-Signature-256 HMAC before dispatch."
|
|
22
|
+
tags: [github, hmac]
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"""GitHub webhook-signature verifier.
|
|
2
|
+
|
|
3
|
+
Authenticates an inbound delivery's ``X-Hub-Signature-256`` HMAC-SHA256 (over the
|
|
4
|
+
exact raw body, keyed by the shared secret). The secret is named by
|
|
5
|
+
``config["secret_env"]`` and read from the environment at verify time; a missing or
|
|
6
|
+
empty secret raises loudly so the door fails CLOSED. Standard-library only
|
|
7
|
+
(``hmac`` / ``hashlib``).
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import hashlib
|
|
13
|
+
import hmac
|
|
14
|
+
import os
|
|
15
|
+
from collections.abc import Mapping
|
|
16
|
+
from typing import Any
|
|
17
|
+
|
|
18
|
+
from tai42_contract.webhooks import WebhookVerificationError
|
|
19
|
+
|
|
20
|
+
# A well-formed value is ``sha256=`` followed by 64 hex chars.
|
|
21
|
+
_SIGNATURE_HEADER = "X-Hub-Signature-256"
|
|
22
|
+
_SIGNATURE_PREFIX = "sha256="
|
|
23
|
+
_HEX_DIGEST_LEN = hashlib.sha256().digest_size * 2 # 64
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class GitHubWebhookVerifier:
|
|
27
|
+
"""Verifies a GitHub webhook delivery's ``X-Hub-Signature-256`` HMAC.
|
|
28
|
+
|
|
29
|
+
Registered under the name ``"github"`` on the app handle's
|
|
30
|
+
``webhook_verifiers`` facet. Satisfies the
|
|
31
|
+
:class:`~tai42_contract.webhooks.WebhookVerifier` protocol.
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
# Signature covers the raw body only, so a door binding this verifier must reject GET.
|
|
35
|
+
post_only = True
|
|
36
|
+
|
|
37
|
+
async def verify(self, body: bytes, headers: Mapping[str, str], config: dict[str, Any]) -> None:
|
|
38
|
+
"""Verify a GitHub webhook, or raise ``WebhookVerificationError``.
|
|
39
|
+
|
|
40
|
+
``body`` is the exact raw request bytes the HMAC is computed over; ``headers``
|
|
41
|
+
are looked up case-insensitively; ``config`` is
|
|
42
|
+
``{"secret_env": "<ENV VAR NAME>"}``. Fails CLOSED: a missing config key,
|
|
43
|
+
missing env var, or empty secret raises loudly (``KeyError`` / ``ValueError``),
|
|
44
|
+
never an ordinary signature failure.
|
|
45
|
+
"""
|
|
46
|
+
# Fail closed: an empty secret would still key the HMAC into a signature anyone could forge.
|
|
47
|
+
secret_env = config["secret_env"]
|
|
48
|
+
secret = os.environ[secret_env].encode("utf-8")
|
|
49
|
+
if not secret:
|
|
50
|
+
raise ValueError(f"webhook secret environment variable {secret_env!r} is set but empty")
|
|
51
|
+
|
|
52
|
+
signature = _header_lookup(headers, _SIGNATURE_HEADER)
|
|
53
|
+
if signature is None:
|
|
54
|
+
raise WebhookVerificationError(f"missing {_SIGNATURE_HEADER} header")
|
|
55
|
+
|
|
56
|
+
if not signature.startswith(_SIGNATURE_PREFIX):
|
|
57
|
+
raise WebhookVerificationError(f"{_SIGNATURE_HEADER} is not prefixed {_SIGNATURE_PREFIX!r}")
|
|
58
|
+
|
|
59
|
+
provided_hex = signature[len(_SIGNATURE_PREFIX) :]
|
|
60
|
+
if len(provided_hex) != _HEX_DIGEST_LEN:
|
|
61
|
+
raise WebhookVerificationError(f"{_SIGNATURE_HEADER} digest is not {_HEX_DIGEST_LEN} hex characters")
|
|
62
|
+
# Reject a non-hex digest as an ordinary verification failure, not an unhandled parse error.
|
|
63
|
+
try:
|
|
64
|
+
provided_digest = bytes.fromhex(provided_hex)
|
|
65
|
+
except ValueError as exc:
|
|
66
|
+
raise WebhookVerificationError(f"{_SIGNATURE_HEADER} digest is not valid hex") from exc
|
|
67
|
+
|
|
68
|
+
expected_digest = hmac.new(secret, body, hashlib.sha256).digest()
|
|
69
|
+
|
|
70
|
+
# Constant-time compare so a mismatch position cannot be timed.
|
|
71
|
+
if not hmac.compare_digest(provided_digest, expected_digest):
|
|
72
|
+
raise WebhookVerificationError(f"{_SIGNATURE_HEADER} digest mismatch")
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def _header_lookup(headers: Mapping[str, str], name: str) -> str | None:
|
|
76
|
+
"""Return ``name``'s value from ``headers`` case-insensitively.
|
|
77
|
+
|
|
78
|
+
HTTP header names are case-insensitive and the caller may pass a plain ``dict``.
|
|
79
|
+
"""
|
|
80
|
+
target = name.lower()
|
|
81
|
+
for key, value in headers.items():
|
|
82
|
+
if key.lower() == target:
|
|
83
|
+
return value
|
|
84
|
+
return None
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
__all__ = ["GitHubWebhookVerifier"]
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tai42-webhook-verifier-github
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: GitHub webhook-signature verifier plugin for the TAI ecosystem: a per-provider WebhookVerifier that checks each delivery's X-Hub-Signature-256 HMAC before the payload is dispatched.
|
|
5
|
+
Author-email: tai42 <oss@tai42.ai>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://tai42.ai
|
|
8
|
+
Project-URL: Repository, https://github.com/tai42ai/tai-webhook-verifier-github
|
|
9
|
+
Project-URL: Issues, https://github.com/tai42ai/tai-webhook-verifier-github/issues
|
|
10
|
+
Project-URL: Changelog, https://github.com/tai42ai/tai-webhook-verifier-github/blob/main/CHANGELOG.md
|
|
11
|
+
Keywords: tai,webhook,verifier,github,hmac,signature,security
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Topic :: Security
|
|
18
|
+
Classifier: Typing :: Typed
|
|
19
|
+
Requires-Python: >=3.13
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
License-File: NOTICE
|
|
23
|
+
Requires-Dist: tai42-contract<0.2,>=0.1
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
|
|
26
|
+
# tai42-webhook-verifier-github
|
|
27
|
+
|
|
28
|
+
[](https://github.com/tai42ai/tai-webhook-verifier-github/actions/workflows/ci.yml)
|
|
29
|
+
[](LICENSE)
|
|
30
|
+
|
|
31
|
+
The GitHub webhook-signature verifier plugin for the TAI ecosystem — a
|
|
32
|
+
per-provider `WebhookVerifier` that authenticates each inbound GitHub delivery
|
|
33
|
+
before the platform parses or dispatches its payload.
|
|
34
|
+
|
|
35
|
+
> A webhook door can bind a named verifier to a topic; this plugin supplies the
|
|
36
|
+
> `github` verifier.
|
|
37
|
+
|
|
38
|
+
GitHub signs every webhook delivery with an HMAC-SHA256 over the **exact raw
|
|
39
|
+
request body**, keyed by the shared secret, and sends it in the
|
|
40
|
+
`X-Hub-Signature-256` header as `"sha256=" + hexdigest`. `GitHubWebhookVerifier`
|
|
41
|
+
recomputes that HMAC over the raw bytes and compares it in constant time. It
|
|
42
|
+
returns `None` on success and raises `WebhookVerificationError` on any failure.
|
|
43
|
+
|
|
44
|
+
Its only tai-\* dependency is `tai42-contract` (the interface it registers
|
|
45
|
+
through); the HMAC work is pure standard library (`hmac` / `hashlib`). It
|
|
46
|
+
**never** imports the skeleton — the plugin is contract-facing.
|
|
47
|
+
|
|
48
|
+
## The TAI ecosystem
|
|
49
|
+
|
|
50
|
+
TAI is an open-source runtime for MCP tools, agents, and workflows. A trigger
|
|
51
|
+
fires a tool from an inbound event; a webhook verifier is the door's bouncer —
|
|
52
|
+
the per-provider check that authenticates a delivery before any hook runs. This
|
|
53
|
+
package is the GitHub verifier. The ecosystem is open-ended: any package can
|
|
54
|
+
supply a verifier, so this repo is this verifier's own full doc home, and the
|
|
55
|
+
documentation site covers the platform-level story:
|
|
56
|
+
|
|
57
|
+
- Triggers & webhooks concept: https://tai42.ai/concepts/triggers-and-webhooks
|
|
58
|
+
- Build a webhook verifier (author guide): https://tai42.ai/guides/authors/webhook-verifier
|
|
59
|
+
- Ecosystem catalog: https://tai42.ai/reference/catalog
|
|
60
|
+
|
|
61
|
+
## Install
|
|
62
|
+
|
|
63
|
+
Requires **Python 3.13+**. Nothing is on PyPI yet, so install from source — clone
|
|
64
|
+
this repo alongside your `tai42-skeleton` checkout and add it as an editable
|
|
65
|
+
dependency of the environment that runs the server:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
git clone https://github.com/tai42ai/tai-webhook-verifier-github
|
|
69
|
+
cd tai-skeleton # or your own app checkout
|
|
70
|
+
uv add --editable ../tai-webhook-verifier-github # once published: uv add tai42-webhook-verifier-github
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## How it loads — `lifecycle_modules`
|
|
74
|
+
|
|
75
|
+
The platform loads this plugin through the manifest's **`lifecycle_modules`**
|
|
76
|
+
field. That field is **import-only**: the host simply imports each listed module
|
|
77
|
+
to run its registration side effect. Importing `tai42_webhook_verifier_github`
|
|
78
|
+
calls `tai42_app.webhook_verifiers.register("github", GitHubWebhookVerifier())`,
|
|
79
|
+
binding the `github` verifier on the app handle.
|
|
80
|
+
|
|
81
|
+
```jsonc
|
|
82
|
+
{
|
|
83
|
+
// Import-only modules: loaded purely for their registration side effect.
|
|
84
|
+
// `lifecycle_modules` are imported WITHOUT going through the extension
|
|
85
|
+
// registry's validation — only `extensions_modules` run that. So this entry
|
|
86
|
+
// is a plain registration, not an extension.
|
|
87
|
+
"lifecycle_modules": ["tai42_webhook_verifier_github"]
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
`lifecycle_modules` entries are imported as-is, with no validation step —
|
|
92
|
+
only `extensions_modules` go through the extension registry's validation. This
|
|
93
|
+
entry is therefore a plain registration, not an extension.
|
|
94
|
+
|
|
95
|
+
## Configuration — the secret never leaves the environment
|
|
96
|
+
|
|
97
|
+
A verifier is bound to a topic with `{verifier, config}`. This plugin's `config`
|
|
98
|
+
holds only the **name** of the environment variable that carries the secret —
|
|
99
|
+
never the secret itself:
|
|
100
|
+
|
|
101
|
+
```json
|
|
102
|
+
{ "verifier": "github", "config": { "secret_env": "GITHUB_WEBHOOK_SECRET" } }
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
At verify time the secret is read from `os.environ[config["secret_env"]]`. A
|
|
106
|
+
**missing** env var raises loudly (`KeyError`) and an **empty** one raises
|
|
107
|
+
`ValueError` — verification fails **CLOSED**, so a misconfigured secret never
|
|
108
|
+
becomes a silently-unauthenticated door.
|
|
109
|
+
|
|
110
|
+
> **Secret hygiene.** The secret lives only in an environment variable. Never
|
|
111
|
+
> commit it to a file, a fixture, a manifest, or a URL. The example secret below
|
|
112
|
+
> (`It's a Secret to Everybody`) is GitHub's own published example — it is a
|
|
113
|
+
> placeholder for docs and tests, never a real secret.
|
|
114
|
+
|
|
115
|
+
## End-to-end
|
|
116
|
+
|
|
117
|
+
1. **Create the GitHub webhook.** In your repo → *Settings* → *Webhooks* → *Add
|
|
118
|
+
webhook*, set the *Payload URL* to your platform's public door, e.g.
|
|
119
|
+
`https://<your-host>/universal_webhook/github-events`, *Content type*
|
|
120
|
+
`application/json`, and a **Secret**. Store that same secret in the
|
|
121
|
+
environment as `GITHUB_WEBHOOK_SECRET` on the platform.
|
|
122
|
+
|
|
123
|
+
2. **List `tai42_webhook_verifier_github` in the manifest** under
|
|
124
|
+
`lifecycle_modules` (see above) so the `github` verifier is registered at
|
|
125
|
+
boot.
|
|
126
|
+
|
|
127
|
+
3. **Bind the verifier to the topic.** Through the skeleton's authenticated
|
|
128
|
+
route:
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
curl -X PUT https://<your-host>/api/hooks/topics/github-events/verifier \
|
|
132
|
+
-H "Authorization: Bearer $TAI_API_TOKEN" \
|
|
133
|
+
-H "Content-Type: application/json" \
|
|
134
|
+
-d '{"verifier": "github", "config": {"secret_env": "GITHUB_WEBHOOK_SECRET"}}'
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
4. **Register a hook** on the `github-events` topic that runs a demo tool (e.g. a
|
|
138
|
+
tool that logs the event). Now push to the repo → GitHub signs and POSTs the
|
|
139
|
+
delivery → the door verifies the `X-Hub-Signature-256` HMAC → the hook fires
|
|
140
|
+
and the tool runs. A delivery with a missing, malformed, or wrong signature is
|
|
141
|
+
rejected before any hook runs.
|
|
142
|
+
|
|
143
|
+
### Simulate a signed delivery locally
|
|
144
|
+
|
|
145
|
+
Compute the signature over the exact body with the same secret and POST it — this
|
|
146
|
+
is what a genuine GitHub delivery looks like on the wire:
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
# The secret lives only in the environment — never hard-coded here.
|
|
150
|
+
export GITHUB_WEBHOOK_SECRET="It's a Secret to Everybody" # GitHub's example placeholder
|
|
151
|
+
|
|
152
|
+
BODY='{"zen":"Keep it logically awesome."}'
|
|
153
|
+
SIG="sha256=$(printf '%s' "$BODY" \
|
|
154
|
+
| openssl dgst -sha256 -hmac "$GITHUB_WEBHOOK_SECRET" -r \
|
|
155
|
+
| cut -d ' ' -f1)"
|
|
156
|
+
|
|
157
|
+
curl -X POST http://127.0.0.1:8000/universal_webhook/github-events \
|
|
158
|
+
-H "Content-Type: application/json" \
|
|
159
|
+
-H "X-GitHub-Event: ping" \
|
|
160
|
+
-H "X-Hub-Signature-256: $SIG" \
|
|
161
|
+
--data-raw "$BODY"
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
`printf '%s'` (not `echo`) sends the body with no trailing newline, so the bytes
|
|
165
|
+
signed match the bytes POSTed exactly — the HMAC is over the raw body.
|
|
166
|
+
|
|
167
|
+
## Verification rules
|
|
168
|
+
|
|
169
|
+
`verify(body, headers, config)` is an `async` method — the caller awaits it. It
|
|
170
|
+
raises `WebhookVerificationError` when:
|
|
171
|
+
|
|
172
|
+
- the `X-Hub-Signature-256` header is **missing** (lookup is case-insensitive),
|
|
173
|
+
- the value is not prefixed exactly `sha256=` (e.g. a `sha1=` prefix),
|
|
174
|
+
- the hex after the prefix is not exactly **64** characters (wrong/truncated),
|
|
175
|
+
- the recomputed digest **does not match** (the final compare uses
|
|
176
|
+
`hmac.compare_digest` — constant-time).
|
|
177
|
+
|
|
178
|
+
A missing `secret_env` env var raises `KeyError` and an empty one raises
|
|
179
|
+
`ValueError` (fails closed), not `WebhookVerificationError`.
|
|
180
|
+
|
|
181
|
+
## Development
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
uv sync
|
|
185
|
+
uv run pytest -q
|
|
186
|
+
uv run ruff check .
|
|
187
|
+
uv run ruff format --check .
|
|
188
|
+
uv run pyright
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
`[tool.uv.sources]` resolves `tai42-contract` from a sibling checkout for local
|
|
192
|
+
development; the published wheel floors it from the index.
|
|
193
|
+
|
|
194
|
+
## License
|
|
195
|
+
|
|
196
|
+
Apache-2.0. See `LICENSE` and `NOTICE`.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
MANIFEST.in
|
|
3
|
+
NOTICE
|
|
4
|
+
README.md
|
|
5
|
+
pyproject.toml
|
|
6
|
+
src/tai42_webhook_verifier_github/__init__.py
|
|
7
|
+
src/tai42_webhook_verifier_github/py.typed
|
|
8
|
+
src/tai42_webhook_verifier_github/tai-plugin.yml
|
|
9
|
+
src/tai42_webhook_verifier_github/verifier.py
|
|
10
|
+
src/tai42_webhook_verifier_github.egg-info/PKG-INFO
|
|
11
|
+
src/tai42_webhook_verifier_github.egg-info/SOURCES.txt
|
|
12
|
+
src/tai42_webhook_verifier_github.egg-info/dependency_links.txt
|
|
13
|
+
src/tai42_webhook_verifier_github.egg-info/requires.txt
|
|
14
|
+
src/tai42_webhook_verifier_github.egg-info/top_level.txt
|
tai42_webhook_verifier_github-0.1.0/src/tai42_webhook_verifier_github.egg-info/dependency_links.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
tai42-contract<0.2,>=0.1
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
tai42_webhook_verifier_github
|