fix(events): verify webhook signatures before parsing (#2021)
A source now declares how its deliveries prove themselves: token (the default, unchanged), hmac (HMAC-SHA256 over the raw body, per-source header and prefix, secret sealed at rest and write-only) or none. The events module verifies before the connector parses, answers 401 and logs the refusal. The digest comparison is ported from internal/webhookguard/hmac.go and the header-borne signature from internal/infrastructure/captureintake/receiver.go; the old copies stay until their service goes. The seal package moves to internal/platform/seal so events can seal the secret.
This commit is contained in:
15 files changed
+415
-65
No files matched your search
@@ -16,7 +16,7 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@
|
||||
import { SettingRow } from "@/components/ui/setting-row";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { errors } from "@/copy/errors";
|
||||
import { api, describeError, type EventSource_ } from "@/lib/api";
|
||||
import { api, describeError, type EventSource_, type SourceVerification } from "@/lib/api";
|
||||
import { useRead } from "@/lib/use-read";
|
||||
|
||||
const { data, error, reload } = useRead(() => api.eventSources());
|
||||
@@ -29,19 +29,20 @@ onMounted(() => {
|
||||
const columns: DataTableColumn<EventSource_>[] = [
|
||||
{ id: "name", label: "Source", fixed: true, sort: (s) => s.name },
|
||||
{ id: "connector", label: "Connector", sort: (s) => s.connector },
|
||||
{ id: "verification", label: "Verified by" },
|
||||
{ id: "key", label: "Grouped by" },
|
||||
];
|
||||
|
||||
// A put creates a source or rotates its token; either way the token is shown
|
||||
// once, since only its hash is kept.
|
||||
const issued = ref<{ url: string; token: string } | null>(null);
|
||||
const issued = ref<{ url: string; token?: string } | null>(null);
|
||||
const busy = ref(false);
|
||||
const actionError = ref("");
|
||||
async function put(name: string, connector: string): Promise<boolean> {
|
||||
async function put(name: string, connector: string, verification?: SourceVerification): Promise<boolean> {
|
||||
busy.value = true;
|
||||
actionError.value = "";
|
||||
try {
|
||||
const created = await api.putEventSource(name, connector);
|
||||
const created = await api.putEventSource(name, connector, verification);
|
||||
issued.value = { url: new URL(created.url, window.location.origin).toString(), token: created.token };
|
||||
await reload();
|
||||
return true;
|
||||
@@ -54,13 +55,17 @@ async function put(name: string, connector: string): Promise<boolean> {
|
||||
}
|
||||
|
||||
const adding = ref(false);
|
||||
const draft = ref({ name: "", connector: "" });
|
||||
const blank = { name: "", connector: "", verification: "token" as SourceVerification["verification"], hmac_header: "", hmac_prefix: "", hmac_secret: "" };
|
||||
const draft = ref({ ...blank });
|
||||
async function add(): Promise<void> {
|
||||
if (await put(draft.value.name.trim(), draft.value.connector)) {
|
||||
const { name, connector, ...verification } = draft.value;
|
||||
if (await put(name.trim(), connector, verification)) {
|
||||
adding.value = false;
|
||||
draft.value = { name: "", connector: "" };
|
||||
draft.value = { ...blank };
|
||||
}
|
||||
}
|
||||
const addDisabled = computed(() => busy.value || !draft.value.name || !draft.value.connector
|
||||
|| (draft.value.verification === "hmac" && (!draft.value.hmac_header || !draft.value.hmac_secret)));
|
||||
|
||||
const keyFieldsOf = ref<EventSource_ | null>(null);
|
||||
const keyFields = ref("");
|
||||
@@ -89,9 +94,9 @@ const connectorNames = computed(() => (connectors.data.value ?? []).map((c) => c
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<Section v-if="issued" title="Webhook" description="Copy the token now: it is not shown again.">
|
||||
<Section v-if="issued" title="Webhook" :description="issued.token ? 'Copy the token now: it is not shown again.' : undefined">
|
||||
<SettingRow label="URL"><CodeView :code="issued.url" /></SettingRow>
|
||||
<SettingRow label="Bearer token"><CodeView :code="issued.token" /></SettingRow>
|
||||
<SettingRow v-if="issued.token" label="Bearer token"><CodeView :code="issued.token" /></SettingRow>
|
||||
<div class="flex justify-end"><Button size="sm" variant="outline" @click="issued = null">Done</Button></div>
|
||||
</Section>
|
||||
<p v-if="actionError && !adding && !keyFieldsOf" role="alert" class="mb-2 text-caption text-danger">{{ actionError }}</p>
|
||||
@@ -104,11 +109,12 @@ const connectorNames = computed(() => (connectors.data.value ?? []).map((c) => c
|
||||
<DataTable :columns="columns" :rows="data" :row-key="(s) => s.name" storage-key="sources">
|
||||
<template #cell-name="{ row }"><span class="font-medium">{{ row.name }}</span></template>
|
||||
<template #cell-connector="{ row }">{{ row.connector }}</template>
|
||||
<template #cell-verification="{ row }">{{ row.verification === "hmac" ? `HMAC (${row.hmac_header})` : row.verification === "none" ? "Nothing" : "Bearer token" }}</template>
|
||||
<template #cell-key="{ row }"><span class="font-mono text-caption">{{ (row.key_fields ?? []).join(", ") || "Connector default" }}</span></template>
|
||||
<template #actions="{ row }">
|
||||
<MoreMenu :label="`${row.name} actions`">
|
||||
<DropdownMenuItem @select="editKeyFields(row)">Group by…</DropdownMenuItem>
|
||||
<DropdownMenuItem :disabled="busy" @select="put(row.name, row.connector)">Rotate token</DropdownMenuItem>
|
||||
<DropdownMenuItem v-if="row.verification === 'token'" :disabled="busy" @select="put(row.name, row.connector)">Rotate token</DropdownMenuItem>
|
||||
</MoreMenu>
|
||||
</template>
|
||||
<template #empty><Empty><EmptyHeader><EmptyTitle>No sources</EmptyTitle></EmptyHeader></Empty></template>
|
||||
@@ -126,10 +132,23 @@ const connectorNames = computed(() => (connectors.data.value ?? []).map((c) => c
|
||||
<SelectItem v-for="name in connectorNames" :key="name" :value="name">{{ name }}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<Select v-model="draft.verification">
|
||||
<SelectTrigger class="w-full" aria-label="Verification"><SelectValue /></SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="token">Bearer token</SelectItem>
|
||||
<SelectItem value="hmac">HMAC signature</SelectItem>
|
||||
<SelectItem value="none">Nothing</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<template v-if="draft.verification === 'hmac'">
|
||||
<Input v-model="draft.hmac_header" aria-label="Signature header" placeholder="X-Hub-Signature-256" required />
|
||||
<Input v-model="draft.hmac_prefix" aria-label="Signature prefix" placeholder="sha256=" />
|
||||
<Input v-model="draft.hmac_secret" type="password" aria-label="Signing secret" autocomplete="off" required />
|
||||
</template>
|
||||
<p v-if="connectors.error.value" class="text-caption text-danger">{{ connectors.error.value }}</p>
|
||||
<p v-if="actionError" role="alert" class="text-caption text-danger">{{ actionError }}</p>
|
||||
</form>
|
||||
<DialogFooter><Button type="submit" form="add-source" :disabled="busy || !draft.name || !draft.connector">Add</Button></DialogFooter>
|
||||
<DialogFooter><Button type="submit" form="add-source" :disabled="addDisabled">Add</Button></DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
|
||||
+14
-2
@@ -194,8 +194,8 @@ export const api = {
|
||||
request<EventRecord[]>("/api/events" + qs(params)),
|
||||
event: (id: string) => request<EventDetail>(`/api/events/${encodeURIComponent(id)}`),
|
||||
eventSources: () => request<EventSource_[]>("/api/sources"),
|
||||
putEventSource: (name: string, connector: string) =>
|
||||
request<{ source: string; token: string; url: string }>(`/api/sources/${encodeURIComponent(name)}`, { method: "PUT", body: { connector } }),
|
||||
putEventSource: (name: string, connector: string, verification?: SourceVerification) =>
|
||||
request<{ source: string; token?: string; url: string }>(`/api/sources/${encodeURIComponent(name)}`, { method: "PUT", body: { connector, ...verification } }),
|
||||
putSourceKeyFields: (name: string, paths: string[]) =>
|
||||
request<{ key_fields: string[] }>(`/api/sources/${encodeURIComponent(name)}/key-fields`, { method: "PUT", body: { paths } }),
|
||||
triggers: () => request<Trigger[]>("/api/triggers"),
|
||||
@@ -741,11 +741,23 @@ export interface EventDetail {
|
||||
}
|
||||
|
||||
// Named with a trailing underscore: EventSource is the browser's SSE class.
|
||||
export interface SourceVerification {
|
||||
verification: "token" | "hmac" | "none";
|
||||
hmac_header?: string;
|
||||
hmac_prefix?: string;
|
||||
/** Write-only: sealed on save and never returned. */
|
||||
hmac_secret?: string;
|
||||
}
|
||||
|
||||
export interface EventSource_ {
|
||||
name: string;
|
||||
connector: string;
|
||||
key_fields?: string[];
|
||||
token_set: boolean;
|
||||
verification: "token" | "hmac" | "none";
|
||||
hmac_header?: string;
|
||||
hmac_prefix?: string;
|
||||
hmac_secret_set: boolean;
|
||||
}
|
||||
|
||||
export interface Trigger {
|
||||
|
||||
Reference in new issue
Block a user