Skip to content
Open
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
5 changes: 5 additions & 0 deletions .changeset/tough-guests-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sapiom/harness": patch
---

Compare the /ingest bearer token in constant time, matching the /api and WS upgrade paths.
6 changes: 6 additions & 0 deletions packages/harness/src/server/ingest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ describe("createIngestRouter", () => {
expect(stored).toHaveLength(0);
});

it("rejects requests with no Authorization header at all", async () => {
const res = await postIngest(baseUrl, { hookEvent: "SessionStart" }, "");
expect(res.status).toBe(401);
expect(stored).toHaveLength(0);
});

it("responds 200 immediately and processes asynchronously", async () => {
const res = await postIngest(baseUrl, {
hookEvent: "UserPromptSubmit",
Expand Down
3 changes: 2 additions & 1 deletion packages/harness/src/server/ingest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import express, { type Router } from "express";
import type { AnalyticsEvent, HarnessKind } from "../shared/types.js";
import type { NormalizeContext } from "../core/collector/normalizer.js";
import { createSeqCounter, type SeqCounter } from "../core/collector/seq.js";
import { timingSafeEqualString } from "./auth.js";

export interface IngestSessionContext {
harness: HarnessKind;
Expand Down Expand Up @@ -162,7 +163,7 @@ export function createIngestRouter(deps: IngestDeps): Router {

router.post("/ingest", (req, res) => {
const token = bearerToken(req.headers.authorization);
if (token !== deps.ingestToken) {
if (!timingSafeEqualString(token ?? "", deps.ingestToken)) {
res.status(401).json({ ok: false });
return;
}
Expand Down
Loading