@routr/common 2.17.0 → 2.19.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 (88) 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/index.d.ts +1 -0
  21. package/dist/index.js +2 -1
  22. package/dist/protos/processor.proto +4 -0
  23. package/dist/trace/compat.d.ts +37 -0
  24. package/dist/trace/compat.js +131 -0
  25. package/dist/trace/diff.d.ts +48 -0
  26. package/dist/trace/diff.js +152 -0
  27. package/dist/trace/index.d.ts +11 -0
  28. package/dist/trace/index.js +68 -0
  29. package/dist/trace/metadata.d.ts +28 -0
  30. package/dist/trace/metadata.js +75 -0
  31. package/dist/trace/normalize.d.ts +11 -0
  32. package/dist/trace/normalize.js +39 -0
  33. package/dist/trace/redact.d.ts +19 -0
  34. package/dist/trace/redact.js +52 -0
  35. package/dist/trace/rules/facts.d.ts +43 -0
  36. package/dist/trace/rules/facts.js +117 -0
  37. package/dist/trace/rules/index.d.ts +34 -0
  38. package/dist/trace/rules/index.js +153 -0
  39. package/dist/trace/rules/sip/ack-2xx.d.ts +2 -0
  40. package/dist/trace/rules/sip/ack-2xx.js +56 -0
  41. package/dist/trace/rules/sip/cancel-matches.d.ts +2 -0
  42. package/dist/trace/rules/sip/cancel-matches.js +46 -0
  43. package/dist/trace/rules/sip/credentials-stripped.d.ts +2 -0
  44. package/dist/trace/rules/sip/credentials-stripped.js +41 -0
  45. package/dist/trace/rules/sip/cseq-ack.d.ts +2 -0
  46. package/dist/trace/rules/sip/cseq-ack.js +40 -0
  47. package/dist/trace/rules/sip/cseq-monotonic.d.ts +2 -0
  48. package/dist/trace/rules/sip/cseq-monotonic.js +50 -0
  49. package/dist/trace/rules/sip/max-forwards.d.ts +2 -0
  50. package/dist/trace/rules/sip/max-forwards.js +47 -0
  51. package/dist/trace/rules/sip/private-address.d.ts +2 -0
  52. package/dist/trace/rules/sip/private-address.js +48 -0
  53. package/dist/trace/rules/sip/record-route-self.d.ts +2 -0
  54. package/dist/trace/rules/sip/record-route-self.js +46 -0
  55. package/dist/trace/rules/sip/register-ok.d.ts +2 -0
  56. package/dist/trace/rules/sip/register-ok.js +52 -0
  57. package/dist/trace/rules/sip/retransmission.d.ts +2 -0
  58. package/dist/trace/rules/sip/retransmission.js +47 -0
  59. package/dist/trace/rules/sip/route-self-removed.d.ts +2 -0
  60. package/dist/trace/rules/sip/route-self-removed.js +38 -0
  61. package/dist/trace/rules/sip/via.d.ts +2 -0
  62. package/dist/trace/rules/sip/via.js +50 -0
  63. package/dist/trace/rules/sip-connect/from-e164-or-anonymous.d.ts +2 -0
  64. package/dist/trace/rules/sip-connect/from-e164-or-anonymous.js +43 -0
  65. package/dist/trace/rules/sip-connect/pai-e164.d.ts +2 -0
  66. package/dist/trace/rules/sip-connect/pai-e164.js +44 -0
  67. package/dist/trace/rules/sip-connect/pai-single.d.ts +2 -0
  68. package/dist/trace/rules/sip-connect/pai-single.js +41 -0
  69. package/dist/trace/rules/sip-connect/privacy.d.ts +2 -0
  70. package/dist/trace/rules/sip-connect/privacy.js +50 -0
  71. package/dist/trace/rules/sip-connect/request-uri-e164.d.ts +2 -0
  72. package/dist/trace/rules/sip-connect/request-uri-e164.js +44 -0
  73. package/dist/trace/rules/sip-connect/scope.d.ts +11 -0
  74. package/dist/trace/rules/sip-connect/scope.js +19 -0
  75. package/dist/trace/rules/types.d.ts +34 -0
  76. package/dist/trace/rules/types.js +13 -0
  77. package/dist/trace/sanitize.d.ts +40 -0
  78. package/dist/trace/sanitize.js +85 -0
  79. package/dist/trace/schema.d.ts +338 -0
  80. package/dist/trace/schema.js +197 -0
  81. package/dist/trace/status.d.ts +15 -0
  82. package/dist/trace/status.js +102 -0
  83. package/dist/trace/types.d.ts +126 -0
  84. package/dist/trace/types.js +82 -0
  85. package/dist/trace/validate.d.ts +56 -0
  86. package/dist/trace/validate.js +140 -0
  87. package/dist/types.d.ts +2 -0
  88. package/package.json +2 -2
@@ -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;
@@ -0,0 +1,48 @@
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/private-address",
26
+ profile: types_2.Profile.SIP,
27
+ severity: types_2.Severity.WARNING,
28
+ spec: "RFC 3261 §8.1.1.8, RFC 3264 §5",
29
+ summary: "A request leaving through the external interface names no internal address in Contact or SDP"
30
+ }, ({ record }, fail) => {
31
+ var _a, _b, _c, _d, _e, _f;
32
+ if (!(0, facts_1.isForwarded)(record))
33
+ return;
34
+ const out = (0, facts_1.outbound)(record);
35
+ if (!out || !(0, facts_1.isExternalHost)(record.request, (_b = (_a = out.via) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.host))
36
+ return;
37
+ const internal = (host) => !!host && (0, facts_1.isInternalHost)(record.request, host);
38
+ const findings = [];
39
+ const contact = (_e = (_d = (_c = out.contact) === null || _c === void 0 ? void 0 : _c.address) === null || _d === void 0 ? void 0 : _d.uri) === null || _e === void 0 ? void 0 : _e.host;
40
+ if (internal(contact)) {
41
+ findings.push(fail(`Contact names ${contact}, an internal address the far side cannot reach`, "out", "Contact"));
42
+ }
43
+ const c = (_f = /^c=IN IP4 (\S+)/m.exec(out.body || "")) === null || _f === void 0 ? void 0 : _f[1];
44
+ if (internal(c)) {
45
+ findings.push(fail(`SDP connection address ${c} is internal; media needs a relay`, "out", "Body"));
46
+ }
47
+ return findings;
48
+ });
@@ -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/record-route-self",
26
+ profile: types_2.Profile.SIP,
27
+ severity: types_2.Severity.WARNING,
28
+ spec: "RFC 3261 §16.6 step 4",
29
+ summary: "A Record-Route the proxy adds names one of its own interfaces, and one the far side can reach"
30
+ }, ({ record }, fail) => {
31
+ var _a, _b, _c, _d, _e, _f;
32
+ if (!(0, facts_1.isForwarded)(record) || (0, facts_1.isInDialog)(record))
33
+ return;
34
+ const out = (0, facts_1.outbound)(record);
35
+ const rr = (_d = (_c = (_b = (_a = out === null || out === void 0 ? void 0 : out.recordRoute) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.address) === null || _c === void 0 ? void 0 : _c.uri) === null || _d === void 0 ? void 0 : _d.host;
36
+ if (!rr)
37
+ return;
38
+ if (!(0, facts_1.isOwnHost)(record.request, rr)) {
39
+ return fail(`top Record-Route names ${rr}, not one of the proxy's interfaces`, "out", "Record-Route");
40
+ }
41
+ const via = (_f = (_e = out === null || out === void 0 ? void 0 : out.via) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.host;
42
+ if ((0, facts_1.isExternalHost)(record.request, via) &&
43
+ (0, facts_1.isInternalHost)(record.request, rr)) {
44
+ return fail(`Record-Route names ${rr}, an internal interface, while the request leaves through ${via}`, "out", "Record-Route");
45
+ }
46
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: import("../types").Rule;
2
+ export default _default;
@@ -0,0 +1,52 @@
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/register-ok",
26
+ profile: types_2.Profile.SIP,
27
+ severity: types_2.Severity.ERROR,
28
+ spec: "RFC 3261 §10.3 step 8",
29
+ summary: "A 200 to REGISTER carries the Contact bound and an expiration (the EdgePort copies the request's Expires)"
30
+ }, ({ record }, fail) => {
31
+ var _a, _b, _c;
32
+ if (!(0, facts_1.isRequest)(record) ||
33
+ record.method !== "REGISTER" ||
34
+ record.outcome !== types_2.TraceOutcome.ANSWERED ||
35
+ (0, facts_1.statusOf)(record) !== 200) {
36
+ return;
37
+ }
38
+ const out = (0, facts_1.outbound)(record);
39
+ if (!(out === null || out === void 0 ? void 0 : out.contact)) {
40
+ return fail("200 to REGISTER carries no Contact", "out", "Contact");
41
+ }
42
+ const inMsg = (0, facts_1.inbound)(record);
43
+ const candidates = [
44
+ (_a = out.expires) === null || _a === void 0 ? void 0 : _a.expires,
45
+ out.contact.expires,
46
+ (_b = inMsg.expires) === null || _b === void 0 ? void 0 : _b.expires,
47
+ (_c = inMsg.contact) === null || _c === void 0 ? void 0 : _c.expires
48
+ ];
49
+ if (!candidates.some((e) => typeof e === "number" && e >= 0)) {
50
+ return fail("200 to REGISTER carries no expiration and the request had none", "out", "Expires");
51
+ }
52
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: import("../types").Rule;
2
+ export default _default;