@routr/common 2.17.0 → 2.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/dist/connect/config.d.ts +5 -1
  2. package/dist/connect/mappers/agent.js +1 -0
  3. package/dist/connect/mappers/domain.js +1 -0
  4. package/dist/connect/mappers/peer.js +1 -0
  5. package/dist/connect/mappers/trunk.js +1 -0
  6. package/dist/connect/protos/agents.proto +7 -0
  7. package/dist/connect/protos/domains.proto +7 -0
  8. package/dist/connect/protos/peers.proto +7 -0
  9. package/dist/connect/protos/trace.proto +28 -0
  10. package/dist/connect/protos/trunks.proto +7 -0
  11. package/dist/connect/schemas/agent.d.ts +10 -0
  12. package/dist/connect/schemas/agent.js +8 -0
  13. package/dist/connect/schemas/domain.d.ts +10 -0
  14. package/dist/connect/schemas/domain.js +8 -0
  15. package/dist/connect/schemas/peer.d.ts +10 -0
  16. package/dist/connect/schemas/peer.js +8 -0
  17. package/dist/connect/schemas/trunk.d.ts +10 -0
  18. package/dist/connect/schemas/trunk.js +8 -0
  19. package/dist/connect/types.d.ts +7 -0
  20. package/dist/errors.d.ts +14 -0
  21. package/dist/errors.js +19 -1
  22. package/dist/helper.js +2 -1
  23. package/dist/index.d.ts +1 -0
  24. package/dist/index.js +2 -1
  25. package/dist/protos/processor.proto +4 -0
  26. package/dist/trace/compat.d.ts +37 -0
  27. package/dist/trace/compat.js +131 -0
  28. package/dist/trace/diff.d.ts +48 -0
  29. package/dist/trace/diff.js +152 -0
  30. package/dist/trace/index.d.ts +11 -0
  31. package/dist/trace/index.js +68 -0
  32. package/dist/trace/metadata.d.ts +28 -0
  33. package/dist/trace/metadata.js +75 -0
  34. package/dist/trace/normalize.d.ts +11 -0
  35. package/dist/trace/normalize.js +39 -0
  36. package/dist/trace/redact.d.ts +19 -0
  37. package/dist/trace/redact.js +52 -0
  38. package/dist/trace/rules/facts.d.ts +43 -0
  39. package/dist/trace/rules/facts.js +117 -0
  40. package/dist/trace/rules/index.d.ts +34 -0
  41. package/dist/trace/rules/index.js +153 -0
  42. package/dist/trace/rules/sip/ack-2xx.d.ts +2 -0
  43. package/dist/trace/rules/sip/ack-2xx.js +56 -0
  44. package/dist/trace/rules/sip/cancel-matches.d.ts +2 -0
  45. package/dist/trace/rules/sip/cancel-matches.js +46 -0
  46. package/dist/trace/rules/sip/credentials-stripped.d.ts +2 -0
  47. package/dist/trace/rules/sip/credentials-stripped.js +41 -0
  48. package/dist/trace/rules/sip/cseq-ack.d.ts +2 -0
  49. package/dist/trace/rules/sip/cseq-ack.js +40 -0
  50. package/dist/trace/rules/sip/cseq-monotonic.d.ts +2 -0
  51. package/dist/trace/rules/sip/cseq-monotonic.js +50 -0
  52. package/dist/trace/rules/sip/max-forwards.d.ts +2 -0
  53. package/dist/trace/rules/sip/max-forwards.js +47 -0
  54. package/dist/trace/rules/sip/private-address.d.ts +2 -0
  55. package/dist/trace/rules/sip/private-address.js +48 -0
  56. package/dist/trace/rules/sip/record-route-self.d.ts +2 -0
  57. package/dist/trace/rules/sip/record-route-self.js +46 -0
  58. package/dist/trace/rules/sip/register-ok.d.ts +2 -0
  59. package/dist/trace/rules/sip/register-ok.js +52 -0
  60. package/dist/trace/rules/sip/retransmission.d.ts +2 -0
  61. package/dist/trace/rules/sip/retransmission.js +47 -0
  62. package/dist/trace/rules/sip/route-self-removed.d.ts +2 -0
  63. package/dist/trace/rules/sip/route-self-removed.js +38 -0
  64. package/dist/trace/rules/sip/via.d.ts +2 -0
  65. package/dist/trace/rules/sip/via.js +50 -0
  66. package/dist/trace/rules/sip-connect/from-e164-or-anonymous.d.ts +2 -0
  67. package/dist/trace/rules/sip-connect/from-e164-or-anonymous.js +43 -0
  68. package/dist/trace/rules/sip-connect/pai-e164.d.ts +2 -0
  69. package/dist/trace/rules/sip-connect/pai-e164.js +44 -0
  70. package/dist/trace/rules/sip-connect/pai-single.d.ts +2 -0
  71. package/dist/trace/rules/sip-connect/pai-single.js +41 -0
  72. package/dist/trace/rules/sip-connect/privacy.d.ts +2 -0
  73. package/dist/trace/rules/sip-connect/privacy.js +50 -0
  74. package/dist/trace/rules/sip-connect/request-uri-e164.d.ts +2 -0
  75. package/dist/trace/rules/sip-connect/request-uri-e164.js +44 -0
  76. package/dist/trace/rules/sip-connect/scope.d.ts +11 -0
  77. package/dist/trace/rules/sip-connect/scope.js +19 -0
  78. package/dist/trace/rules/types.d.ts +34 -0
  79. package/dist/trace/rules/types.js +13 -0
  80. package/dist/trace/sanitize.d.ts +40 -0
  81. package/dist/trace/sanitize.js +85 -0
  82. package/dist/trace/schema.d.ts +338 -0
  83. package/dist/trace/schema.js +197 -0
  84. package/dist/trace/status.d.ts +15 -0
  85. package/dist/trace/status.js +102 -0
  86. package/dist/trace/types.d.ts +126 -0
  87. package/dist/trace/types.js +82 -0
  88. package/dist/trace/validate.d.ts +56 -0
  89. package/dist/trace/validate.js +140 -0
  90. package/dist/types.d.ts +2 -0
  91. package/package.json +2 -2
@@ -0,0 +1,43 @@
1
+ import { MessageRequest, SIPMessage, Via } from "../../types";
2
+ import { TraceRecord } from "../types";
3
+ export declare const inbound: (r: TraceRecord) => SIPMessage;
4
+ export declare const outbound: (r: TraceRecord) => SIPMessage | undefined;
5
+ export declare const isRequest: (r: TraceRecord) => boolean;
6
+ export declare const isResponse: (r: TraceRecord) => boolean;
7
+ export declare const isForwarded: (r: TraceRecord) => boolean;
8
+ export declare const isRelayed: (r: TraceRecord) => boolean;
9
+ export declare const isInDialog: (r: TraceRecord) => boolean;
10
+ export declare const statusOf: (r: TraceRecord) => number | undefined;
11
+ export declare const headerValues: (m: SIPMessage | undefined, name: string) => string[];
12
+ export declare const cseqOf: (m: SIPMessage | undefined) => {
13
+ number: number;
14
+ method: string;
15
+ } | undefined;
16
+ export declare const topVia: (m: SIPMessage | undefined) => Via | undefined;
17
+ export declare const topBranch: (m: SIPMessage | undefined) => string | undefined;
18
+ export declare const isExternalHost: (req: MessageRequest, host?: string) => boolean;
19
+ /**
20
+ * Whether a host is one of the proxy's own internal interfaces: a listening
21
+ * point, the socket the message came in on, or an address in localnets.
22
+ *
23
+ * @param {MessageRequest} req - The recorded request
24
+ * @param {string} host - Host to test
25
+ * @return {boolean} True for an internal interface
26
+ */
27
+ export declare const isInternalHost: (req: MessageRequest, host?: string) => boolean;
28
+ export declare const isOwnHost: (req: MessageRequest, host?: string) => boolean;
29
+ export declare const requestsIn: (call: TraceRecord[]) => TraceRecord[];
30
+ /**
31
+ * Identifies the party that sent a request: its From URI and tag. Both are
32
+ * needed, a SIPp-style endpoint may use the same tag on both sides.
33
+ *
34
+ * @param {TraceRecord} r - A request record
35
+ * @return {string} A key equal for every request from the same party
36
+ */
37
+ export declare const directionOf: (r: TraceRecord) => string;
38
+ export declare const isE164: (user?: string) => boolean;
39
+ export declare const uriOf: (value: string) => {
40
+ user?: string;
41
+ host?: string;
42
+ params: string;
43
+ } | undefined;
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.uriOf = exports.isE164 = exports.directionOf = exports.requestsIn = exports.isOwnHost = exports.isInternalHost = exports.isExternalHost = exports.topBranch = exports.topVia = exports.cseqOf = exports.headerValues = exports.statusOf = exports.isInDialog = exports.isRelayed = exports.isForwarded = exports.isResponse = exports.isRequest = exports.outbound = exports.inbound = void 0;
4
+ const types_1 = require("../types");
5
+ const status_1 = require("../status");
6
+ /*
7
+ * Facts a rule may read: the SIP messages, the processor contract fields
8
+ * (sender, listening points, external addresses, localnets, receivedOn)
9
+ * and what the dispatcher measured. Never a hop's metadata.
10
+ */
11
+ const inbound = (r) => r.request.message;
12
+ exports.inbound = inbound;
13
+ const outbound = (r) => { var _a; return (_a = r.response) === null || _a === void 0 ? void 0 : _a.message; };
14
+ exports.outbound = outbound;
15
+ const isRequest = (r) => r.kind === types_1.TraceKind.REQUEST;
16
+ exports.isRequest = isRequest;
17
+ const isResponse = (r) => r.kind === types_1.TraceKind.RESPONSE;
18
+ exports.isResponse = isResponse;
19
+ const isForwarded = (r) => (0, exports.isRequest)(r) && r.outcome === types_1.TraceOutcome.FORWARDED && !!r.response;
20
+ exports.isForwarded = isForwarded;
21
+ const isRelayed = (r) => (0, exports.isResponse)(r) && r.outcome === types_1.TraceOutcome.RELAYED && !!r.response;
22
+ exports.isRelayed = isRelayed;
23
+ const isInDialog = (r) => { var _a; return !!((_a = (0, exports.inbound)(r).to) === null || _a === void 0 ? void 0 : _a.tag); };
24
+ exports.isInDialog = isInDialog;
25
+ const statusOf = (r) => {
26
+ var _a, _b;
27
+ return (_a = r.status) !== null && _a !== void 0 ? _a : (0, status_1.statusCodeOf)((0, exports.isResponse)(r) ? (0, exports.inbound)(r).responseType : (_b = (0, exports.outbound)(r)) === null || _b === void 0 ? void 0 : _b.responseType);
28
+ };
29
+ exports.statusOf = statusOf;
30
+ const headerValues = (m, name) => ((m === null || m === void 0 ? void 0 : m.extensions) || [])
31
+ .filter((e) => e.name.toLowerCase() === name.toLowerCase())
32
+ .map((e) => e.value);
33
+ exports.headerValues = headerValues;
34
+ const cseqOf = (m) => {
35
+ const raw = (0, exports.headerValues)(m, "CSeq")[0];
36
+ if (!raw)
37
+ return undefined;
38
+ const [n, method] = raw.trim().split(/\s+/);
39
+ const number = parseInt(n, 10);
40
+ return isNaN(number) ? undefined : { number, method: method || "" };
41
+ };
42
+ exports.cseqOf = cseqOf;
43
+ const topVia = (m) => { var _a; return (_a = m === null || m === void 0 ? void 0 : m.via) === null || _a === void 0 ? void 0 : _a[0]; };
44
+ exports.topVia = topVia;
45
+ const topBranch = (m) => { var _a; return (_a = (0, exports.topVia)(m)) === null || _a === void 0 ? void 0 : _a.branch; };
46
+ exports.topBranch = topBranch;
47
+ const isExternalHost = (req, host) => !!host && (req.externalAddrs || []).includes(host);
48
+ exports.isExternalHost = isExternalHost;
49
+ /**
50
+ * Whether a host is one of the proxy's own internal interfaces: a listening
51
+ * point, the socket the message came in on, or an address in localnets.
52
+ *
53
+ * @param {MessageRequest} req - The recorded request
54
+ * @param {string} host - Host to test
55
+ * @return {boolean} True for an internal interface
56
+ */
57
+ const isInternalHost = (req, host) => {
58
+ var _a;
59
+ return !!host &&
60
+ ((req.listeningPoints || []).some((lp) => lp.host === host) ||
61
+ ((_a = req.receivedOn) === null || _a === void 0 ? void 0 : _a.host) === host ||
62
+ (req.localnets || []).some((net) => inNet(host, net)));
63
+ };
64
+ exports.isInternalHost = isInternalHost;
65
+ const isOwnHost = (req, host) => (0, exports.isExternalHost)(req, host) || (0, exports.isInternalHost)(req, host);
66
+ exports.isOwnHost = isOwnHost;
67
+ const inNet = (host, net) => {
68
+ const [base, bitsRaw] = net.split("/");
69
+ const bits = bitsRaw === undefined ? 32 : parseInt(bitsRaw, 10);
70
+ const a = ipv4(host);
71
+ const b = ipv4(base);
72
+ if (a === undefined || b === undefined || isNaN(bits))
73
+ return host === base;
74
+ const mask = bits === 0 ? 0 : (~0 << (32 - bits)) >>> 0;
75
+ return (a & mask) >>> 0 === (b & mask) >>> 0;
76
+ };
77
+ const ipv4 = (s) => {
78
+ const parts = s.split(".");
79
+ if (parts.length !== 4)
80
+ return undefined;
81
+ let n = 0;
82
+ // eslint-disable-next-line no-loops/no-loops
83
+ for (const p of parts) {
84
+ const v = parseInt(p, 10);
85
+ if (isNaN(v) || v < 0 || v > 255)
86
+ return undefined;
87
+ n = (n << 8) | v;
88
+ }
89
+ return n >>> 0;
90
+ };
91
+ const requestsIn = (call) => call.filter(exports.isRequest);
92
+ exports.requestsIn = requestsIn;
93
+ /**
94
+ * Identifies the party that sent a request: its From URI and tag. Both are
95
+ * needed, a SIPp-style endpoint may use the same tag on both sides.
96
+ *
97
+ * @param {TraceRecord} r - A request record
98
+ * @return {string} A key equal for every request from the same party
99
+ */
100
+ const directionOf = (r) => {
101
+ var _a, _b, _c, _d;
102
+ const from = (0, exports.inbound)(r).from;
103
+ const uri = (_a = from === null || from === void 0 ? void 0 : from.address) === null || _a === void 0 ? void 0 : _a.uri;
104
+ return `${(_b = uri === null || uri === void 0 ? void 0 : uri.user) !== null && _b !== void 0 ? _b : ""}@${(_c = uri === null || uri === void 0 ? void 0 : uri.host) !== null && _c !== void 0 ? _c : ""};${(_d = from === null || from === void 0 ? void 0 : from.tag) !== null && _d !== void 0 ? _d : ""}`;
105
+ };
106
+ exports.directionOf = directionOf;
107
+ // Whether an E.164 number: a plus sign and 7 to 15 digits
108
+ const isE164 = (user) => !!user && /^\+[1-9][0-9]{6,14}$/.test(user);
109
+ exports.isE164 = isE164;
110
+ // Parses `<sip:user@host;params>` or `sip:user@host` out of a header value
111
+ const uriOf = (value) => {
112
+ const m = /<?sips?:(?:([^@>;]*)@)?([^>;?]*)([^>]*)>?/.exec(value);
113
+ if (!m)
114
+ return undefined;
115
+ return { user: m[1], host: m[2], params: m[3] || "" };
116
+ };
117
+ exports.uriOf = uriOf;
@@ -0,0 +1,34 @@
1
+ import { Finding, Profile, TraceRecord } from "../types";
2
+ import { EvaluateOptions, Rule } from "./types";
3
+ export * from "./types";
4
+ export * as Facts from "./facts";
5
+ export { towardServiceProvider } from "./sip-connect/scope";
6
+ export declare const RULESET_VERSION: string;
7
+ /** Every rule, in evaluation order. */
8
+ export declare const RULES: ReadonlyArray<Rule>;
9
+ export declare const DEFAULT_PROFILES: Profile[];
10
+ /**
11
+ * Returns the rules of the given profiles.
12
+ *
13
+ * @param {Profile[]} profiles - Profiles to evaluate
14
+ * @return {Rule[]} The matching rules
15
+ */
16
+ export declare function rulesFor(profiles: Profile[]): Rule[];
17
+ /**
18
+ * Evaluates the rules of the given profiles on one record.
19
+ *
20
+ * @param {TraceRecord} record - The record
21
+ * @param {TraceRecord[]} call - Earlier records of the same call, oldest first
22
+ * @param {EvaluateOptions} options - Which profiles to evaluate
23
+ * @return {Finding[]} The findings, errors first
24
+ */
25
+ export declare function evaluate(record: TraceRecord, call: TraceRecord[], options?: EvaluateOptions): Finding[];
26
+ /**
27
+ * Evaluates every record of a call in order, each with the records before
28
+ * it as context.
29
+ *
30
+ * @param {TraceRecord[]} records - The whole call, oldest first
31
+ * @param {EvaluateOptions} options - Which profiles to evaluate
32
+ * @return {Map<number, Finding[]>} Findings by record seq (only non-empty)
33
+ */
34
+ export declare function evaluateAll(records: TraceRecord[], options?: EvaluateOptions): Map<number, Finding[]>;
@@ -0,0 +1,153 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
19
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
20
+ };
21
+ var __importStar = (this && this.__importStar) || (function () {
22
+ var ownKeys = function(o) {
23
+ ownKeys = Object.getOwnPropertyNames || function (o) {
24
+ var ar = [];
25
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
26
+ return ar;
27
+ };
28
+ return ownKeys(o);
29
+ };
30
+ return function (mod) {
31
+ if (mod && mod.__esModule) return mod;
32
+ var result = {};
33
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
34
+ __setModuleDefault(result, mod);
35
+ return result;
36
+ };
37
+ })();
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.DEFAULT_PROFILES = exports.RULES = exports.RULESET_VERSION = exports.towardServiceProvider = exports.Facts = void 0;
43
+ exports.rulesFor = rulesFor;
44
+ exports.evaluate = evaluate;
45
+ exports.evaluateAll = evaluateAll;
46
+ /*
47
+ * Copyright (C) 2026 by Fonoster Inc (https://fonoster.com)
48
+ * http://github.com/fonoster/routr
49
+ *
50
+ * This file is part of Routr.
51
+ *
52
+ * Licensed under the MIT License (the "License");
53
+ * you may not use this file except in compliance with
54
+ * the License. You may obtain a copy of the License at
55
+ *
56
+ * https://opensource.org/licenses/MIT
57
+ *
58
+ * Unless required by applicable law or agreed to in writing, software
59
+ * distributed under the License is distributed on an "AS IS" BASIS,
60
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
61
+ * See the License for the specific language governing permissions and
62
+ * limitations under the License.
63
+ */
64
+ const types_1 = require("../types");
65
+ const max_forwards_1 = __importDefault(require("./sip/max-forwards"));
66
+ const via_1 = __importDefault(require("./sip/via"));
67
+ const record_route_self_1 = __importDefault(require("./sip/record-route-self"));
68
+ const route_self_removed_1 = __importDefault(require("./sip/route-self-removed"));
69
+ const credentials_stripped_1 = __importDefault(require("./sip/credentials-stripped"));
70
+ const private_address_1 = __importDefault(require("./sip/private-address"));
71
+ const register_ok_1 = __importDefault(require("./sip/register-ok"));
72
+ const cseq_ack_1 = __importDefault(require("./sip/cseq-ack"));
73
+ const cseq_monotonic_1 = __importDefault(require("./sip/cseq-monotonic"));
74
+ const cancel_matches_1 = __importDefault(require("./sip/cancel-matches"));
75
+ const ack_2xx_1 = __importDefault(require("./sip/ack-2xx"));
76
+ const retransmission_1 = __importDefault(require("./sip/retransmission"));
77
+ const pai_single_1 = __importDefault(require("./sip-connect/pai-single"));
78
+ const pai_e164_1 = __importDefault(require("./sip-connect/pai-e164"));
79
+ const request_uri_e164_1 = __importDefault(require("./sip-connect/request-uri-e164"));
80
+ const from_e164_or_anonymous_1 = __importDefault(require("./sip-connect/from-e164-or-anonymous"));
81
+ const privacy_1 = __importDefault(require("./sip-connect/privacy"));
82
+ __exportStar(require("./types"), exports);
83
+ exports.Facts = __importStar(require("./facts"));
84
+ var scope_1 = require("./sip-connect/scope");
85
+ Object.defineProperty(exports, "towardServiceProvider", { enumerable: true, get: function () { return scope_1.towardServiceProvider; } });
86
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
87
+ exports.RULESET_VERSION = require("../../../package.json").version;
88
+ /** Every rule, in evaluation order. */
89
+ exports.RULES = [
90
+ max_forwards_1.default,
91
+ via_1.default,
92
+ record_route_self_1.default,
93
+ route_self_removed_1.default,
94
+ credentials_stripped_1.default,
95
+ private_address_1.default,
96
+ register_ok_1.default,
97
+ cseq_ack_1.default,
98
+ cseq_monotonic_1.default,
99
+ cancel_matches_1.default,
100
+ ack_2xx_1.default,
101
+ retransmission_1.default,
102
+ pai_single_1.default,
103
+ pai_e164_1.default,
104
+ request_uri_e164_1.default,
105
+ from_e164_or_anonymous_1.default,
106
+ privacy_1.default
107
+ ];
108
+ exports.DEFAULT_PROFILES = [types_1.Profile.SIP];
109
+ /**
110
+ * Returns the rules of the given profiles.
111
+ *
112
+ * @param {Profile[]} profiles - Profiles to evaluate
113
+ * @return {Rule[]} The matching rules
114
+ */
115
+ function rulesFor(profiles) {
116
+ return exports.RULES.filter((r) => profiles.includes(r.profile));
117
+ }
118
+ /**
119
+ * Evaluates the rules of the given profiles on one record.
120
+ *
121
+ * @param {TraceRecord} record - The record
122
+ * @param {TraceRecord[]} call - Earlier records of the same call, oldest first
123
+ * @param {EvaluateOptions} options - Which profiles to evaluate
124
+ * @return {Finding[]} The findings, errors first
125
+ */
126
+ function evaluate(record, call, options = { profiles: exports.DEFAULT_PROFILES }) {
127
+ const ctx = { record, call };
128
+ const findings = rulesFor(options.profiles).flatMap((rule) => {
129
+ const fail = (message, side = "out", header) => (Object.assign({ rule: rule.id, profile: rule.profile, severity: rule.severity, spec: rule.spec, message,
130
+ side }, (header ? { header } : {})));
131
+ const result = rule.check(ctx, fail);
132
+ return result ? (Array.isArray(result) ? result : [result]) : [];
133
+ });
134
+ return findings.sort((a, b) => rank(a) - rank(b));
135
+ }
136
+ /**
137
+ * Evaluates every record of a call in order, each with the records before
138
+ * it as context.
139
+ *
140
+ * @param {TraceRecord[]} records - The whole call, oldest first
141
+ * @param {EvaluateOptions} options - Which profiles to evaluate
142
+ * @return {Map<number, Finding[]>} Findings by record seq (only non-empty)
143
+ */
144
+ function evaluateAll(records, options = { profiles: exports.DEFAULT_PROFILES }) {
145
+ const out = new Map();
146
+ records.forEach((record, i) => {
147
+ const findings = evaluate(record, records.slice(0, i), options);
148
+ if (findings.length)
149
+ out.set(record.seq, findings);
150
+ });
151
+ return out;
152
+ }
153
+ const rank = (f) => (f.severity === "error" ? 0 : 1);
@@ -0,0 +1,2 @@
1
+ declare const _default: import("../types").Rule;
2
+ export default _default;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /*
4
+ * Copyright (C) 2026 by Fonoster Inc (https://fonoster.com)
5
+ * http://github.com/fonoster/routr
6
+ *
7
+ * This file is part of Routr.
8
+ *
9
+ * Licensed under the MIT License (the "License");
10
+ * you may not use this file except in compliance with
11
+ * the License. You may obtain a copy of the License at
12
+ *
13
+ * https://opensource.org/licenses/MIT
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software
16
+ * distributed under the License is distributed on an "AS IS" BASIS,
17
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ * See the License for the specific language governing permissions and
19
+ * limitations under the License.
20
+ */
21
+ const types_1 = require("../types");
22
+ const types_2 = require("../../types");
23
+ const facts_1 = require("../facts");
24
+ exports.default = (0, types_1.defineRule)({
25
+ id: "sip/ack-2xx",
26
+ profile: types_2.Profile.SIP,
27
+ severity: types_2.Severity.WARNING,
28
+ spec: "RFC 3261 §13.2.2.4",
29
+ summary: "A 2xx to INVITE is acknowledged before the dialog is torn down"
30
+ }, ({ record, call }, fail) => {
31
+ var _a;
32
+ if (!(0, facts_1.isRequest)(record) || record.method !== "BYE")
33
+ return;
34
+ const unacked = call
35
+ .filter((r) => {
36
+ var _a, _b;
37
+ return (0, facts_1.isResponse)(r) &&
38
+ r.method === "INVITE" &&
39
+ ((_a = (0, facts_1.statusOf)(r)) !== null && _a !== void 0 ? _a : 0) >= 200 &&
40
+ ((_b = (0, facts_1.statusOf)(r)) !== null && _b !== void 0 ? _b : 0) < 300;
41
+ })
42
+ .filter((ok) => {
43
+ var _a;
44
+ const n = (_a = (0, facts_1.cseqOf)((0, facts_1.inbound)(ok))) === null || _a === void 0 ? void 0 : _a.number;
45
+ return !call.some((r) => {
46
+ var _a;
47
+ return (0, facts_1.isRequest)(r) &&
48
+ r.method === "ACK" &&
49
+ r.seq > ok.seq &&
50
+ ((_a = (0, facts_1.cseqOf)((0, facts_1.inbound)(r))) === null || _a === void 0 ? void 0 : _a.number) === n;
51
+ });
52
+ });
53
+ if (unacked.length) {
54
+ return fail(`BYE arrived while the 2xx to INVITE (CSeq ${(_a = (0, facts_1.cseqOf)((0, facts_1.inbound)(unacked[0]))) === null || _a === void 0 ? void 0 : _a.number}) was never acknowledged`, "call");
55
+ }
56
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: import("../types").Rule;
2
+ export default _default;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /*
4
+ * Copyright (C) 2026 by Fonoster Inc (https://fonoster.com)
5
+ * http://github.com/fonoster/routr
6
+ *
7
+ * This file is part of Routr.
8
+ *
9
+ * Licensed under the MIT License (the "License");
10
+ * you may not use this file except in compliance with
11
+ * the License. You may obtain a copy of the License at
12
+ *
13
+ * https://opensource.org/licenses/MIT
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software
16
+ * distributed under the License is distributed on an "AS IS" BASIS,
17
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ * See the License for the specific language governing permissions and
19
+ * limitations under the License.
20
+ */
21
+ const types_1 = require("../types");
22
+ const types_2 = require("../../types");
23
+ const facts_1 = require("../facts");
24
+ exports.default = (0, types_1.defineRule)({
25
+ id: "sip/cancel-matches",
26
+ profile: types_2.Profile.SIP,
27
+ severity: types_2.Severity.ERROR,
28
+ spec: "RFC 3261 §9.1",
29
+ summary: "A CANCEL carries the CSeq number and top Via branch of the INVITE it cancels"
30
+ }, ({ record, call }, fail) => {
31
+ if (!(0, facts_1.isRequest)(record) || record.method !== "CANCEL")
32
+ return;
33
+ const cseq = (0, facts_1.cseqOf)((0, facts_1.inbound)(record));
34
+ const branch = (0, facts_1.topBranch)((0, facts_1.inbound)(record));
35
+ const invites = call.filter((r) => (0, facts_1.isRequest)(r) && r.method === "INVITE");
36
+ if (!cseq || invites.length === 0)
37
+ return;
38
+ const match = invites.find((r) => {
39
+ var _a;
40
+ return ((_a = (0, facts_1.cseqOf)((0, facts_1.inbound)(r))) === null || _a === void 0 ? void 0 : _a.number) === cseq.number &&
41
+ (!branch || (0, facts_1.topBranch)((0, facts_1.inbound)(r)) === branch);
42
+ });
43
+ if (!match) {
44
+ return fail(`CANCEL (CSeq ${cseq.number}, branch ${branch !== null && branch !== void 0 ? branch : "none"}) matches no INVITE of this call`, "in", "CSeq");
45
+ }
46
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: import("../types").Rule;
2
+ export default _default;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /*
4
+ * Copyright (C) 2026 by Fonoster Inc (https://fonoster.com)
5
+ * http://github.com/fonoster/routr
6
+ *
7
+ * This file is part of Routr.
8
+ *
9
+ * Licensed under the MIT License (the "License");
10
+ * you may not use this file except in compliance with
11
+ * the License. You may obtain a copy of the License at
12
+ *
13
+ * https://opensource.org/licenses/MIT
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software
16
+ * distributed under the License is distributed on an "AS IS" BASIS,
17
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ * See the License for the specific language governing permissions and
19
+ * limitations under the License.
20
+ */
21
+ const types_1 = require("../types");
22
+ const types_2 = require("../../types");
23
+ const facts_1 = require("../facts");
24
+ exports.default = (0, types_1.defineRule)({
25
+ id: "sip/credentials-stripped",
26
+ profile: types_2.Profile.SIP,
27
+ severity: types_2.Severity.ERROR,
28
+ spec: "RFC 3261 §22.2",
29
+ summary: "Credentials the proxy accepted are not forwarded; the next hop would receive the digest"
30
+ }, ({ record }, fail) => {
31
+ if (!(0, facts_1.isForwarded)(record))
32
+ return;
33
+ const accepted = !!(0, facts_1.inbound)(record).authorization ||
34
+ (0, facts_1.headerValues)((0, facts_1.inbound)(record), "Authorization").length > 0;
35
+ if (!accepted)
36
+ return;
37
+ const out = (0, facts_1.outbound)(record);
38
+ if ((out === null || out === void 0 ? void 0 : out.authorization) || (0, facts_1.headerValues)(out, "Authorization").length) {
39
+ return fail("Authorization the proxy accepted was forwarded to the next hop", "out", "Authorization");
40
+ }
41
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: import("../types").Rule;
2
+ export default _default;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /*
4
+ * Copyright (C) 2026 by Fonoster Inc (https://fonoster.com)
5
+ * http://github.com/fonoster/routr
6
+ *
7
+ * This file is part of Routr.
8
+ *
9
+ * Licensed under the MIT License (the "License");
10
+ * you may not use this file except in compliance with
11
+ * the License. You may obtain a copy of the License at
12
+ *
13
+ * https://opensource.org/licenses/MIT
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software
16
+ * distributed under the License is distributed on an "AS IS" BASIS,
17
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ * See the License for the specific language governing permissions and
19
+ * limitations under the License.
20
+ */
21
+ const types_1 = require("../types");
22
+ const types_2 = require("../../types");
23
+ const facts_1 = require("../facts");
24
+ exports.default = (0, types_1.defineRule)({
25
+ id: "sip/cseq-ack",
26
+ profile: types_2.Profile.SIP,
27
+ severity: types_2.Severity.ERROR,
28
+ spec: "RFC 3261 §17.1.1.3, §13.2.2.4",
29
+ summary: "An ACK carries the CSeq number of the INVITE it acknowledges"
30
+ }, ({ record, call }, fail) => {
31
+ if (!(0, facts_1.isRequest)(record) || record.method !== "ACK")
32
+ return;
33
+ const cseq = (0, facts_1.cseqOf)((0, facts_1.inbound)(record));
34
+ const invites = call.filter((r) => (0, facts_1.isRequest)(r) && r.method === "INVITE");
35
+ if (!cseq || invites.length === 0)
36
+ return;
37
+ if (!invites.some((r) => { var _a; return ((_a = (0, facts_1.cseqOf)((0, facts_1.inbound)(r))) === null || _a === void 0 ? void 0 : _a.number) === cseq.number; })) {
38
+ return fail(`ACK CSeq ${cseq.number} matches no INVITE of this call`, "in", "CSeq");
39
+ }
40
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: import("../types").Rule;
2
+ export default _default;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /*
4
+ * Copyright (C) 2026 by Fonoster Inc (https://fonoster.com)
5
+ * http://github.com/fonoster/routr
6
+ *
7
+ * This file is part of Routr.
8
+ *
9
+ * Licensed under the MIT License (the "License");
10
+ * you may not use this file except in compliance with
11
+ * the License. You may obtain a copy of the License at
12
+ *
13
+ * https://opensource.org/licenses/MIT
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software
16
+ * distributed under the License is distributed on an "AS IS" BASIS,
17
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ * See the License for the specific language governing permissions and
19
+ * limitations under the License.
20
+ */
21
+ const types_1 = require("../types");
22
+ const types_2 = require("../../types");
23
+ const facts_1 = require("../facts");
24
+ // ACK and CANCEL reuse the CSeq number of their INVITE
25
+ const SHARES_CSEQ = new Set(["ACK", "CANCEL"]);
26
+ exports.default = (0, types_1.defineRule)({
27
+ id: "sip/cseq-monotonic",
28
+ profile: types_2.Profile.SIP,
29
+ severity: types_2.Severity.ERROR,
30
+ spec: "RFC 3261 §12.2.1.1",
31
+ summary: "CSeq grows with every new request a party sends within a dialog"
32
+ }, ({ record, call }, fail) => {
33
+ if (!(0, facts_1.isRequest)(record) || SHARES_CSEQ.has(record.method))
34
+ return;
35
+ const cseq = (0, facts_1.cseqOf)((0, facts_1.inbound)(record));
36
+ if (!cseq)
37
+ return;
38
+ const direction = (0, facts_1.directionOf)(record);
39
+ const branch = (0, facts_1.topBranch)((0, facts_1.inbound)(record));
40
+ const previous = (0, facts_1.requestsIn)(call)
41
+ .filter((r) => (0, facts_1.directionOf)(r) === direction &&
42
+ !SHARES_CSEQ.has(r.method) &&
43
+ (0, facts_1.topBranch)((0, facts_1.inbound)(r)) !== branch)
44
+ .map((r) => { var _a; return (_a = (0, facts_1.cseqOf)((0, facts_1.inbound)(r))) === null || _a === void 0 ? void 0 : _a.number; })
45
+ .filter((n) => n !== undefined);
46
+ const highest = previous.length ? Math.max(...previous) : undefined;
47
+ if (highest !== undefined && cseq.number <= highest) {
48
+ return fail(`${record.method} CSeq ${cseq.number} does not exceed the previous ${highest} from the same party`, "in", "CSeq");
49
+ }
50
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: import("../types").Rule;
2
+ export default _default;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /*
4
+ * Copyright (C) 2026 by Fonoster Inc (https://fonoster.com)
5
+ * http://github.com/fonoster/routr
6
+ *
7
+ * This file is part of Routr.
8
+ *
9
+ * Licensed under the MIT License (the "License");
10
+ * you may not use this file except in compliance with
11
+ * the License. You may obtain a copy of the License at
12
+ *
13
+ * https://opensource.org/licenses/MIT
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software
16
+ * distributed under the License is distributed on an "AS IS" BASIS,
17
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ * See the License for the specific language governing permissions and
19
+ * limitations under the License.
20
+ */
21
+ const types_1 = require("../types");
22
+ const types_2 = require("../../types");
23
+ const facts_1 = require("../facts");
24
+ exports.default = (0, types_1.defineRule)({
25
+ id: "sip/max-forwards",
26
+ profile: types_2.Profile.SIP,
27
+ severity: types_2.Severity.ERROR,
28
+ spec: "RFC 3261 §16.6 step 3, §16.3",
29
+ summary: "A proxy decrements Max-Forwards by one and never forwards zero"
30
+ }, ({ record }, fail) => {
31
+ var _a, _b, _c;
32
+ if (!(0, facts_1.isForwarded)(record))
33
+ return;
34
+ const mfIn = (_a = (0, facts_1.inbound)(record).maxForwards) === null || _a === void 0 ? void 0 : _a.maxForwards;
35
+ const mfOut = (_c = (_b = (0, facts_1.outbound)(record)) === null || _b === void 0 ? void 0 : _b.maxForwards) === null || _c === void 0 ? void 0 : _c.maxForwards;
36
+ if (mfIn === undefined) {
37
+ return mfOut === undefined
38
+ ? fail("Max-Forwards missing on the outgoing request", "out", "Max-Forwards")
39
+ : undefined;
40
+ }
41
+ if (mfIn === 0) {
42
+ return fail("forwarded a request whose Max-Forwards was 0 (should answer 483)", "in", "Max-Forwards");
43
+ }
44
+ if (mfOut !== mfIn - 1) {
45
+ return fail(`Max-Forwards not decremented (${mfIn} in, ${mfOut !== null && mfOut !== void 0 ? mfOut : "none"} out)`, "out", "Max-Forwards");
46
+ }
47
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: import("../types").Rule;
2
+ export default _default;