Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ if (!isValid) {
| Intercom | `X-Hub-Signature` | HMAC-SHA1 |
| Mailchimp | `X-Mailchimp-Signature` | HMAC-SHA256 (base64) |
| GitLab | `X-Gitlab-Token` | Token comparison |
| Home Assistant | `X-HA-Secret` | Token comparison |
| Typeform | `Typeform-Signature` | HMAC-SHA256 (base64) |
| Crystallize | `X-Crystallize-Signature` | JWT + HMAC-SHA256 |
| Zendesk | `X-Zendesk-Webhook-Signature` | HMAC-SHA256 + timestamp |
Expand Down Expand Up @@ -389,6 +390,42 @@ app.post('/webhook/gitlab', express.json(), (req, res) => {
});
```

### Home Assistant

```typescript
import { verify } from 'webhook-verify';

app.post('/webhook/homeassistant', express.json(), (req, res) => {
// Home Assistant uses token comparison via X-HA-Secret header
const isValid = verify(
'homeassistant',
'',
req.headers,
process.env.HA_SHARED_SECRET
);

if (!isValid) {
return res.status(401).send('Invalid token');
}

const { entity_id, state } = req.body;
// Process Home Assistant event...
});
```

Home Assistant configuration example:

```yaml
rest_command:
send_event:
url: "https://your-webhook-url.com/ha/event"
method: POST
headers:
X-HA-Secret: !secret webhook_secret
content_type: "application/json"
payload: '{"entity_id": "{{ entity_id }}", "state": "{{ state }}"}'
```

### Crystallize

```typescript
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
"square",
"hubspot",
"segment",
"homeassistant",
"home-assistant",
"ed25519",
"rsa",
"security",
Expand Down
7 changes: 7 additions & 0 deletions src/headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ const providerHeaders: Record<Provider, (headers: Headers) => SignatureData | nu
return { signature: token, rawSignature: token, eventType: event };
},

homeassistant: (headers) => {
const token = getHeader(headers, 'x-ha-secret');
if (!token) return null;
return { signature: token, rawSignature: token };
},

typeform: (headers) => {
const signature = getHeader(headers, 'typeform-signature');
if (!signature) return null;
Expand Down Expand Up @@ -286,6 +292,7 @@ export function getHeaderNames(provider: Provider): Record<string, string> {
intercom: { signature: 'x-hub-signature' },
mailchimp: { signature: 'x-mailchimp-signature' },
gitlab: { token: 'x-gitlab-token', event: 'x-gitlab-event' },
homeassistant: { token: 'x-ha-secret' },
typeform: { signature: 'typeform-signature' },
crystallize: { signature: 'x-crystallize-signature' },
zendesk: { signature: 'x-zendesk-webhook-signature', timestamp: 'x-zendesk-webhook-signature-timestamp' },
Expand Down
33 changes: 33 additions & 0 deletions src/providers/homeassistant.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { secureCompare } from '../utils/crypto.js';
import type { ProviderVerifier } from '../types.js';

/**
* Home Assistant webhook verification
*
* Home Assistant uses a simple secret token comparison via X-HA-Secret header.
* The signature parameter should contain the token from the header.
*
* Home Assistant Configuration Example:
* ```yaml
* rest_command:
* send_event:
* url: "https://your-webhook-url.com/ha/event"
* method: POST
* headers:
* X-HA-Secret: "your-shared-secret"
* content_type: "application/json"
* payload: '{"entity_id": "{{ entity_id }}", "state": "{{ state }}"}'
* ```
*
* @see https://www.home-assistant.io/integrations/rest_command/
*/
export const homeassistant: ProviderVerifier = {
verify(_payload, signature, secret) {
if (!signature || !secret) {
return false;
}

// Home Assistant simply compares the token from the header with the secret
return secureCompare(signature, secret);
},
};
3 changes: 3 additions & 0 deletions src/providers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { crystallize } from './crystallize.js';
import { discord } from './discord.js';
import { github } from './github.js';
import { gitlab } from './gitlab.js';
import { homeassistant } from './homeassistant.js';
import { hubspot } from './hubspot.js';
import { intercom } from './intercom.js';
import { linear } from './linear.js';
Expand Down Expand Up @@ -31,6 +32,7 @@ export const providers: Record<Provider, ProviderVerifier> = {
discord,
github,
gitlab,
homeassistant,
hubspot,
intercom,
linear,
Expand All @@ -55,6 +57,7 @@ export {
discord,
github,
gitlab,
homeassistant,
hubspot,
intercom,
linear,
Expand Down
3 changes: 2 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export type Provider =
| 'zendesk'
| 'square'
| 'hubspot'
| 'segment';
| 'segment'
| 'homeassistant';

/**
* Base options available to all providers
Expand Down