@serve.zone/interfaces 32.88.0 → 32.90.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 (43) hide show
  1. package/changelog.md +22 -0
  2. package/dist_ts/00_commitinfo_data.js +1 -1
  3. package/dist_ts/data/cloudaccess.d.ts +402 -0
  4. package/dist_ts/data/cloudaccess.js +685 -0
  5. package/dist_ts/data/cloudlyconfig.d.ts +20 -0
  6. package/dist_ts/data/cloudlyconfig.js +21 -1
  7. package/dist_ts/data/gatewayareas.d.ts +120 -22
  8. package/dist_ts/data/gatewayareas.js +36 -1
  9. package/dist_ts/data/gatewayareas.validation.js +203 -42
  10. package/dist_ts/data/gatewayconnector.d.ts +2 -2
  11. package/dist_ts/data/gatewayconnector.js +20 -1
  12. package/dist_ts/data/gatewayintent.d.ts +181 -0
  13. package/dist_ts/data/gatewayintent.js +67 -0
  14. package/dist_ts/data/index.d.ts +2 -0
  15. package/dist_ts/data/index.js +3 -1
  16. package/dist_ts/data/mail.d.ts +6 -1
  17. package/dist_ts/data/mail.js +1 -1
  18. package/dist_ts/data/witness.js +4 -9
  19. package/dist_ts/private/bearerencoding.d.ts +9 -0
  20. package/dist_ts/private/bearerencoding.js +17 -0
  21. package/dist_ts/private/storagecontract.js +3 -3
  22. package/dist_ts/requests/cloudaccess.d.ts +125 -0
  23. package/dist_ts/requests/cloudaccess.js +2 -0
  24. package/dist_ts/requests/gatewayconnector.d.ts +33 -1
  25. package/dist_ts/requests/index.d.ts +2 -1
  26. package/dist_ts/requests/index.js +3 -2
  27. package/package.json +1 -1
  28. package/readme.md +155 -11
  29. package/ts/00_commitinfo_data.ts +1 -1
  30. package/ts/data/cloudaccess.ts +1133 -0
  31. package/ts/data/cloudlyconfig.ts +27 -0
  32. package/ts/data/gatewayareas.ts +88 -22
  33. package/ts/data/gatewayareas.validation.ts +225 -40
  34. package/ts/data/gatewayconnector.ts +19 -0
  35. package/ts/data/gatewayintent.ts +239 -0
  36. package/ts/data/index.ts +2 -0
  37. package/ts/data/mail.ts +6 -1
  38. package/ts/data/witness.ts +3 -10
  39. package/ts/private/bearerencoding.ts +24 -0
  40. package/ts/private/storagecontract.ts +2 -2
  41. package/ts/requests/cloudaccess.ts +201 -0
  42. package/ts/requests/gatewayconnector.ts +41 -1
  43. package/ts/requests/index.ts +2 -0
@@ -22,6 +22,7 @@ import {
22
22
  import { isPlainRecord, readDataElements, readDataProperty, readExactDataRecord } from '../private/dataproperties.js';
23
23
  import { matchesEngineKeyEntry, readEngineKeyEntries } from '../private/enginekeyentries.js';
24
24
  import { isGatewayClientIdText } from '../private/gatewayclientid.js';
25
+ import { parseCanonicalIpAddress } from '../private/ipaddress.js';
25
26
  import { normalizeCoreMailCredentialVerifier } from './coremail.runtime.js';
26
27
  import {
27
28
  isGatewayClientHostname,
@@ -35,6 +36,7 @@ import {
35
36
  gatewayBlockRuleTypes,
36
37
  gatewayDnsRecordTypes,
37
38
  gatewayDnsStaticRecordTypes,
39
+ gatewayEdgeSettingBounds,
38
40
  gatewayMailIdentityScramIterations,
39
41
  gatewayRoutePathClasses,
40
42
  isGatewayApiTokenScope,
@@ -91,7 +93,10 @@ export const gatewayAreaContentRefusalCodes = Object.freeze([
91
93
  'area-repeated',
92
94
  /** A sealed value is not `{ version, value }` with a 22-character base64url version, or its value breaks the member's encoding. */
93
95
  'invalid-sealed-value',
94
- /** A lifted secret is set without its engine member, or the engine member exists without the secret. */
96
+ /**
97
+ * A lifted secret is set without its engine member, or the engine member exists without the secret.
98
+ * A `basicAuth` or `jwtAuth` exists in any spelling, `null` included.
99
+ */
95
100
  'secret-engine-mismatch',
96
101
  /**
97
102
  * Engine configuration carries, at any depth, a key or `parent.name` member of
@@ -682,7 +687,11 @@ const checkEngineConfig = (scopeArg: IScope, valueArg: unknown, pathArg: string)
682
687
  return true;
683
688
  };
684
689
 
685
- /** A lifted secret is set exactly when its engine member is an object. */
690
+ /**
691
+ * A lifted secret is set exactly when its engine member is an object: `action.tls.certificate`
692
+ * beside `secrets.tlsKey`, a member that has a spelling without a key (`'auto'`). A member that
693
+ * exists only with its secret goes through `checkLiftedPresence`.
694
+ */
686
695
  const checkLiftedCoherence = (
687
696
  scopeArg: IScope,
688
697
  engineArg: unknown,
@@ -694,6 +703,26 @@ const checkLiftedCoherence = (
694
703
  'secret-engine-mismatch');
695
704
  };
696
705
 
706
+ /**
707
+ * A lifted secret is set exactly when its engine member is present, and a present member is an
708
+ * object: `basicAuth` beside `basicAuthUsers` and `jwtAuth` beside `jwtSecret`, in a route's or a
709
+ * source profile's security block. Without its secret the member is absent; one that is present but
710
+ * no object (`basicAuth: null`, a text, a number) is refused like an object without its secret, at
711
+ * the secret's path. The gateway's rule (dcrouter's `validateLiftedPresence`), which a table alone
712
+ * decides.
713
+ */
714
+ const checkLiftedPresence = (
715
+ scopeArg: IScope,
716
+ engineArg: unknown,
717
+ engineMemberArg: string,
718
+ secretArg: unknown,
719
+ secretPathArg: string,
720
+ ): void => {
721
+ const member = engineValueAt(engineArg, engineMemberArg);
722
+ check(scopeArg, secretArg === null ? member === undefined : isPlainRecord(member), secretPathArg,
723
+ 'secret-engine-mismatch');
724
+ };
725
+
697
726
  // ---------------------------------------------------------------------------------------------
698
727
  // Row lists and singletons
699
728
  // ---------------------------------------------------------------------------------------------
@@ -926,36 +955,114 @@ const validateSecurity = (scopeArg: IScope, contentArg: Record<string, unknown>)
926
955
  // ---------------------------------------------------------------------------------------------
927
956
 
928
957
  /**
929
- * The `A` form the gateway's DNS encoder takes (dcrouter's record value owner, after smartdns
930
- * `encode_a`): four decimal octets of one to three digits, each at most 255, nothing around them.
958
+ * The form of a record's `name` (Linus ruling 129, Q1): at most 253 characters, every label a
959
+ * `zoneLabel`, except that the leftmost label may be exactly `*` with at least one label after it.
960
+ * Lowercase, no trailing dot, nothing around it.
931
961
  */
932
- const isDnsIpv4Value = (valueArg: string): boolean => {
933
- const octets = valueArg.split('.');
934
- return octets.length === 4 && octets.every((octetArg) => /^[0-9]{1,3}$/.test(octetArg) && Number(octetArg) <= 255);
962
+ const isDnsRecordName = (valueArg: unknown): valueArg is string => {
963
+ if (typeof valueArg !== 'string' || valueArg.length === 0 || valueArg.length > 253) {
964
+ return false;
965
+ }
966
+ const [first, ...rest] = valueArg.split('.');
967
+ return (first === '*' ? rest.length > 0 : zoneLabel.test(first)) && rest.every((labelArg) => zoneLabel.test(labelArg));
935
968
  };
936
969
 
970
+ /** A record's `name`: beyond 253 characters `bound-exceeded`, outside the form `invalid-value`. */
971
+ const checkDnsRecordName = (scopeArg: IScope, valueArg: unknown): boolean => {
972
+ if (typeof valueArg === 'string' && valueArg.length > 253) {
973
+ refuse(scopeArg, 'name', 'bound-exceeded');
974
+ return false;
975
+ }
976
+ check(scopeArg, isDnsRecordName(valueArg), 'name');
977
+ return isDnsRecordName(valueArg);
978
+ };
979
+
980
+ const utf8Encoder = new TextEncoder();
981
+ const utf8Length = (textArg: string): number => utf8Encoder.encode(textArg).length;
982
+ const whitespace = /\s/;
983
+
937
984
  /**
938
- * The `AAAA` form the gateway's DNS encoder takes (smartdns 11.1.0 `encode_aaaa`, as dcrouter's
939
- * record value owner ports it): hex groups of one to four digits, either case, eight of them, or at
940
- * most eight with exactly one `::`; no IPv4 tail, no zone id, nothing around them. `net.isIPv6`
941
- * differs on all three and is not this check.
985
+ * A domain name inside a record value, in the one spelling the gateway's record value owner emits
986
+ * (dcrouter's `canonicalDnsRecordValue`): lowercase as written, no trailing dot, no whitespace, no
987
+ * empty label, every label at most 63 octets and the name at most 253. The characters of a label are
988
+ * not restricted further, as the gateway's encoder does not restrict them; the root is no name here.
942
989
  */
943
- const isDnsIpv6Value = (valueArg: string): boolean => {
944
- const halves = valueArg.split('::');
945
- if (halves.length > 2) {
946
- return false;
990
+ const isDnsValueName = (valueArg: string): boolean => (
991
+ valueArg !== '' && !whitespace.test(valueArg) && valueArg === valueArg.toLowerCase() && !valueArg.endsWith('.')
992
+ && utf8Length(valueArg) <= 253
993
+ && valueArg.split('.').every((labelArg) => labelArg !== '' && utf8Length(labelArg) <= 63)
994
+ );
995
+
996
+ /** A decimal number from 0 to `maximumArg` without a leading zero, as the value owner writes one. */
997
+ const isDnsValueNumber = (valueArg: string, maximumArg: number): boolean => (
998
+ /^(?:0|[1-9][0-9]{0,9})$/.test(valueArg) && Number(valueArg) <= maximumArg
999
+ );
1000
+
1001
+ /**
1002
+ * The one spelling of a record value per type (Linus ruling 129, Q3), which is what dcrouter's
1003
+ * record value owner emits (`canonicalDnsRecordValue`): the validator judges that spelling and
1004
+ * accepts no other, so one record has one digest.
1005
+ *
1006
+ * - `A`, `AAAA`: one address of the type's family in the contract's canonical address text
1007
+ * (`parseCanonicalIpAddress`, Linus ruling 143 B): a dotted quad without leading zeros, or the
1008
+ * RFC 5952 text (lowercase, no leading zeros, the longest run of zero groups compressed). Every
1009
+ * other spelling of the same address, which the gateway's DNS encoder would serve alike, is
1010
+ * refused: the gateway's exporter respells a stored value. Spelling only: any address of the
1011
+ * family is a value (the unspecified and multicast addresses too).
1012
+ * - `CNAME`, `NS`: one name (`isDnsValueName`).
1013
+ * - `MX`: `<preference> <exchange>` with one space between: the preference 0 to 65535, the exchange
1014
+ * a name, or `.` exactly with preference 0 (the null MX of RFC 7505).
1015
+ * - `SOA`: `<mname> <rname> <serial> <refresh> <retry> <expire> <minimum>` with one space between
1016
+ * each: two names and five numbers from 0 to 4294967295.
1017
+ * - `CAA`: any text without whitespace around it (the gateway keeps it as it is).
1018
+ * - `TXT`: the text itself.
1019
+ */
1020
+ const isDnsRecordValue = (typeArg: unknown, valueArg: string): boolean => {
1021
+ switch (typeArg) {
1022
+ case 'A':
1023
+ return parseCanonicalIpAddress(valueArg)?.family === 4;
1024
+ case 'AAAA':
1025
+ return parseCanonicalIpAddress(valueArg)?.family === 6;
1026
+ case 'CNAME':
1027
+ case 'NS':
1028
+ return isDnsValueName(valueArg);
1029
+ case 'MX': {
1030
+ const fields = valueArg.split(' ');
1031
+ return fields.length === 2 && isDnsValueNumber(fields[0], 65_535)
1032
+ && (fields[1] === '.' ? fields[0] === '0' : isDnsValueName(fields[1]));
1033
+ }
1034
+ case 'SOA': {
1035
+ const fields = valueArg.split(' ');
1036
+ return fields.length === 7 && isDnsValueName(fields[0]) && isDnsValueName(fields[1])
1037
+ && fields.slice(2).every((fieldArg) => isDnsValueNumber(fieldArg, 4_294_967_295));
1038
+ }
1039
+ case 'CAA':
1040
+ return valueArg === valueArg.trim();
1041
+ default:
1042
+ // `TXT` is the text itself; a type outside the vocabulary is refused at `type`.
1043
+ return true;
947
1044
  }
948
- const groups = halves.flatMap((halfArg) => (halfArg === '' ? [] : halfArg.split(':')));
949
- return groups.every((groupArg) => /^[0-9A-Fa-f]{1,4}$/.test(groupArg))
950
- && (halves.length === 2 ? groups.length <= 8 : groups.length === 8);
951
1045
  };
952
1046
 
953
- /** A record value: a bounded text, and for `A` and `AAAA` an address in the form the gateway serves. */
1047
+ /** A record value: a bounded text in the one spelling of its type (`isDnsRecordValue`). */
954
1048
  const checkRecordValue = (scopeArg: IScope, typeArg: unknown, valueArg: unknown): void => {
955
1049
  checkText(scopeArg, valueArg, 'value', contract.maximumRecordValueLength);
956
- if (isText(valueArg, contract.maximumRecordValueLength) && (typeArg === 'A' || typeArg === 'AAAA')) {
957
- check(scopeArg, typeArg === 'A' ? isDnsIpv4Value(valueArg) : isDnsIpv6Value(valueArg), 'value');
1050
+ if (isText(valueArg, contract.maximumRecordValueLength)) {
1051
+ check(scopeArg, isDnsRecordValue(typeArg, valueArg), 'value');
1052
+ }
1053
+ };
1054
+
1055
+ /**
1056
+ * A zone the gateway may answer for: a zone name of at least two labels whose labels are letters,
1057
+ * digits and inner hyphens (no underscore), the form a delegation can name.
1058
+ */
1059
+ const authorityZoneLabel = /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/;
1060
+ const isAuthorityZoneName = (valueArg: unknown): boolean => {
1061
+ if (!isZoneName(valueArg)) {
1062
+ return false;
958
1063
  }
1064
+ const labels = valueArg.split('.');
1065
+ return labels.length >= 2 && labels.every((labelArg) => authorityZoneLabel.test(labelArg));
959
1066
  };
960
1067
 
961
1068
  const validateDns = (scopeArg: IScope, contentArg: Record<string, unknown>): void => {
@@ -1039,13 +1146,14 @@ const validateDns = (scopeArg: IScope, contentArg: Record<string, unknown>): voi
1039
1146
  } else if (domainSources.get(row.domainId) !== 'dcrouter') {
1040
1147
  refuse(rowScopeArg, 'domainId', 'reference-not-dcrouter-zone');
1041
1148
  } else {
1042
- // A record lies inside its zone: the zone's name itself or a name below it, as written.
1149
+ // A record lies inside its zone: the zone's name itself or a name below it, as written. A name
1150
+ // outside the name form is refused for that alone, below.
1043
1151
  const zone = domainNames.get(row.domainId);
1044
- if (isText(row.name, 253) && isZoneName(zone)) {
1152
+ if (isDnsRecordName(row.name) && isZoneName(zone)) {
1045
1153
  check(rowScopeArg, row.name === zone || row.name.endsWith(`.${zone}`), 'name');
1046
1154
  }
1047
1155
  }
1048
- checkText(rowScopeArg, row.name, 'name', 253);
1156
+ checkDnsRecordName(rowScopeArg, row.name);
1049
1157
  checkOneOf(rowScopeArg, row.type, 'type', gatewayDnsRecordTypes);
1050
1158
  checkRecordValue(rowScopeArg, row.type, row.value);
1051
1159
  checkInteger(rowScopeArg, row.ttl, 'ttl', 1);
@@ -1058,7 +1166,7 @@ const validateDns = (scopeArg: IScope, contentArg: Record<string, unknown>): voi
1058
1166
  if (rowScopeArg.rowId !== null) {
1059
1167
  check(rowScopeArg, /^static-[a-f0-9]{64}$/.test(rowScopeArg.rowId), 'id', 'invalid-row-id');
1060
1168
  }
1061
- checkText(rowScopeArg, row.name, 'name', 253);
1169
+ checkDnsRecordName(rowScopeArg, row.name);
1062
1170
  checkOneOf(rowScopeArg, row.type, 'type', gatewayDnsStaticRecordTypes);
1063
1171
  checkRecordValue(rowScopeArg, row.type, row.value);
1064
1172
  checkInteger(rowScopeArg, row.ttl, 'ttl', 1, true);
@@ -1079,10 +1187,14 @@ const validateDns = (scopeArg: IScope, contentArg: Record<string, unknown>): voi
1079
1187
  check(rowScopeArg, isGatewayClientHostname(rowScopeArg.rowId), 'id', 'invalid-row-id');
1080
1188
  }
1081
1189
  checkText(rowScopeArg, row.reason, 'reason', contract.maximumTextLength);
1190
+ // The gateway stores a reason trimmed, so one with whitespace around it would not read back.
1191
+ if (isText(row.reason, contract.maximumTextLength)) {
1192
+ check(rowScopeArg, row.reason === row.reason.trim(), 'reason');
1193
+ }
1082
1194
  });
1083
1195
  rowList(scopeArg, 'authorityZones', contentArg.authorityZones, bounds.authorityZones, (rowScopeArg, rowArg) => {
1084
1196
  if (exact(rowScopeArg, rowArg, ['id'], null) !== null && rowScopeArg.rowId !== null) {
1085
- check(rowScopeArg, isZoneName(rowScopeArg.rowId), 'id', 'invalid-row-id');
1197
+ check(rowScopeArg, isAuthorityZoneName(rowScopeArg.rowId), 'id', 'invalid-row-id');
1086
1198
  }
1087
1199
  });
1088
1200
  rowList(scopeArg, 'clientHostnames', contentArg.clientHostnames, bounds.clientHostnames, (rowScopeArg, rowArg) => {
@@ -1333,9 +1445,9 @@ const validateRoutes = (scopeArg: IScope, contentArg: Record<string, unknown>):
1333
1445
  checkNullableSealed(rowScopeArg, secrets.requestHeaders, 'secrets.requestHeaders', decodeGatewayRequestHeaders);
1334
1446
  if (isPlainRecord(row.route)) {
1335
1447
  checkLiftedCoherence(rowScopeArg, row.route, 'action.tls.certificate', secrets.tlsKey, 'secrets.tlsKey');
1336
- checkLiftedCoherence(rowScopeArg, row.route, 'security.basicAuth', secrets.basicAuthUsers,
1448
+ checkLiftedPresence(rowScopeArg, row.route, 'security.basicAuth', secrets.basicAuthUsers,
1337
1449
  'secrets.basicAuthUsers');
1338
- checkLiftedCoherence(rowScopeArg, row.route, 'security.jwtAuth', secrets.jwtSecret, 'secrets.jwtSecret');
1450
+ checkLiftedPresence(rowScopeArg, row.route, 'security.jwtAuth', secrets.jwtSecret, 'secrets.jwtSecret');
1339
1451
  }
1340
1452
  }
1341
1453
  const metadata = exact(rowScopeArg, row.metadata, [
@@ -1384,8 +1496,8 @@ const validateRoutes = (scopeArg: IScope, contentArg: Record<string, unknown>):
1384
1496
  checkNullableSealed(rowScopeArg, secrets.basicAuthUsers, 'secrets.basicAuthUsers', decodeGatewayBasicAuthUsers);
1385
1497
  checkNullableSealed(rowScopeArg, secrets.jwtSecret, 'secrets.jwtSecret');
1386
1498
  if (isPlainRecord(row.security)) {
1387
- checkLiftedCoherence(rowScopeArg, row.security, 'basicAuth', secrets.basicAuthUsers, 'secrets.basicAuthUsers');
1388
- checkLiftedCoherence(rowScopeArg, row.security, 'jwtAuth', secrets.jwtSecret, 'secrets.jwtSecret');
1499
+ checkLiftedPresence(rowScopeArg, row.security, 'basicAuth', secrets.basicAuthUsers, 'secrets.basicAuthUsers');
1500
+ checkLiftedPresence(rowScopeArg, row.security, 'jwtAuth', secrets.jwtSecret, 'secrets.jwtSecret');
1389
1501
  }
1390
1502
  }
1391
1503
  const extendsProfiles = list(rowScopeArg, row.extendsProfiles, 'extendsProfiles');
@@ -1646,6 +1758,20 @@ const validateMail = (scopeArg: IScope, contentArg: Record<string, unknown>, dns
1646
1758
  });
1647
1759
  }
1648
1760
  checkOneOf(memberScopeArg, server.tlsSource, 'tlsSource', ['managedCertificate', 'configuredMaterial']);
1761
+ // Enabled mail with server options names its hostname and at least one port: the gateway cannot
1762
+ // start a mail server without them.
1763
+ if (server.enabled === true && isPlainRecord(server.emailConfig)) {
1764
+ const hostname = engineValueAt(server.emailConfig, 'hostname');
1765
+ check(memberScopeArg, typeof hostname === 'string' && hostname.trim() !== '', 'emailConfig.hostname');
1766
+ const ports = readDataElements(engineValueAt(server.emailConfig, 'ports'), Number.MAX_SAFE_INTEGER);
1767
+ check(memberScopeArg, ports !== null && ports.length > 0 && ports.every(isPort), 'emailConfig.ports');
1768
+ }
1769
+ // `configuredMaterial` serves the table's own TLS material: the lifted key, or a certificate in
1770
+ // `emailConfig.tls` (every other material member is a refused engine key).
1771
+ if (server.tlsSource === 'configuredMaterial') {
1772
+ check(memberScopeArg, isPlainRecord(server.emailConfig)
1773
+ && (server.tlsKey !== null || Boolean(engineValueAt(server.emailConfig, 'tls.certPem'))), 'tlsSource');
1774
+ }
1649
1775
  });
1650
1776
  rowList(scopeArg, 'domains', contentArg.domains, bounds.domains, (rowScopeArg, rowArg) => {
1651
1777
  const row = exact(rowScopeArg, rowArg, [
@@ -1796,6 +1922,40 @@ const checkNullableNonEmptyList = (
1796
1922
  checkListArg(scopeArg, valueArg, pathArg);
1797
1923
  };
1798
1924
 
1925
+ const edgeBounds = gatewayEdgeSettingBounds;
1926
+
1927
+ /** A bounded set of ports that never names the client-first TLS port. */
1928
+ const checkServerFirstPorts = (scopeArg: IScope, valueArg: unknown, pathArg: string): void => {
1929
+ if (Array.isArray(valueArg) && valueArg.length > edgeBounds.maximumServerFirstPorts) {
1930
+ refuse(scopeArg, pathArg, 'bound-exceeded');
1931
+ return;
1932
+ }
1933
+ checkPortSet(scopeArg, valueArg, pathArg);
1934
+ const ports = readDataElements(valueArg, edgeBounds.maximumServerFirstPorts);
1935
+ check(scopeArg, ports === null || !ports.includes(edgeBounds.clientFirstPort), pathArg);
1936
+ };
1937
+
1938
+ /** A bounded set of texts without whitespace around them (the gateway stores each trimmed). */
1939
+ const checkEgressTextSet = (scopeArg: IScope, valueArg: unknown, pathArg: string): void => {
1940
+ if (Array.isArray(valueArg) && valueArg.length > edgeBounds.maximumEgressListEntries) {
1941
+ refuse(scopeArg, pathArg, 'bound-exceeded');
1942
+ return;
1943
+ }
1944
+ checkTextSet(scopeArg, valueArg, pathArg,
1945
+ (entryArg) => isText(entryArg, contract.maximumNameLength) && entryArg === entryArg.trim());
1946
+ };
1947
+
1948
+ /** An edge's mail hostname: lowercase letters, digits and inner hyphens in two or more labels, at most 253 characters. */
1949
+ const mailHostnamePattern = /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)+$/;
1950
+
1951
+ /** `null`, or the contract's canonical address text of one family (dotted quad, RFC 5952). */
1952
+ const checkNullableAddress = (scopeArg: IScope, valueArg: unknown, pathArg: string, familyArg: 4 | 6): void => {
1953
+ checkNullableText(scopeArg, valueArg, pathArg, 64);
1954
+ if (isText(valueArg, 64)) {
1955
+ check(scopeArg, parseCanonicalIpAddress(valueArg)?.family === familyArg, pathArg);
1956
+ }
1957
+ };
1958
+
1799
1959
  const checkPerformance = (scopeArg: IScope, valueArg: unknown, pathArg: string): void => {
1800
1960
  if (valueArg === null) {
1801
1961
  return;
@@ -1814,9 +1974,21 @@ const checkPerformance = (scopeArg: IScope, valueArg: unknown, pathArg: string):
1814
1974
  if (key === 'profile') {
1815
1975
  checkOneOf(inner, performance.profile, 'profile', ['balanced', 'throughput', 'highConcurrency'], true);
1816
1976
  } else if (key === 'serverFirstPorts') {
1817
- checkNullableNonEmptyList(inner, performance.serverFirstPorts, 'serverFirstPorts', checkPortSet);
1977
+ checkNullableNonEmptyList(inner, performance.serverFirstPorts, 'serverFirstPorts', checkServerFirstPorts);
1818
1978
  } else {
1819
- checkInteger(inner, performance[key], key, 0, true);
1979
+ const range = edgeBounds.performance[key];
1980
+ const value = performance[key];
1981
+ check(inner, value === null || (isInteger(value, range.minimum) && value <= range.maximum), key);
1982
+ }
1983
+ }
1984
+ // A stream window never starts or settles above its maximum.
1985
+ const maximumWindow = performance.maxStreamWindowBytes;
1986
+ if (isInteger(maximumWindow, 1)) {
1987
+ for (const key of ['minStreamWindowBytes', 'sustainedStreamWindowBytes'] as const) {
1988
+ const value = performance[key];
1989
+ if (isInteger(value, 1)) {
1990
+ check(inner, value <= maximumWindow, key);
1991
+ }
1820
1992
  }
1821
1993
  }
1822
1994
  };
@@ -1828,7 +2000,8 @@ const egressSettingKeys = [
1828
2000
  /**
1829
2001
  * An edge's egress policy in its one spelling (ruling 125, Q-b7): always the object, so `null` fails
1830
2002
  * the shape check (the gateway reads no policy and a disabled one alike; ruling 128, B2's pattern);
1831
- * enabled, it states its ports (the gateway's default `[25]` written out); disabled, every setting is
2003
+ * enabled, it states its ports, which are exactly `gatewayEdgeSettingBounds.egressAllowedPorts`
2004
+ * (`[25]`, Linus ruling 129 Q3: the only ports a gateway opens for egress); disabled, every setting is
1832
2005
  * `null`, because the gateway keeps only `enabled` of a disabled policy; a list is `null` or non-empty.
1833
2006
  */
1834
2007
  const checkEgress = (scopeArg: IScope, valueArg: unknown): void => {
@@ -1845,13 +2018,19 @@ const checkEgress = (scopeArg: IScope, valueArg: unknown): void => {
1845
2018
  return;
1846
2019
  }
1847
2020
  if (egress.enabled === true) {
1848
- check(inner, egress.allowedPorts !== null, 'allowedPorts');
2021
+ const ports = readDataElements(egress.allowedPorts, contract.maximumListEntries);
2022
+ const allowed = edgeBounds.egressAllowedPorts;
2023
+ check(inner, ports !== null && ports.length === allowed.length
2024
+ && ports.every((portArg, indexArg) => portArg === allowed[indexArg]), 'allowedPorts');
2025
+ } else {
2026
+ checkNullableNonEmptyList(inner, egress.allowedPorts, 'allowedPorts', checkPortSet);
1849
2027
  }
1850
- checkNullableNonEmptyList(inner, egress.allowedPorts, 'allowedPorts', checkPortSet);
1851
2028
  checkNullableBoolean(inner, egress.allowPrivateRanges, 'allowPrivateRanges');
1852
- checkNullableNonEmptyList(inner, egress.deniedCidrs, 'deniedCidrs', checkTextSet);
1853
- checkNullableNonEmptyList(inner, egress.allowedHostPatterns, 'allowedHostPatterns', checkTextSet);
1854
- checkInteger(inner, egress.maxConcurrentStreams, 'maxConcurrentStreams', 0, true);
2029
+ checkNullableNonEmptyList(inner, egress.deniedCidrs, 'deniedCidrs', checkEgressTextSet);
2030
+ checkNullableNonEmptyList(inner, egress.allowedHostPatterns, 'allowedHostPatterns', checkEgressTextSet);
2031
+ const streams = egress.maxConcurrentStreams;
2032
+ check(inner, streams === null || (isInteger(streams, 1) && streams <= edgeBounds.maximumEgressConcurrentStreams),
2033
+ 'maxConcurrentStreams');
1855
2034
  };
1856
2035
 
1857
2036
  const validateEdges = (scopeArg: IScope, contentArg: Record<string, unknown>): void => {
@@ -1861,6 +2040,9 @@ const validateEdges = (scopeArg: IScope, contentArg: Record<string, unknown>): v
1861
2040
  if (hub !== null) {
1862
2041
  checkBoolean(memberScopeArg, hub.enabled, 'enabled');
1863
2042
  checkNullableText(memberScopeArg, hub.hubDomain, 'hubDomain', 253);
2043
+ if (isText(hub.hubDomain, 253)) {
2044
+ check(memberScopeArg, hub.hubDomain === hub.hubDomain.trim(), 'hubDomain');
2045
+ }
1864
2046
  checkPerformance(memberScopeArg, hub.performance, 'performance');
1865
2047
  }
1866
2048
  });
@@ -1881,9 +2063,12 @@ const validateEdges = (scopeArg: IScope, contentArg: Record<string, unknown>): v
1881
2063
  checkPerformance(rowScopeArg, row.performance, 'performance');
1882
2064
  checkEgress(rowScopeArg, row.egress);
1883
2065
  checkTextSet(rowScopeArg, row.tags, 'tags');
1884
- checkNullableText(rowScopeArg, row.publicIp, 'publicIp', 64);
1885
- checkNullableText(rowScopeArg, row.publicIpv6, 'publicIpv6', 64);
2066
+ checkNullableAddress(rowScopeArg, row.publicIp, 'publicIp', 4);
2067
+ checkNullableAddress(rowScopeArg, row.publicIpv6, 'publicIpv6', 6);
1886
2068
  checkNullableText(rowScopeArg, row.mailHostname, 'mailHostname', 253);
2069
+ if (isText(row.mailHostname, 253)) {
2070
+ check(rowScopeArg, mailHostnamePattern.test(row.mailHostname), 'mailHostname');
2071
+ }
1887
2072
  });
1888
2073
  };
1889
2074
 
@@ -360,6 +360,24 @@ export const gatewayConnectorRefusals = Object.freeze([
360
360
  * export.
361
361
  */
362
362
  'local-changing-during-export',
363
+ /**
364
+ * A local write to a configuration area the gateway's controller owns: an operator's or a gateway
365
+ * client's change on the gateway itself, whichever call carried it (the gateway's own API, a
366
+ * gateway-client token or a gateway-client call on the connector socket). Nothing was written; the
367
+ * error text names the area (the error data stays `{ code, retryable }` and carries none), and the
368
+ * change is made at the controller. A reader built on an earlier release of this package reads it
369
+ * as a failure without a named refusal.
370
+ */
371
+ 'area-controller-owned',
372
+ /**
373
+ * Momentary (`gatewayConnectorMomentaryRefusals`): a `getGatewayRouteDnsResults` while the gateway
374
+ * runs no route DNS reconciler (it has not started yet, or it failed), so no outcome can be read.
375
+ * It refuses the whole read only and is never one hostname's condition: those stay in the result
376
+ * rows (`IGatewayRouteDnsResult`). Nothing changed, and the controller asks again later. A reader
377
+ * built on an earlier release of this package reads it as a failure without a named refusal, never
378
+ * as an answer.
379
+ */
380
+ 'route-dns-unavailable',
363
381
  ] as const);
364
382
 
365
383
  /** One of the reasons one side of the gateway connector answers instead of a request. */
@@ -386,6 +404,7 @@ export const isGatewayConnectorRefusal = (valueArg: unknown): valueArg is TGatew
386
404
  */
387
405
  export const gatewayConnectorMomentaryRefusals = Object.freeze([
388
406
  'local-changing-during-export',
407
+ 'route-dns-unavailable',
389
408
  ] as const satisfies readonly TGatewayConnectorRefusal[]);
390
409
 
391
410
  /** One of the momentary connector refusals. */