hookarmor 1.0.1 โ 1.0.2
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.
- package/README.md +57 -0
- package/package.json +1 -1
- package/src/dispatcher.js +20 -1
package/README.md
CHANGED
|
@@ -153,6 +153,63 @@ HookArmor solves this automatically:
|
|
|
153
153
|
|
|
154
154
|
---
|
|
155
155
|
|
|
156
|
+
## ๐ก๏ธ Provenance Headers & Out-of-Order Replay Protection
|
|
157
|
+
|
|
158
|
+
When replaying dead-letter events hours or days later, applying payloads out of order can accidentally clobber newer database state (e.g., an older `customer.subscription.updated` event overwriting a newer cancellation).
|
|
159
|
+
|
|
160
|
+
To protect downstream handlers against state drift, HookArmor injects explicit provenance headers on every forward and replay:
|
|
161
|
+
|
|
162
|
+
* `x-hookarmor-delivery-id`: Unique HookArmor event delivery ID.
|
|
163
|
+
* `x-hookarmor-attempt`: Current delivery attempt number (e.g., `1` on initial, `2+` on retries).
|
|
164
|
+
* `x-hookarmor-original-timestamp`: The exact ISO-8601 timestamp when the webhook originally arrived at the ingress edge.
|
|
165
|
+
* `x-hookarmor-is-replay`: Set to `'true'` during automated retries and manual dashboard replays (`'false'` on initial delivery).
|
|
166
|
+
* `x-hookarmor-original-stripe-signature`: Preserves the authentic original Stripe signature for audit logs and forensic verification.
|
|
167
|
+
|
|
168
|
+
**Recommended Downstream Handler Pattern:**
|
|
169
|
+
```javascript
|
|
170
|
+
app.post('/api/webhooks/stripe', express.raw({ type: 'application/json' }), (req, res) => {
|
|
171
|
+
// Standard verification passes 100% of the time
|
|
172
|
+
const event = stripe.webhooks.constructEvent(req.body, req.headers['stripe-signature'], endpointSecret);
|
|
173
|
+
|
|
174
|
+
// If this is a replay, verify you are not clobbering newer database state:
|
|
175
|
+
if (req.headers['x-hookarmor-is-replay'] === 'true') {
|
|
176
|
+
const originalTime = new Date(req.headers['x-hookarmor-original-timestamp']).getTime();
|
|
177
|
+
// Fetch latest object from Stripe API or check if local DB already has a newer updated_at timestamp
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
res.json({ received: true });
|
|
181
|
+
});
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
|
|
186
|
+
## ๐๏ธ Dual Trust Boundaries: Transparent vs. Isolated Mode
|
|
187
|
+
|
|
188
|
+
HookArmor supports two forwarding architectures depending on your team's security posture:
|
|
189
|
+
|
|
190
|
+
1. **Mode A: Transparent Proxy (Default ยท Zero Code Changes)**
|
|
191
|
+
* HookArmor re-signs the outbound request using your provider secret with `t=now`.
|
|
192
|
+
* Your existing application code (`stripe.webhooks.constructEvent()`) runs unmodified.
|
|
193
|
+
* Original signatures are preserved in `x-hookarmor-original-stripe-signature`.
|
|
194
|
+
|
|
195
|
+
2. **Mode B: Isolated Trust Boundary (Enterprise Security)**
|
|
196
|
+
* Set the `HOOKARMOR_SIGNING_SECRET` environment variable.
|
|
197
|
+
* HookArmor attaches an isolated `x-hookarmor-signature: t=..., v1=...` HMAC header using your internal secret.
|
|
198
|
+
* Downstream handlers verify HookArmor as the internal sender, maintaining strict separation between external Stripe signatures and internal relay deliveries.
|
|
199
|
+
|
|
200
|
+
---
|
|
201
|
+
|
|
202
|
+
## โ ๏ธ Production Durability: The Early 200 OK Tradeoff
|
|
203
|
+
|
|
204
|
+
HookArmor returns an immediate `200 OK` to Stripe and Shopify in `<10ms` to protect your ingress latency and prevent providers from marking your endpoint failed during downstream outages.
|
|
205
|
+
|
|
206
|
+
**What this means for production operators:**
|
|
207
|
+
* Once HookArmor returns `200 OK`, Stripe considers the webhook delivered and **halts its external retry backup**.
|
|
208
|
+
* HookArmor's embedded SQLite database assumes **sole custody** of that event.
|
|
209
|
+
* **Persistent storage is mandatory:** When deploying via Docker, you must mount the data volume (`-v $(pwd)/data:/app/data`) and ensure host-level backups are active.
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
156
213
|
## ๐ฆ Hosted Cloud & Self-Hosting
|
|
157
214
|
|
|
158
215
|
| Feature | Self-Hosted (MIT) | Hosted Cloud Starter ($29/mo) | Hosted Cloud Pro ($79/mo) |
|
package/package.json
CHANGED
package/src/dispatcher.js
CHANGED
|
@@ -164,11 +164,27 @@ class Dispatcher extends EventEmitter {
|
|
|
164
164
|
|
|
165
165
|
let headers = { ...event.headers };
|
|
166
166
|
|
|
167
|
-
//
|
|
167
|
+
// Preserve original raw signatures before re-signing for audit and forensic trace
|
|
168
|
+
if (event.headers && event.headers['stripe-signature']) {
|
|
169
|
+
headers['x-hookarmor-original-stripe-signature'] = event.headers['stripe-signature'];
|
|
170
|
+
}
|
|
171
|
+
if (event.headers && event.headers['x-shopify-hmac-sha256']) {
|
|
172
|
+
headers['x-hookarmor-original-shopify-hmac'] = event.headers['x-shopify-hmac-sha256'];
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Re-sign outbound headers if endpoint secret is configured (Transparent Zero-Code-Change Mode)
|
|
168
176
|
if (endpoint.secret) {
|
|
169
177
|
headers = this.signHeaders(event.provider, event.raw_body, headers, endpoint.secret);
|
|
170
178
|
}
|
|
171
179
|
|
|
180
|
+
// Optional Isolated Trust Domain mode: if HOOKARMOR_SIGNING_SECRET is provided
|
|
181
|
+
const internalSecret = process.env.HOOKARMOR_SIGNING_SECRET || endpoint.internal_secret;
|
|
182
|
+
if (internalSecret) {
|
|
183
|
+
const freshTs = Math.floor(Date.now() / 1000);
|
|
184
|
+
const internalSig = crypto.createHmac('sha256', internalSecret).update(`${freshTs}.${event.raw_body}`).digest('hex');
|
|
185
|
+
headers['x-hookarmor-signature'] = `t=${freshTs},v1=${internalSig}`;
|
|
186
|
+
}
|
|
187
|
+
|
|
172
188
|
// Remove hop-by-hop and encoding headers
|
|
173
189
|
delete headers['host'];
|
|
174
190
|
delete headers['connection'];
|
|
@@ -180,6 +196,9 @@ class Dispatcher extends EventEmitter {
|
|
|
180
196
|
headers['content-length'] = rawBuffer.length;
|
|
181
197
|
headers['x-hookarmor-delivery-id'] = event.id;
|
|
182
198
|
headers['x-hookarmor-attempt'] = String(event.attempts + 1);
|
|
199
|
+
headers['x-hookarmor-original-timestamp'] = event.created_at;
|
|
200
|
+
const isReplay = (event.attempts > 0 || event.status === 'replaying');
|
|
201
|
+
headers['x-hookarmor-is-replay'] = isReplay ? 'true' : 'false';
|
|
183
202
|
|
|
184
203
|
return new Promise((resolve) => {
|
|
185
204
|
try {
|