Skip to content
Draft
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
9 changes: 5 additions & 4 deletions src/lab/artifacts/sanitize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,12 @@ const WEAK_HOST_CONTEXT_RE =
/\b(?:upstream)["']?\s*[\s=:]\s*["']?([A-Za-z0-9_.-]{1,255})/gi;

/**
* A dotted run of plain alphabetic words with no digits or hyphens in any
* label — `provider.metric.p95` reads as a namespace, not a host. Under a
* WEAK marker this is left alone; under a STRONG one the marker decides.
* A dotted run of plain alphabetic words, or the conventional
* `<name>.metric.p<digits>` shape, reads as a namespace rather than a host.
* Other digit-suffixed labels are host-shaped and must not receive this weak
* marker exemption. Under a STRONG marker the marker always decides.
*/
const DOTTED_NAMESPACE_RE = /^[a-z]+(?:\.[a-z]+)*\.[a-z]+[0-9]*$/i;
const DOTTED_NAMESPACE_RE = /^(?:[a-z]+(?:\.[a-z]+)+|[a-z]+(?:\.[a-z]+)*\.metric\.p[0-9]+)$/i;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Handle a trailing dot before validating upstream hosts

When a digit-suffixed host ends the diagnostic or uses FQDN root notation, such as upstream api.v2., WEAK_HOST_CONTEXT_RE includes the terminal dot in name; CONTEXTUAL_HOST_TOKEN_RE then rejects the candidate, so this new predicate is never consulted and the raw hostname is persisted. Strip and preserve a terminal punctuation/root dot before applying the predicates, or adjust the capture so the host candidate excludes it, and add this form to the regression test.

AGENTS.md reference: AGENTS.md:L233-L234

Useful? React with 👍 / 👎.


/**
* Does this token look like a host rather than an English word?
Expand Down
4 changes: 4 additions & 0 deletions tests/lab-evidence-sanitization.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ describe("SEC-02 sanitizer boundary", () => {
.toBe("dial tcp [host]:443: connect: refused");
expect(sanitizeDiagnostic("upstream api.us-east-1 unavailable"))
.toBe("upstream [host] unavailable");
for (const host of ["internal.service1", "db.prod1", "api.v2"]) {
expect(sanitizeDiagnostic(`upstream ${host} unavailable`))
.toBe("upstream [host] unavailable");
}
// Without such a marker they survive — a recorded limit, asserted so it
// cannot drift silently in either direction.
expect(sanitizeDiagnostic("db.prod-1")).toBe("db.prod-1");
Expand Down
Loading