chore(release): v1.4.25

Largest feature delta in the v1.4.x line. Insights expands into seven dedicated metric sub-pages; GLP-1 medication tracking lands end-to-end (drug-level chart with Research Mode acknowledgment, EMA titration ladder, cadence + compliance, side-effect taxonomy, pen/vial inventory); cross-source priority becomes a two-axis resolver; per-user timezone threads through ten analytics surfaces; Withings activity + sleep v2 sync; onboarding rebuilt as a nested-route wizard; Personal Records ship end-to-end; Health Score provenance accordion; Coach runs native first-party prompts across six locales with a 1800-assertion refusal-probe matrix; OpenAPI drift gate hard-fails; multi-arch GHCR image. Migrations 0043 through 0060 are additive and forward-only. PROMPT_VERSION 4.24.0 → 4.25.0 with GROUND RULE 9 (refuses dose recommendations) and GROUND RULE 15 (refuses drug-level estimates with MDR + MDCG 2021-24 cites).

See CHANGELOG.md for the full per-section delta.
This commit is contained in:
Marc-André Bombeck authored and GitHub committed 2026-05-14 23:49:32 +02:00
1 parent de0689e419
commit 17b8d8d2c2
528 files changed
+104033 -6524

No files matched your search

@@ -0,0 +1,112 @@
import { describe, expect, it } from "vitest";
import { WideEventBuilder } from "../event-builder";
describe("WideEventBuilder.setHttp", () => {
it("stores plain http metadata as-is", () => {
const evt = new WideEventBuilder("http");
evt.setHttp({
method: "GET",
path: "/api/health",
route: "/api/health",
status: 200,
});
const json = evt.toJSON();
expect(json.http).toMatchObject({
method: "GET",
path: "/api/health",
route: "/api/health",
status: 200,
});
});
// Fix-J (v1.4.25 W21, sec-C1): WITHINGS_WEBHOOK_SECRET lands in
// http.path on every request without this scrub. Verify the redaction
// is applied at setHttp time so the secret never reaches stdout, the
// in-memory ring buffer, or Loki.
it("redacts Withings webhook secret from http.path and http.route", () => {
const evt = new WideEventBuilder("http");
evt.setHttp({
method: "POST",
path: "/api/withings/webhook/test-secret",
route: "/api/withings/webhook/test-secret",
status: 200,
});
const http = evt.toJSON().http;
expect(http?.path).toBe("/api/withings/webhook/[REDACTED]");
expect(http?.route).toBe("/api/withings/webhook/[REDACTED]");
});
it("preserves trailing path segments after the redacted secret", () => {
const evt = new WideEventBuilder("http");
evt.setHttp({
method: "GET",
path: "/api/withings/webhook/sup3r-secr3t/verify",
route: "/api/withings/webhook/[token]/verify",
status: 200,
});
const http = evt.toJSON().http;
expect(http?.path).toBe("/api/withings/webhook/[REDACTED]/verify");
// The Next.js route template `[token]` does not match the
// path-segment rule's `<segment>` shape boundary (the brackets are
// treated as a regular segment), so it is still redacted; either
// shape is acceptable since the goal is to never leak the secret.
expect(http?.route).toBe("/api/withings/webhook/[REDACTED]/verify");
});
it("does not over-redact unrelated paths", () => {
const evt = new WideEventBuilder("http");
evt.setHttp({
method: "GET",
path: "/api/measurements/123",
route: "/api/measurements/[id]",
status: 200,
});
const http = evt.toJSON().http;
expect(http?.path).toBe("/api/measurements/123");
expect(http?.route).toBe("/api/measurements/[id]");
});
it("still scrubs query-string secrets via the existing rule", () => {
const evt = new WideEventBuilder("http");
evt.setHttp({
method: "POST",
path: "/api/withings/webhook?secret=abc123",
route: "/api/withings/webhook",
status: 200,
});
const http = evt.toJSON().http;
expect(http?.path).toBe("/api/withings/webhook?secret=[REDACTED]");
expect(http?.route).toBe("/api/withings/webhook");
});
it("preserves other http fields verbatim", () => {
const evt = new WideEventBuilder("http");
evt.setHttp({
method: "POST",
path: "/api/withings/webhook/leak",
route: "/api/withings/webhook/leak",
status: 200,
user_agent: "WithingsClient/1.0",
ip: "10.0.0.1",
content_length: 42,
response_size: 17,
});
const http = evt.toJSON().http;
expect(http).toMatchObject({
method: "POST",
path: "/api/withings/webhook/[REDACTED]",
route: "/api/withings/webhook/[REDACTED]",
status: 200,
user_agent: "WithingsClient/1.0",
ip: "10.0.0.1",
content_length: 42,
response_size: 17,
});
});
it("handles an undefined http payload without throwing", () => {
const evt = new WideEventBuilder("http");
evt.setHttp(undefined);
expect(evt.toJSON().http).toBeUndefined();
});
});
+72 -1
View File
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
import { redactSecrets, redactOptional } from "../redact";
import { redactSecrets, redactOptional, PATH_SECRET_PATHS } from "../redact";
describe("redactSecrets", () => {
it("redacts Bearer tokens", () => {
@@ -118,6 +118,77 @@ describe("redactSecrets", () => {
"Bearer [REDACTED] bot[REDACTED] ?code=[REDACTED]",
);
});
// v1.4.25 W21 Fix-J: `WITHINGS_WEBHOOK_SECRET` travels as the trailing
// path segment on `/api/withings/webhook/<secret>`. The Wide Event
// builder feeds `http.path` and `http.route` through `redactSecrets`,
// so the path-segment rule must rewrite the secret to `[REDACTED]`
// before stdout / ring-buffer / Loki egress.
describe("path-segment secret redaction", () => {
it("registers the Withings webhook prefix in PATH_SECRET_PATHS", () => {
expect(PATH_SECRET_PATHS.map((entry) => entry.prefix)).toContain(
"/api/withings/webhook/",
);
});
it("redacts the Withings webhook secret segment", () => {
expect(redactSecrets("/api/withings/webhook/test-secret")).toBe(
"/api/withings/webhook/[REDACTED]",
);
expect(
redactSecrets(
"/api/withings/webhook/abc123_DEADBEEF-cafe.0123456789abcdef",
),
).toBe("/api/withings/webhook/[REDACTED]");
});
it("preserves trailing path segments after the secret", () => {
expect(redactSecrets("/api/withings/webhook/test-secret/")).toBe(
"/api/withings/webhook/[REDACTED]/",
);
expect(redactSecrets("/api/withings/webhook/test-secret/verify")).toBe(
"/api/withings/webhook/[REDACTED]/verify",
);
});
it("preserves query strings after the secret segment", () => {
// Note: the existing query-string rule then redacts the
// `?secret=…` payload too; both layers compose.
expect(
redactSecrets("/api/withings/webhook/test-secret?retries=2"),
).toBe("/api/withings/webhook/[REDACTED]?retries=2");
});
it("redacts an absolute URL form (origin + path-segment secret)", () => {
expect(
redactSecrets(
"https://app.healthlog.dev/api/withings/webhook/super-secret",
),
).toBe("https://app.healthlog.dev/api/withings/webhook/[REDACTED]");
});
it("leaves the legacy query-string webhook form alone (no path-segment secret)", () => {
// `/api/withings/webhook` (no trailing segment) keeps shape; the
// `?secret=` rule scrubs the query payload via the existing rule.
expect(redactSecrets("/api/withings/webhook?secret=abc123")).toBe(
"/api/withings/webhook?secret=[REDACTED]",
);
expect(redactSecrets("/api/withings/webhook")).toBe(
"/api/withings/webhook",
);
});
it("does not over-redact sibling routes that share the prefix root", () => {
// Sibling paths (`/api/withings/measure`, `/api/withings/auth`)
// must not match the webhook-specific prefix.
expect(redactSecrets("/api/withings/measure/123")).toBe(
"/api/withings/measure/123",
);
expect(redactSecrets("/api/withings/auth/callback")).toBe(
"/api/withings/auth/callback",
);
});
});
});
describe("redactOptional", () => {
+10
View File
@@ -1,6 +1,7 @@
import { AsyncLocalStorage } from "node:async_hooks";
import type { WideEvent } from "./types";
import { WideEventBuilder } from "./event-builder";
import { registerSourcePriorityParseObserver } from "@/lib/validations/source-priority";
/** AsyncLocalStorage fuer den aktuellen Request-Kontext */
export const eventStorage = new AsyncLocalStorage<WideEventBuilder>();
@@ -27,3 +28,12 @@ export function annotate(fields: {
}
}
}
// v1.4.25 Fix-G — wire the schema-parser breadcrumb into the
// AsyncLocalStorage-backed `annotate()` only on the server. The
// validations module stays bundle-safe for client imports; this side
// effect runs the first time any server module imports the logging
// context.
registerSourcePriorityParseObserver((fields) => {
annotate(fields);
});
+14 -1
View File
@@ -38,7 +38,20 @@ export class WideEventBuilder {
}
setHttp(http: WideEvent["http"]): this {
this.event.http = http;
if (http) {
// Fix-J (v1.4.25 W21): the Withings webhook ships its shared
// secret as a path segment, so `path` and `route` carry the
// secret unless we scrub on the way in. `redactSecrets` is the
// single egress-redaction surface (see redact.ts for the rules
// and the PATH_SECRET_PATHS registry).
this.event.http = {
...http,
path: redactSecrets(http.path),
route: redactSecrets(http.route),
};
} else {
this.event.http = http;
}
return this;
}
+42 -4
View File
@@ -1,8 +1,8 @@
/**
* Redact secrets from strings before they leave the process boundary
* (Loki, Glitchtip, console). Applied in `WideEventBuilder.setError()`
* and `reportToGlitchtip()` so every error reaching observability is
* scrubbed once, centrally.
* (Loki, Glitchtip, console). Applied in `WideEventBuilder.setError()`,
* `WideEventBuilder.setHttp()`, and `reportToGlitchtip()` so every
* value reaching observability is scrubbed once, centrally.
*
* Patterns:
* - `Bearer <token>` — generic API tokens incl. our `hlk_` /
@@ -18,13 +18,51 @@
* - `sk-…` and `sk-ant-…` — OpenAI / Anthropic API keys. We never
* log them on purpose, but a misconfigured client error or a
* dump of the request body could carry one. Scrub before egress.
* - path-segment secrets — routes like `/api/withings/webhook/<secret>`
* carry the shared secret as a positional path segment. The Wide
* Event `http.path` and `http.route` fields would otherwise leak
* the secret into stdout, the in-memory ring buffer, and Loki.
* See `PATH_SECRET_PATHS`.
*
* The substitution is intentionally generic ([REDACTED]) — we don't
* want partial revelation of token entropy.
*/
/**
* Registry of path prefixes where the trailing segment is a shared
* secret. Each entry's `prefix` must end with `/`; any non-empty
* segment after it is rewritten to `[REDACTED]`. Subsequent path
* segments are preserved (so `/foo/<secret>/bar` becomes
* `/foo/[REDACTED]/bar`).
*
* Add a new entry whenever a route exposes a secret in its URL path
* (rather than headers, body, or query). Tested in `redact.test.ts`.
*/
export const PATH_SECRET_PATHS: ReadonlyArray<{ prefix: string }> = [
// Withings webhook entrypoint: `WITHINGS_WEBHOOK_SECRET` travels as
// the trailing path segment (v1.4.25 W17a). Without this rule the
// secret lands in every Wide Event's `http.path` / `http.route`.
{ prefix: "/api/withings/webhook/" },
];
function redactPathSegments(input: string): string {
let out = input;
for (const { prefix } of PATH_SECRET_PATHS) {
// Match `<prefix><segment>` where `<segment>` is one or more
// non-`/` non-`?` chars, then preserve anything after (next path
// segment, query string, hash). Capture group 1 is the optional
// trailing context starting with `/`, `?`, or `#`.
const escaped = prefix.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
const re = new RegExp(`${escaped}[^/?#\\s]+([/?#][^\\s]*)?`, "g");
out = out.replace(re, (_match, tail: string | undefined) => {
return `${prefix}[REDACTED]${tail ?? ""}`;
});
}
return out;
}
export function redactSecrets(input: string): string {
return (
input
redactPathSegments(input)
.replace(/Bearer\s+\S+/gi, "Bearer [REDACTED]")
.replace(/bot\d+:[A-Za-z0-9_-]+/g, "bot[REDACTED]")
// `sk-` is a common English-prefix substring (task-force, risk-