@onlyflows/servicenow-mcp 2.3.0-rc.2 → 2.3.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 (46) hide show
  1. package/CHANGELOG.md +171 -0
  2. package/README.md +28 -1
  3. package/dist/field-policy.d.ts +13 -3
  4. package/dist/field-policy.d.ts.map +1 -1
  5. package/dist/field-policy.js +316 -23
  6. package/dist/field-policy.js.map +1 -1
  7. package/dist/policy-card.d.ts.map +1 -1
  8. package/dist/policy-card.js +2 -0
  9. package/dist/policy-card.js.map +1 -1
  10. package/dist/risky-grants.d.ts +6 -2
  11. package/dist/risky-grants.d.ts.map +1 -1
  12. package/dist/risky-grants.js +57 -5
  13. package/dist/risky-grants.js.map +1 -1
  14. package/dist/tools/platform-view-contracts.d.ts +2 -2
  15. package/dist/tools/platform-view-evaluate.d.ts +214 -6
  16. package/dist/tools/platform-view-evaluate.d.ts.map +1 -1
  17. package/dist/tools/platform-view-evaluate.js +1337 -10
  18. package/dist/tools/platform-view-evaluate.js.map +1 -1
  19. package/dist/update-set-eval/engine.d.ts +29 -0
  20. package/dist/update-set-eval/engine.d.ts.map +1 -0
  21. package/dist/update-set-eval/engine.js +405 -0
  22. package/dist/update-set-eval/engine.js.map +1 -0
  23. package/dist/update-set-eval/prepare.d.ts +72 -0
  24. package/dist/update-set-eval/prepare.d.ts.map +1 -0
  25. package/dist/update-set-eval/prepare.js +216 -0
  26. package/dist/update-set-eval/prepare.js.map +1 -0
  27. package/dist/update-set-eval/rules.d.ts +126 -0
  28. package/dist/update-set-eval/rules.d.ts.map +1 -0
  29. package/dist/update-set-eval/rules.js +927 -0
  30. package/dist/update-set-eval/rules.js.map +1 -0
  31. package/dist/update-set-eval/script-scan.d.ts +65 -0
  32. package/dist/update-set-eval/script-scan.d.ts.map +1 -0
  33. package/dist/update-set-eval/script-scan.js +378 -0
  34. package/dist/update-set-eval/script-scan.js.map +1 -0
  35. package/dist/update-set-eval/secret-patterns.js +2 -2
  36. package/dist/update-set-eval/secret-patterns.js.map +1 -1
  37. package/dist/update-set-eval/types.d.ts +181 -0
  38. package/dist/update-set-eval/types.d.ts.map +1 -0
  39. package/dist/update-set-eval/types.js +20 -0
  40. package/dist/update-set-eval/types.js.map +1 -0
  41. package/dist/version.d.ts +1 -1
  42. package/dist/version.d.ts.map +1 -1
  43. package/dist/version.js +1 -1
  44. package/dist/version.js.map +1 -1
  45. package/package.json +1 -1
  46. package/server.json +2 -2
@@ -13,7 +13,7 @@
13
13
  * @module field-policy
14
14
  */
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.FieldPolicyConfigurationError = exports.EXPLICIT_WRITE_FIELD_NAMES = exports.FieldPolicyError = exports.SAFE_DEFAULT_FIELDS = exports.BUILT_IN_TABLE_CLASSES = exports.MAX_TOOL_ARGUMENT_OWN_KEYS = exports.MAX_FIELD_OBJECT_OWN_KEYS = exports.MAX_FIELD_ARRAY_LENGTH = exports.MAX_FIELD_VALUE_NODES = exports.MAX_FIELD_VALUE_DEPTH = exports.MAX_FIELDS_PER_OPERATION = void 0;
16
+ exports.FieldPolicyConfigurationError = exports.EXPLICIT_WRITE_FIELD_NAMES = exports.FieldPolicyError = exports.SAFE_DEFAULT_FIELDS = exports.BUILT_IN_TABLE_CLASSES = exports.ROTATION_SHARD_BASE_NAMES = exports.EXPLICIT_READ_FIELD_NAMES = exports.MAX_TOOL_ARGUMENT_OWN_KEYS = exports.MAX_FIELD_OBJECT_OWN_KEYS = exports.MAX_FIELD_ARRAY_LENGTH = exports.MAX_FIELD_VALUE_NODES = exports.MAX_FIELD_VALUE_DEPTH = exports.MAX_FIELDS_PER_OPERATION = void 0;
17
17
  exports.fieldPolicyDenialMessage = fieldPolicyDenialMessage;
18
18
  exports.isFieldPolicyError = isFieldPolicyError;
19
19
  exports.snapshotPlainDataArguments = snapshotPlainDataArguments;
@@ -98,6 +98,115 @@ const EXPLICIT_WRITE_FIELDS = new Set([
98
98
  "sys_domain",
99
99
  "sys_domain_path",
100
100
  ]);
101
+ /**
102
+ * Record payload columns: per table, the columns that carry other records'
103
+ * content (whole records as XML, diffs, serialized queue and replication
104
+ * messages, change payloads, flow snapshots) or other packaged content.
105
+ *
106
+ * A wildcard never covers these columns, for reads or writes: not the
107
+ * built-in default, a `"*"` table entry, a profile's `"*"` field entry, or
108
+ * `"*"` on the table's own entry. A column is read only where the profile's
109
+ * own entry for that exact table lists it in `readable`, and written only
110
+ * where that entry lists it in `writable`. Until listed, a column is refused
111
+ * by name (to return, filter, order, group, aggregate or write) and dropped
112
+ * from every wildcard, default, detailed, all-fields and write-response
113
+ * projection. Columns a given release lacks are listed anyway, harmlessly.
114
+ */
115
+ const RECORD_PAYLOAD_COLUMNS = new Map([
116
+ // Customer updates and their versions, previews and diffs, team
117
+ // development previews, application metadata, the upgrade log, and
118
+ // deleted, archived or clone-preserved records.
119
+ ["sys_update_xml", ["payload", "payload_diff"]],
120
+ ["sys_update_version", ["payload", "payload_diff"]],
121
+ ["sys_update_preview_xml", ["payload", "payload_diff"]],
122
+ ["sys_update_diff", ["payload", "payload_diff"]],
123
+ ["sys_sync_preview_remote", ["payload", "payload_diff"]],
124
+ ["sys_upgrade_history_log", ["payload", "payload_diff"]],
125
+ ["sys_metadata_link", ["payload", "payload_diff"]],
126
+ ["sys_metadata_delete", ["payload", "payload_diff"]],
127
+ ["sys_audit_delete", ["payload", "payload_diff"]],
128
+ ["sys_archive_log", ["payload", "payload_diff"]],
129
+ ["clone_preserved_data", ["payload", "payload_diff"]],
130
+ // MID Server, replication and change-data-capture queues.
131
+ ["ecc_queue", ["payload"]],
132
+ ["sys_replication_queue", ["payload", "payload_short"]],
133
+ ["data_replication_queue", ["payload"]],
134
+ ["cdc_queue_ih", ["payload", "previous_payload"]],
135
+ ["cdc_queue_par", ["payload", "previous_payload"]],
136
+ ["cdc_queue_uxa_user_props", ["payload", "previous_payload"]],
137
+ ["sys_rt_change_log", ["payload"]],
138
+ // Flow snapshots and versions.
139
+ ["sys_hub_snapshot", ["payload"]],
140
+ ["sys_hub_snapshot_chunk", ["data"]],
141
+ ["sys_hub_flow_version", ["payload"]],
142
+ // Certificate management.
143
+ ["sn_disco_certmgmt_certificate_ca_credentials", ["encoded_keystore"]],
144
+ ].map(([table, columns]) => [
145
+ table,
146
+ Object.freeze(new Set(columns)),
147
+ ]));
148
+ /**
149
+ * Tables the platform rotates into numbered shards (`ecc_queue0003`,
150
+ * `sys_replication_queue5`), each a separate table that a `"*"` grant reaches
151
+ * by name. A shard is the base name followed by digits only.
152
+ */
153
+ const ROTATION_SHARD_BASES = new Set([
154
+ "ecc_queue",
155
+ "sys_replication_queue",
156
+ "data_replication_queue",
157
+ "cdc_queue_ih",
158
+ "cdc_queue_par",
159
+ "cdc_queue_uxa_user_props",
160
+ ]);
161
+ /**
162
+ * Change-data-capture queues are created per consumer (`cdc_queue_<consumer>`,
163
+ * with or without a shard suffix). Every table under this prefix carries the
164
+ * CDC payload columns, except the consumer-state tables (`cdc_queue_state_*`).
165
+ */
166
+ const CDC_QUEUE_PREFIX = "cdc_queue_";
167
+ const CDC_QUEUE_STATE_PREFIX = "cdc_queue_state_";
168
+ const CDC_QUEUE_COLUMNS = RECORD_PAYLOAD_COLUMNS.get("cdc_queue_ih");
169
+ const NO_FIELDS = Object.freeze([]);
170
+ /**
171
+ * `table` without its trailing digits, or undefined when it has none or is
172
+ * all digits. A single backward scan, so it is linear in the name's length.
173
+ */
174
+ function withoutShardSuffix(table) {
175
+ let end = table.length;
176
+ while (end > 0) {
177
+ const code = table.charCodeAt(end - 1);
178
+ if (code < 48 || code > 57)
179
+ break;
180
+ end -= 1;
181
+ }
182
+ return end === table.length || end === 0 ? undefined : table.slice(0, end);
183
+ }
184
+ /**
185
+ * The record payload columns of `table` (a normalized name), or undefined.
186
+ * A rotation shard takes its base table's columns, and a CDC queue takes the
187
+ * CDC columns. Lookups and fixed rules only: nothing is stored per name, so
188
+ * arbitrary names never grow any state.
189
+ */
190
+ function recordPayloadColumns(table) {
191
+ const exact = RECORD_PAYLOAD_COLUMNS.get(table);
192
+ if (exact !== undefined)
193
+ return exact;
194
+ if (table.length > CDC_QUEUE_PREFIX.length &&
195
+ table.startsWith(CDC_QUEUE_PREFIX) &&
196
+ !table.startsWith(CDC_QUEUE_STATE_PREFIX)) {
197
+ return CDC_QUEUE_COLUMNS;
198
+ }
199
+ const base = withoutShardSuffix(table);
200
+ return base !== undefined && ROTATION_SHARD_BASES.has(base) ? RECORD_PAYLOAD_COLUMNS.get(base) : undefined;
201
+ }
202
+ /**
203
+ * Each base table and the columns its own entry must list. A rotation shard
204
+ * (see ROTATION_SHARD_BASE_NAMES) has its base table's columns, and every
205
+ * `cdc_queue_*` table except `cdc_queue_state_*` has the CDC queue columns.
206
+ */
207
+ exports.EXPLICIT_READ_FIELD_NAMES = Object.freeze(Object.fromEntries([...RECORD_PAYLOAD_COLUMNS].map(([table, columns]) => [table, Object.freeze([...columns])])));
208
+ /** The base tables whose numbered rotation shards share their columns. */
209
+ exports.ROTATION_SHARD_BASE_NAMES = Object.freeze([...ROTATION_SHARD_BASES]);
101
210
  const INCIDENT_DEFAULTS = [
102
211
  "sys_id",
103
212
  "number",
@@ -695,6 +804,62 @@ const POLICY_DEFINITIONS = {
695
804
  ],
696
805
  writable: [],
697
806
  },
807
+ // The platform tables (PLATFORM_BUILT_INS): customer updates, the upgrade
808
+ // log and Instance Scan. A "*" table grant covers them like any table, and
809
+ // for field policy they belong to the profile, so a profile's "*" field
810
+ // entry narrows them. Each default projection names the row and leaves out
811
+ // the columns that carry script, XML or matched code; those are read only
812
+ // when asked for by name.
813
+ //
814
+ // A customer update. Never in the default projection: payload (the record's
815
+ // XML, scripts included).
816
+ sys_update_xml: {
817
+ defaults: ["sys_id", "name", "type", "target_name", "table", "action", "update_set", "application", "sys_updated_on"],
818
+ readable: [
819
+ "sys_id", "name", "type", "target_name", "table", "action", "update_set", "application",
820
+ "replace_on_upgrade", "remote_update_set", "update_guid", "payload", "payload_hash",
821
+ "sys_updated_by", "sys_updated_on", "sys_created_on",
822
+ ],
823
+ writable: [],
824
+ },
825
+ // One file of an upgrade or app-install run. Never in the default
826
+ // projection: payload and payload_diff (the file's XML and its diff).
827
+ sys_upgrade_history_log: {
828
+ defaults: ["sys_id", "upgrade_history", "file_name", "type", "target_name", "disposition", "resolution_status", "change_type", "plugin"],
829
+ readable: [
830
+ "sys_id", "upgrade_history", "file_name", "type", "target_name", "disposition",
831
+ "resolution_status", "change_type", "plugin", "payload", "payload_diff", "sys_created_on",
832
+ ],
833
+ writable: [],
834
+ },
835
+ // An Instance Scan finding. Never in the default projection:
836
+ // finding_details (it can hold the matched code), task and user.
837
+ scan_finding: {
838
+ defaults: ["sys_id", "result", "check", "source_table", "source", "count", "muted", "sys_created_on"],
839
+ readable: [
840
+ "sys_id", "result", "check", "source_table", "source", "count", "muted", "finding_details",
841
+ "task", "user", "check_version", "product_family", "scan_mute_rule", "sys_created_on",
842
+ ],
843
+ writable: [],
844
+ },
845
+ // An Instance Scan run. Never in the default projection: message.
846
+ scan_result: {
847
+ defaults: ["sys_id", "number", "state", "finding_count", "scan_type", "sys_created_on"],
848
+ readable: [
849
+ "sys_id", "number", "state", "finding_count", "scan_type", "execution_time", "message",
850
+ "sys_created_on",
851
+ ],
852
+ writable: [],
853
+ },
854
+ // An Instance Scan check. Never in the default projection: script.
855
+ scan_check: {
856
+ defaults: ["sys_id", "name", "category", "priority", "short_description", "active"],
857
+ readable: [
858
+ "sys_id", "name", "category", "priority", "short_description", "description", "active",
859
+ "finding_type", "script", "sys_updated_on",
860
+ ],
861
+ writable: [],
862
+ },
698
863
  };
699
864
  /**
700
865
  * The policy base.
@@ -711,8 +876,9 @@ const POLICY_DEFINITIONS = {
711
876
  * a granted custom table needs no field-policy entry to be usable.
712
877
  *
713
878
  * A profile's own "*" entry reaches further: it also covers the ITSM tables
714
- * (ITSM_TABLES), the named-only tables (NAMED_ONLY_BUILT_INS) and every table
715
- * the profile names, key by key, wherever the table's own entry is silent.
879
+ * (ITSM_TABLES), the named-only tables (NAMED_ONLY_BUILT_INS), the platform
880
+ * tables (PLATFORM_BUILT_INS) and every table the profile names, key by key,
881
+ * wherever the table's own entry is silent.
716
882
  * Only the system tables (SYSTEM_TABLES) are never covered by a "*" entry.
717
883
  */
718
884
  const FIELD_POLICY_BASE = Object.freeze({
@@ -759,8 +925,8 @@ const ITSM_TABLES = new Set([
759
925
  *
760
926
  * This list is written out rather than derived as "built-in minus ITSM", so
761
927
  * a new built-in entry never escapes every profile's "*" entry by default.
762
- * Each built-in entry must be in exactly one of ITSM_TABLES, SYSTEM_TABLES
763
- * and NAMED_ONLY_BUILT_INS; a test enforces this through
928
+ * Each built-in entry must be in exactly one of ITSM_TABLES, SYSTEM_TABLES,
929
+ * NAMED_ONLY_BUILT_INS and PLATFORM_BUILT_INS; a test enforces this through
764
930
  * BUILT_IN_TABLE_CLASSES.
765
931
  */
766
932
  const SYSTEM_TABLES = new Set([
@@ -799,6 +965,23 @@ const SYSTEM_TABLES = new Set([
799
965
  * readable set. A table's own entry still narrows or widens it.
800
966
  */
801
967
  const NAMED_ONLY_BUILT_INS = new Set(table_policy_js_1.NAMED_ONLY_TABLES);
968
+ /**
969
+ * The platform tables: customer updates, the upgrade log and Instance Scan.
970
+ * A "*" table grant covers them, as it covers any table. For field policy
971
+ * they are profile-owned like the ITSM and named-only tables: `readable` and
972
+ * `writable` resolve from the profile's own entry for the table, then its "*"
973
+ * entry, then the built-in "*" (open), so a profile that narrows reads with
974
+ * "*" narrows these too, whether or not it names them. Their built-in
975
+ * `defaults` leave out the script, XML and matched-code columns and are
976
+ * clamped to the effective readable set.
977
+ */
978
+ const PLATFORM_BUILT_INS = new Set([
979
+ "sys_update_xml",
980
+ "sys_upgrade_history_log",
981
+ "scan_finding",
982
+ "scan_result",
983
+ "scan_check",
984
+ ]);
802
985
  /**
803
986
  * The built-in tables and how each is classified for a profile's "*" entry.
804
987
  * Frozen copies for tests; the policy reads the sets above.
@@ -808,7 +991,15 @@ exports.BUILT_IN_TABLE_CLASSES = Object.freeze({
808
991
  itsm: Object.freeze([...ITSM_TABLES]),
809
992
  system: Object.freeze([...SYSTEM_TABLES]),
810
993
  namedOnly: Object.freeze([...NAMED_ONLY_BUILT_INS]),
994
+ platform: Object.freeze([...PLATFORM_BUILT_INS]),
811
995
  });
996
+ /**
997
+ * Every built-in table a profile's "*" entry covers: each one that is not a
998
+ * system table, whatever its class. Derived rather than listed by class, so a
999
+ * built-in entry or class added later is covered by a narrowing "*" entry
1000
+ * without touching the merge.
1001
+ */
1002
+ const PROFILE_OWNED_BUILT_INS = Object.freeze(Object.keys(POLICY_DEFINITIONS).filter((table) => !SYSTEM_TABLES.has(table)));
812
1003
  const GENERIC_RECORD_TABLES = new Set([
813
1004
  "incident",
814
1005
  "change_request",
@@ -895,13 +1086,25 @@ function fieldPolicyDenialMessage(error) {
895
1086
  case "field_types_unavailable":
896
1087
  return hidden_values_js_1.FIELD_TYPES_UNAVAILABLE_MESSAGE;
897
1088
  case "explicit_field_required":
898
- // Only the EXPLICIT_WRITE_FIELDS names reach this case; each is a fixed
899
- // name that passed FIELD_NAME.
1089
+ // Only EXPLICIT_WRITE_FIELDS and record payload column names reach this
1090
+ // case; each is a fixed name that passed FIELD_NAME.
1091
+ if (table && field && !EXPLICIT_WRITE_FIELDS.has(field)) {
1092
+ return (`Write denied by policy: field "${field}" on "${table}" holds record payloads, ` +
1093
+ "so a writable wildcard never covers it. List it explicitly in " +
1094
+ `fieldPolicy.${table}.writable to allow this write.`);
1095
+ }
900
1096
  return table && field
901
1097
  ? `Write denied by policy: field "${field}" on "${table}" changes the record's ` +
902
1098
  "class or domain, so a writable wildcard never covers it. List it explicitly " +
903
1099
  `in fieldPolicy.${table}.writable to allow this write.`
904
- : "Write denied by policy: a class or domain field must be listed explicitly in the writable set.";
1100
+ : "Write denied by policy: a field that a writable wildcard never covers must be listed explicitly in the writable set.";
1101
+ case "explicit_read_required":
1102
+ // Only record payload column names reach this case, on a fixed table.
1103
+ return table && field
1104
+ ? `Read denied by policy: field "${field}" on "${table}" holds record payloads, ` +
1105
+ "so a readable wildcard never covers it. List it explicitly in " +
1106
+ `fieldPolicy.${table}.readable to allow this read.`
1107
+ : "Read denied by policy: a record payload field must be listed explicitly in its table's readable set.";
905
1108
  case "unsupported_field_path":
906
1109
  // The key itself is not echoed: as a whole it did not pass FIELD_NAME.
907
1110
  return (`Write denied by policy: write keys${table ? ` on "${table}"` : ""} must be plain field names. ` +
@@ -952,7 +1155,8 @@ function resolveReadableFields(tableCandidate, input = {}) {
952
1155
  const canonicalInput = snapshotPlainDataArguments(input);
953
1156
  const responseFormat = normalizeResponseFormat(canonicalInput.responseFormat);
954
1157
  const requested = canonicalInput.fields;
955
- const hidden = typeHiddenFields(policy.table);
1158
+ const hidden = readHiddenFields(policy.table);
1159
+ const explicitDenied = explicitReadDeniedFields(policy.table);
956
1160
  const queryDenied = canonicalInput.purpose === "query" ? (0, hidden_values_js_1.rowValueRule)(policy.table)?.queryDenied : undefined;
957
1161
  if (requested === undefined) {
958
1162
  return visibleSelection(policy.table, requireNonEmptySelection(responseFormat === "detailed" ? readableSelection(policy) : policy.defaults));
@@ -972,6 +1176,12 @@ function resolveReadableFields(tableCandidate, input = {}) {
972
1176
  const field = normalizeFieldName(candidate);
973
1177
  if (seen.has(field))
974
1178
  throw new FieldPolicyError("invalid_field_selection");
1179
+ // A record payload column the profile's own entry for the table does
1180
+ // not list. Checked first: unlike a hidden-typed field, configuration can
1181
+ // open it, so the refusal says how.
1182
+ if (explicitDenied.has(field)) {
1183
+ throw new FieldPolicyError("explicit_read_required", { table: policy.table, field });
1184
+ }
975
1185
  // A hidden-typed field is refused exactly like a sensitive name, with the
976
1186
  // same message, before the readable check, so the refusal says nothing
977
1187
  // about the field's type or whether a configuration could grant it.
@@ -1020,6 +1230,10 @@ function validateWritableFields(tableCandidate, payloadCandidate) {
1020
1230
  if (EXPLICIT_WRITE_FIELDS.has(field) && !policy.writable.includes(field)) {
1021
1231
  throw new FieldPolicyError("explicit_field_required", { table: policy.table, field });
1022
1232
  }
1233
+ // A record payload column is written only where the table's own entry lists it.
1234
+ if (recordPayloadColumns(policy.table)?.has(field) && !policy.explicitWritable.includes(field)) {
1235
+ throw new FieldPolicyError("explicit_field_required", { table: policy.table, field });
1236
+ }
1023
1237
  if (!fieldSetAllows(policy.writable, policy.allowAnyWritable, field)) {
1024
1238
  throw new FieldPolicyError("non_writable_field", { table: policy.table, field });
1025
1239
  }
@@ -1252,14 +1466,72 @@ function typeHiddenFields(table) {
1252
1466
  function typeHiddenFieldNames(tableCandidate) {
1253
1467
  return typeHiddenFields(normalizeTableName(tableCandidate));
1254
1468
  }
1469
+ /** Per policy map, the closed record payload columns of each table it names. */
1470
+ const EXPLICIT_READ_DENIED = new WeakMap();
1471
+ /**
1472
+ * The record payload columns of `table` that the current policy does not
1473
+ * open: every one, unless the profile's own entry for the table lists it in
1474
+ * `readable`. With nothing listed the answer is the table's fixed column set,
1475
+ * so nothing is stored; a partial opening is cached per policy map and table,
1476
+ * and only tables the configuration names can reach that cache.
1477
+ */
1478
+ function explicitReadDeniedFields(table) {
1479
+ const fields = recordPayloadColumns(table);
1480
+ if (fields === undefined)
1481
+ return EMPTY_FIELDS;
1482
+ let policies;
1483
+ try {
1484
+ policies = currentTableFieldPolicies();
1485
+ }
1486
+ catch {
1487
+ return fields;
1488
+ }
1489
+ // A table with no entry of its own resolves through "*", which lists none.
1490
+ const listed = policies.get(table)?.explicitReadable ?? NO_FIELDS;
1491
+ if (listed.length === 0)
1492
+ return fields;
1493
+ let byTable = EXPLICIT_READ_DENIED.get(policies);
1494
+ if (!byTable)
1495
+ EXPLICIT_READ_DENIED.set(policies, (byTable = new Map()));
1496
+ const cached = byTable.get(table);
1497
+ if (cached !== undefined)
1498
+ return cached;
1499
+ const denied = Object.freeze(new Set([...fields].filter((field) => !listed.includes(field))));
1500
+ byTable.set(table, denied);
1501
+ return denied;
1502
+ }
1503
+ const READ_HIDDEN_UNIONS = new WeakMap();
1504
+ /**
1505
+ * Every field a read of `table` treats as hidden: its hidden-typed fields and
1506
+ * the record payload columns its policy leaves closed. Writes check types
1507
+ * here and record payload columns in validateWritableFields.
1508
+ */
1509
+ function readHiddenFields(table) {
1510
+ const typed = typeHiddenFields(table);
1511
+ const explicit = explicitReadDeniedFields(table);
1512
+ if (explicit.size === 0)
1513
+ return typed;
1514
+ if (typed.size === 0)
1515
+ return explicit;
1516
+ let byExplicit = READ_HIDDEN_UNIONS.get(typed);
1517
+ if (!byExplicit)
1518
+ READ_HIDDEN_UNIONS.set(typed, (byExplicit = new WeakMap()));
1519
+ let union = byExplicit.get(explicit);
1520
+ if (!union) {
1521
+ union = Object.freeze(new Set([...typed, ...explicit]));
1522
+ byExplicit.set(explicit, union);
1523
+ }
1524
+ return union;
1525
+ }
1255
1526
  /**
1256
1527
  * Fields of `table` that may never filter, order, group or aggregate a read:
1257
- * its hidden-typed fields and its row rule's value field. The sensitive-name
1258
- * check applies on top, wherever a caller checks names.
1528
+ * its hidden-typed fields, the record payload columns its policy leaves closed,
1529
+ * and its row rule's value field. The sensitive-name check applies on top,
1530
+ * wherever a caller checks names.
1259
1531
  */
1260
1532
  function queryDeniedFields(tableCandidate) {
1261
1533
  const table = normalizeTableName(tableCandidate);
1262
- const hidden = typeHiddenFields(table);
1534
+ const hidden = readHiddenFields(table);
1263
1535
  const rule = (0, hidden_values_js_1.rowValueRule)(table);
1264
1536
  return rule === undefined ? hidden : new Set([...hidden, ...rule.queryDenied]);
1265
1537
  }
@@ -1282,11 +1554,11 @@ function readableSelectionForTable(tableCandidate, fields,
1282
1554
  extending) {
1283
1555
  const table = normalizeTableName(tableCandidate);
1284
1556
  const inherited = extending === undefined ? undefined : SELECTION_CONTEXTS.get(extending)?.companions;
1285
- return preparedSelection(table, fields, typeHiddenFields(table), inherited);
1557
+ return preparedSelection(table, fields, readHiddenFields(table), inherited);
1286
1558
  }
1287
1559
  const SELECTION_CONTEXTS = new WeakMap();
1288
1560
  /** A frozen selection that remembers its table's hidden fields and row rule. */
1289
- function boundSelection(table, fields, hidden = typeHiddenFields(table), companions = EMPTY_FIELDS) {
1561
+ function boundSelection(table, fields, hidden = readHiddenFields(table), companions = EMPTY_FIELDS) {
1290
1562
  const selection = Object.freeze([...fields]);
1291
1563
  const rule = (0, hidden_values_js_1.rowValueRule)(table);
1292
1564
  SELECTION_CONTEXTS.set(selection, Object.freeze({ hidden, ...(rule === undefined ? {} : { rule }), companions }));
@@ -1300,7 +1572,7 @@ function boundSelection(table, fields, hidden = typeHiddenFields(table), compani
1300
1572
  const VISIBLE_SELECTIONS = new WeakMap();
1301
1573
  /** A policy-chosen projection (defaults, or "all") without hidden-typed fields. */
1302
1574
  function visibleSelection(table, selection) {
1303
- const hidden = typeHiddenFields(table);
1575
+ const hidden = readHiddenFields(table);
1304
1576
  let byTable = VISIBLE_SELECTIONS.get(selection);
1305
1577
  if (!byTable)
1306
1578
  VISIBLE_SELECTIONS.set(selection, (byTable = new Map()));
@@ -1368,6 +1640,8 @@ function selectionContext(selection) {
1368
1640
  for (const [table, fields] of scope.tables) {
1369
1641
  for (const field of fields)
1370
1642
  hidden.add(field);
1643
+ for (const field of explicitReadDeniedFields(table))
1644
+ hidden.add(field);
1371
1645
  rule ??= (0, hidden_values_js_1.rowValueRule)(table);
1372
1646
  }
1373
1647
  return { hidden, ...(rule === undefined ? {} : { rule }), companions: EMPTY_FIELDS };
@@ -1515,17 +1789,15 @@ function isDeepFrozen(candidate, depth) {
1515
1789
  }
1516
1790
  function mergeFieldPolicyDefinitions(base, configured) {
1517
1791
  const merged = { ...base };
1518
- // A profile's "*" entry also covers the ITSM tables and the named-only
1519
- // tables it does not name, so they are merged even without an entry of their
1520
- // own.
1792
+ // A profile's "*" entry also covers every built-in table that is not a
1793
+ // system table (the ITSM, named-only and platform tables) when the profile
1794
+ // does not name it, so each is merged even without an entry of its own.
1521
1795
  const profileWildcard = Object.hasOwn(configured, FIELD_POLICY_WILDCARD)
1522
1796
  ? configured[FIELD_POLICY_WILDCARD]
1523
1797
  : undefined;
1524
1798
  const tables = new Set(Object.keys(configured));
1525
1799
  if (profileWildcard !== undefined) {
1526
- for (const table of ITSM_TABLES)
1527
- tables.add(table);
1528
- for (const table of NAMED_ONLY_BUILT_INS)
1800
+ for (const table of PROFILE_OWNED_BUILT_INS)
1529
1801
  tables.add(table);
1530
1802
  }
1531
1803
  for (const table of tables) {
@@ -1533,7 +1805,7 @@ function mergeFieldPolicyDefinitions(base, configured) {
1533
1805
  ? configured[table]
1534
1806
  : {};
1535
1807
  const existing = merged[table];
1536
- // Every table but the system tables (ITSM, named-only and custom alike) resolves each
1808
+ // Every table but the system tables (ITSM, named-only, platform and custom alike) resolves each
1537
1809
  // set from its own entry, then the profile's "*" entry, then the base. A
1538
1810
  // named custom table therefore cannot escape a narrowing "*" by stating
1539
1811
  // only the other key. System tables never take the "*" entry.
@@ -1559,6 +1831,10 @@ function mergeFieldPolicyDefinitions(base, configured) {
1559
1831
  // writes has not asked for a restriction, and tableAccess already
1560
1832
  // decided whether this table is reachable at all.
1561
1833
  writable: definition.writable ?? fallback?.writable ?? existing?.writable,
1834
+ // Only the table's own entry can list a record payload column; the "*"
1835
+ // entry and the base never do.
1836
+ ...(definition.readable === undefined ? {} : { ownReadable: definition.readable }),
1837
+ ...(definition.writable === undefined ? {} : { ownWritable: definition.writable }),
1562
1838
  };
1563
1839
  }
1564
1840
  return merged;
@@ -1632,6 +1908,7 @@ function buildFieldPolicyMap(definitions, root) {
1632
1908
  }
1633
1909
  }
1634
1910
  }
1911
+ const payloadColumns = recordPayloadColumns(table);
1635
1912
  return [
1636
1913
  table,
1637
1914
  Object.freeze({
@@ -1641,10 +1918,26 @@ function buildFieldPolicyMap(definitions, root) {
1641
1918
  writable: writableFields,
1642
1919
  allowAnyReadable: readable === FIELD_POLICY_WILDCARD,
1643
1920
  allowAnyWritable: writable === FIELD_POLICY_WILDCARD,
1921
+ explicitReadable: listedPayloadColumns(payloadColumns, definition.ownReadable, definition.readable, readable),
1922
+ explicitWritable: listedPayloadColumns(payloadColumns, definition.ownWritable, definition.writable, writable),
1644
1923
  }),
1645
1924
  ];
1646
1925
  }));
1647
1926
  }
1927
+ /**
1928
+ * The record payload columns an own-entry list names. The merge passes the own
1929
+ * list through as the resolved list, so its normalized form is reused rather
1930
+ * than normalized twice. A wildcard own list names nothing.
1931
+ */
1932
+ function listedPayloadColumns(columns, own, resolvedSource, resolved) {
1933
+ if (columns === undefined || own === undefined)
1934
+ return NO_FIELDS;
1935
+ const normalized = own === resolvedSource ? resolved : normalizePolicyFieldSet(own);
1936
+ if (normalized === FIELD_POLICY_WILDCARD)
1937
+ return NO_FIELDS;
1938
+ const listed = normalized.filter((field) => columns.has(field));
1939
+ return listed.length === 0 ? NO_FIELDS : Object.freeze(listed);
1940
+ }
1648
1941
  /**
1649
1942
  * A malformed field-policy configuration, raised when a profile is loaded.
1650
1943
  *
@@ -2063,7 +2356,7 @@ function normalizePolicyFields(candidates, location) {
2063
2356
  function issuePreparedAccess(args, table, readableFields) {
2064
2357
  const normalizedTable = normalizeTableName(table);
2065
2358
  const previous = issuedPreparedEntries(args).filter((entry) => entry.table !== normalizedTable);
2066
- const hidden = typeHiddenFields(normalizedTable);
2359
+ const hidden = readHiddenFields(normalizedTable);
2067
2360
  const entry = Object.freeze({
2068
2361
  table: normalizedTable,
2069
2362
  readableFields: preparedSelection(normalizedTable, readableFields, hidden),