fix(ingest): normalize unicode hyphens for BIT-SMOKE noise (ruleset 1.0.5)
CRM /smoke/crm.php BIT-SMOKE-CRM-DIRECT-FWD and similar probes can carry unicode hyphen/minus characters; normalize before substring scan so bitreport_smoke_marker still matches (BIT-933). Paperclip-Issue: BIT-933 Paperclip-Run: 699684ed-75aa-4850-81a0-84bd717627e7
This commit is contained in:
1 parent
c92309a3c4
commit
70d52e1efc
4 files changed
+83
-4
No files matched your search
@@ -32,7 +32,7 @@ Per-key overrides: set `rate_limit_max` and/or `rate_limit_window_ms` on the key
|
||||
|
||||
- Rules live in `ingest-api/src/lib/noisePolicy.ts`; ruleset id: `noise_ruleset_version` in the ingest response.
|
||||
- **Check:** send a known-noise payload (for example ResizeObserver message at non-fatal level); expect `skipped: true`, `noise_filtered_count` incremented, and no new `er_incidents` row.
|
||||
- **Check:** send the same pattern at `fatal` / `critical` level; expect **not** skipped (noise rules do not hide critical), **except** when the **message** or **client-provided stacktrace** contains reserved substring `BIT-SMOKE-` (intentional reporter smoke, e.g. wdmi-store `/smoke/wdmi.js`, CRM `/smoke/crm-main.php`) — those are skipped at every level (`rule_id`: `bitreport_smoke_marker`). The exact deploy-probe failure ribbon `BIT-SMOKE error hub ingest live check` (space after `BIT-SMOKE`, see [RUNBOOK_INGEST_DEBUG.md](../RUNBOOK_INGEST_DEBUG.md) §0) is also skipped at every level with the same `rule_id`.
|
||||
- **Check:** send the same pattern at `fatal` / `critical` level; expect **not** skipped (noise rules do not hide critical), **except** when the **message** or **client-provided stacktrace** contains reserved substring `BIT-SMOKE-` (intentional reporter smoke, e.g. wdmi-store `/smoke/wdmi.js`, CRM `/smoke/crm-main.php`, CRM `/smoke/crm.php` direct-forward `BIT-SMOKE-CRM-DIRECT-FWD`) — those are skipped at every level (`rule_id`: `bitreport_smoke_marker`). Matching treats unicode hyphen/minus characters as ASCII `-` (ruleset **1.0.5+**). The exact deploy-probe failure ribbon `BIT-SMOKE error hub ingest live check` (space after `BIT-SMOKE`, see [RUNBOOK_INGEST_DEBUG.md](../RUNBOOK_INGEST_DEBUG.md) §0) is also skipped at every level with the same `rule_id`.
|
||||
|
||||
## Rate limits
|
||||
|
||||
|
||||
@@ -295,6 +295,44 @@ describe.skipIf(!_testUrl)("two-project passive ingest (BIT-179)", () => {
|
||||
expect(Number((after[0] as { c: number }).c)).toBe(_nBefore);
|
||||
});
|
||||
|
||||
it("skips BIT-SMOKE-CRM-DIRECT-FWD from /smoke/crm.php without inserting rows (BIT-933)", async () => {
|
||||
const [before] = await _pool.execute<RowDataPacket[]>(
|
||||
`SELECT COUNT(*) AS c FROM er_incidents WHERE project_id = ?`,
|
||||
[_projectIdA],
|
||||
);
|
||||
const _nBefore = Number((before[0] as { c: number }).c);
|
||||
const _res = await _app.inject({
|
||||
method: "POST",
|
||||
url: "/v1/ingest/events",
|
||||
headers: { authorization: `Bearer ${_tokenA}` },
|
||||
payload: {
|
||||
events: [
|
||||
{
|
||||
schema_version: 1,
|
||||
occurred_at: "2026-04-05T10:07:00.000Z",
|
||||
level: "error",
|
||||
message: "BIT-SMOKE-CRM-DIRECT-FWD",
|
||||
stack_trace: "Error: BIT-SMOKE-CRM-DIRECT-FWD\n#0 smoke",
|
||||
context: { file_path: "/smoke/crm.php", line_number: "1" },
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
expect(_res.statusCode).toBe(200);
|
||||
const _body = JSON.parse(_res.body) as {
|
||||
noise_filtered_count: number;
|
||||
results: Array<{ skipped?: boolean; rule_id?: string }>;
|
||||
};
|
||||
expect(_body.noise_filtered_count).toBe(1);
|
||||
expect(_body.results[0]?.skipped).toBe(true);
|
||||
expect(_body.results[0]?.rule_id).toBe("bitreport_smoke_marker");
|
||||
const [after] = await _pool.execute<RowDataPacket[]>(
|
||||
`SELECT COUNT(*) AS c FROM er_incidents WHERE project_id = ?`,
|
||||
[_projectIdA],
|
||||
);
|
||||
expect(Number((after[0] as { c: number }).c)).toBe(_nBefore);
|
||||
});
|
||||
|
||||
it("skips deploy ingest live-check failure ribbon without inserting rows", async () => {
|
||||
const [before] = await _pool.execute<RowDataPacket[]>(
|
||||
`SELECT COUNT(*) AS c FROM er_incidents WHERE project_id = ?`,
|
||||
|
||||
@@ -116,6 +116,33 @@ describe("evaluateNoise", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("matches BIT-SMOKE-CRM-DIRECT-FWD message (BIT-933 / crm.php forward)", () => {
|
||||
const _r = evaluateNoise({
|
||||
level: "error",
|
||||
message: "BIT-SMOKE-CRM-DIRECT-FWD",
|
||||
stackText: "Error: BIT-SMOKE-CRM-DIRECT-FWD\n#0 smoke",
|
||||
filePathHint: "/smoke/crm.php",
|
||||
});
|
||||
expect(_r).toEqual({
|
||||
matched: true,
|
||||
ruleId: "bitreport_smoke_marker",
|
||||
reason: "filtered_intentional_smoke_event",
|
||||
});
|
||||
});
|
||||
|
||||
it("matches BIT-SMOKE marker when hyphen is unicode non-breaking hyphen (U+2011)", () => {
|
||||
const _r = evaluateNoise({
|
||||
level: "error",
|
||||
message: "BIT\u2011SMOKE\u2011CRM\u2011DIRECT\u2011FWD",
|
||||
filePathHint: "",
|
||||
});
|
||||
expect(_r).toEqual({
|
||||
matched: true,
|
||||
ruleId: "bitreport_smoke_marker",
|
||||
reason: "filtered_intentional_smoke_event",
|
||||
});
|
||||
});
|
||||
|
||||
it("matches wdmi-store / CRM deploy ingest live-check failure ribbon (BIT-931 family)", () => {
|
||||
const _r = evaluateNoise({
|
||||
level: "critical",
|
||||
|
||||
@@ -4,12 +4,24 @@ import { normalizeLevelToSeverity } from "./normalize.js";
|
||||
* Versioned ruleset id (document in release notes when rules change).
|
||||
* Rule inventory and validation steps: `docs/operations/ingest-hardening-runbook.md`.
|
||||
*/
|
||||
export const NOISE_RULESET_VERSION = "1.0.4";
|
||||
export const NOISE_RULESET_VERSION = "1.0.5";
|
||||
|
||||
export type NoiseEvaluation =
|
||||
| { matched: false }
|
||||
| { matched: true; ruleId: string; reason: string };
|
||||
|
||||
const _DEPLOY_INGEST_PROBE_MESSAGE = "BIT-SMOKE error hub ingest live check";
|
||||
|
||||
/**
|
||||
* CRM / editor copy-paste sometimes inserts unicode hyphens (U+2011 etc.) in the reserved
|
||||
* `BIT-SMOKE-` token; strip ZW* / BOM so probes still match `bitreport_smoke_marker` (BIT-933).
|
||||
*/
|
||||
function normalizeAsciiForSmokeMarkerScan(text: string): string {
|
||||
return text
|
||||
.replace(/\u2010|\u2011|\u2012|\u2013|\u2014|\u2212|\ufe63|\uff0d/g, "-")
|
||||
.replace(/[\u200B-\u200D\uFEFF]/g, "");
|
||||
}
|
||||
|
||||
type NoiseRule = {
|
||||
id: string;
|
||||
reason: string;
|
||||
@@ -145,14 +157,16 @@ export function evaluateNoise(input: {
|
||||
}): NoiseEvaluation {
|
||||
const _msg = input.message.trim();
|
||||
const _stack = (input.stackText ?? "").trim();
|
||||
if (_msg === "BIT-SMOKE error hub ingest live check") {
|
||||
const _msgSmoke = normalizeAsciiForSmokeMarkerScan(_msg);
|
||||
const _stackSmoke = normalizeAsciiForSmokeMarkerScan(_stack);
|
||||
if (_msgSmoke === normalizeAsciiForSmokeMarkerScan(_DEPLOY_INGEST_PROBE_MESSAGE)) {
|
||||
return {
|
||||
matched: true,
|
||||
ruleId: "bitreport_smoke_marker",
|
||||
reason: "filtered_deploy_ingest_probe_failure",
|
||||
};
|
||||
}
|
||||
if (_msg.includes("BIT-SMOKE-") || _stack.includes("BIT-SMOKE-")) {
|
||||
if (_msgSmoke.includes("BIT-SMOKE-") || _stackSmoke.includes("BIT-SMOKE-")) {
|
||||
return {
|
||||
matched: true,
|
||||
ruleId: "bitreport_smoke_marker",
|
||||
|
||||
Reference in new issue
Block a user