@onlyflows/servicenow-mcp 2.3.0-dev.3 → 2.3.0-dev.5
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.
- package/CHANGELOG.md +165 -0
- package/README.md +177 -29
- package/dist/atf-policy.d.ts +1 -1
- package/dist/atf-policy.d.ts.map +1 -1
- package/dist/atf-policy.js +2 -0
- package/dist/atf-policy.js.map +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/credential-tables.d.ts +32 -0
- package/dist/credential-tables.d.ts.map +1 -0
- package/dist/credential-tables.js +58 -0
- package/dist/credential-tables.js.map +1 -0
- package/dist/encoded-query-policy.d.ts.map +1 -1
- package/dist/encoded-query-policy.js +8 -1
- package/dist/encoded-query-policy.js.map +1 -1
- package/dist/execution-context.d.ts +14 -0
- package/dist/execution-context.d.ts.map +1 -1
- package/dist/execution-context.js +8 -0
- package/dist/execution-context.js.map +1 -1
- package/dist/field-policy.d.ts +34 -1
- package/dist/field-policy.d.ts.map +1 -1
- package/dist/field-policy.js +308 -25
- package/dist/field-policy.js.map +1 -1
- package/dist/hidden-values.d.ts +225 -0
- package/dist/hidden-values.d.ts.map +1 -0
- package/dist/hidden-values.js +748 -0
- package/dist/hidden-values.js.map +1 -0
- package/dist/http-entrypoint.d.ts.map +1 -1
- package/dist/http-entrypoint.js +7 -0
- package/dist/http-entrypoint.js.map +1 -1
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/metadata-cache.d.ts +38 -0
- package/dist/metadata-cache.d.ts.map +1 -1
- package/dist/metadata-cache.js +76 -3
- package/dist/metadata-cache.js.map +1 -1
- package/dist/policy-card.d.ts +16 -1
- package/dist/policy-card.d.ts.map +1 -1
- package/dist/policy-card.js +13 -2
- package/dist/policy-card.js.map +1 -1
- package/dist/profile-admin.d.ts +18 -0
- package/dist/profile-admin.d.ts.map +1 -1
- package/dist/profile-admin.js +26 -1
- package/dist/profile-admin.js.map +1 -1
- package/dist/profile-manager.d.ts +13 -1
- package/dist/profile-manager.d.ts.map +1 -1
- package/dist/profile-manager.js +23 -1
- package/dist/profile-manager.js.map +1 -1
- package/dist/setup.d.ts +4 -0
- package/dist/setup.d.ts.map +1 -1
- package/dist/setup.js +150 -66
- package/dist/setup.js.map +1 -1
- package/dist/structured-query.d.ts.map +1 -1
- package/dist/structured-query.js +6 -1
- package/dist/structured-query.js.map +1 -1
- package/dist/table-policy.d.ts +34 -1
- package/dist/table-policy.d.ts.map +1 -1
- package/dist/table-policy.js +95 -10
- package/dist/table-policy.js.map +1 -1
- package/dist/tool-error.d.ts +8 -1
- package/dist/tool-error.d.ts.map +1 -1
- package/dist/tool-error.js +23 -0
- package/dist/tool-error.js.map +1 -1
- package/dist/tool-table-access.d.ts.map +1 -1
- package/dist/tool-table-access.js +25 -6
- package/dist/tool-table-access.js.map +1 -1
- package/dist/tools/aggregate.js +2 -2
- package/dist/tools/aggregate.js.map +1 -1
- package/dist/tools/all-fields-cap.d.ts.map +1 -1
- package/dist/tools/all-fields-cap.js +29 -7
- package/dist/tools/all-fields-cap.js.map +1 -1
- package/dist/tools/atf-author-module.d.ts +1 -7
- package/dist/tools/atf-author-module.d.ts.map +1 -1
- package/dist/tools/atf-author-module.js +16 -7
- package/dist/tools/atf-author-module.js.map +1 -1
- package/dist/tools/atf-contracts.d.ts +69 -4
- package/dist/tools/atf-contracts.d.ts.map +1 -1
- package/dist/tools/atf-contracts.js +32 -2
- package/dist/tools/atf-contracts.js.map +1 -1
- package/dist/tools/atf-renderers.js +2 -1
- package/dist/tools/atf-renderers.js.map +1 -1
- package/dist/tools/atf-results-module.d.ts.map +1 -1
- package/dist/tools/atf-results-module.js +5 -3
- package/dist/tools/atf-results-module.js.map +1 -1
- package/dist/tools/atf-run-module.js +3 -2
- package/dist/tools/atf-run-module.js.map +1 -1
- package/dist/tools/atf-shared.d.ts +6 -0
- package/dist/tools/atf-shared.d.ts.map +1 -1
- package/dist/tools/atf-shared.js +49 -10
- package/dist/tools/atf-shared.js.map +1 -1
- package/dist/tools/atf-step-catalog.d.ts +13 -8
- package/dist/tools/atf-step-catalog.d.ts.map +1 -1
- package/dist/tools/atf-step-catalog.js +169 -5
- package/dist/tools/atf-step-catalog.js.map +1 -1
- package/dist/tools/batch.d.ts.map +1 -1
- package/dist/tools/batch.js +4 -2
- package/dist/tools/batch.js.map +1 -1
- package/dist/tools/flow-view-contracts.d.ts +57 -1
- package/dist/tools/flow-view-contracts.d.ts.map +1 -1
- package/dist/tools/flow-view-contracts.js +34 -2
- package/dist/tools/flow-view-contracts.js.map +1 -1
- package/dist/tools/flow-view-graph.d.ts +14 -0
- package/dist/tools/flow-view-graph.d.ts.map +1 -1
- package/dist/tools/flow-view-graph.js +43 -1
- package/dist/tools/flow-view-graph.js.map +1 -1
- package/dist/tools/flow-view-module.js +1 -1
- package/dist/tools/flow-view-module.js.map +1 -1
- package/dist/tools/flow-view-policy.d.ts +3 -3
- package/dist/tools/flow-view-policy.d.ts.map +1 -1
- package/dist/tools/flow-view-policy.js +5 -4
- package/dist/tools/flow-view-policy.js.map +1 -1
- package/dist/tools/flow-view-renderers.d.ts.map +1 -1
- package/dist/tools/flow-view-renderers.js +9 -21
- package/dist/tools/flow-view-renderers.js.map +1 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +80 -13
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/platform-view-contracts.d.ts +189 -0
- package/dist/tools/platform-view-contracts.d.ts.map +1 -0
- package/dist/tools/platform-view-contracts.js +353 -0
- package/dist/tools/platform-view-contracts.js.map +1 -0
- package/dist/tools/platform-view-evaluate.d.ts +11 -0
- package/dist/tools/platform-view-evaluate.d.ts.map +1 -0
- package/dist/tools/platform-view-evaluate.js +19 -0
- package/dist/tools/platform-view-evaluate.js.map +1 -0
- package/dist/tools/platform-view-module.d.ts +28 -0
- package/dist/tools/platform-view-module.d.ts.map +1 -0
- package/dist/tools/platform-view-module.js +111 -0
- package/dist/tools/platform-view-module.js.map +1 -0
- package/dist/tools/platform-view-scan.d.ts +57 -0
- package/dist/tools/platform-view-scan.d.ts.map +1 -0
- package/dist/tools/platform-view-scan.js +375 -0
- package/dist/tools/platform-view-scan.js.map +1 -0
- package/dist/tools/platform-view-upgrades.d.ts +152 -0
- package/dist/tools/platform-view-upgrades.d.ts.map +1 -0
- package/dist/tools/platform-view-upgrades.js +545 -0
- package/dist/tools/platform-view-upgrades.js.map +1 -0
- package/dist/tools/profile.d.ts.map +1 -1
- package/dist/tools/profile.js +1 -0
- package/dist/tools/profile.js.map +1 -1
- package/dist/tools/query-module.js +1 -1
- package/dist/tools/query-module.js.map +1 -1
- package/dist/tools/record-write-shared.d.ts.map +1 -1
- package/dist/tools/record-write-shared.js +4 -3
- package/dist/tools/record-write-shared.js.map +1 -1
- package/dist/tools/result-envelope.d.ts +116 -36
- package/dist/tools/result-envelope.d.ts.map +1 -1
- package/dist/tools/result-envelope.js +38 -3
- package/dist/tools/result-envelope.js.map +1 -1
- package/dist/tools/syslog-cursor.d.ts +61 -0
- package/dist/tools/syslog-cursor.d.ts.map +1 -0
- package/dist/tools/syslog-cursor.js +146 -0
- package/dist/tools/syslog-cursor.js.map +1 -0
- package/dist/tools/syslog.d.ts +2 -0
- package/dist/tools/syslog.d.ts.map +1 -1
- package/dist/tools/syslog.js +126 -2
- package/dist/tools/syslog.js.map +1 -1
- package/dist/update-set-eval/secret-patterns.d.ts +75 -0
- package/dist/update-set-eval/secret-patterns.d.ts.map +1 -0
- package/dist/update-set-eval/secret-patterns.js +570 -0
- package/dist/update-set-eval/secret-patterns.js.map +1 -0
- package/dist/update-set-eval/xml-reader.d.ts +117 -0
- package/dist/update-set-eval/xml-reader.d.ts.map +1 -0
- package/dist/update-set-eval/xml-reader.js +561 -0
- package/dist/update-set-eval/xml-reader.js.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/docs/CLIENT-SETUP.md +8 -6
- package/docs/FLOW-VIEW.md +14 -5
- package/docs/PRODUCTION-SECURITY.md +63 -0
- package/docs/PROFILE-CREDENTIALS.md +10 -4
- package/package.json +1 -1
- package/server.json +2 -2
package/dist/field-policy.js
CHANGED
|
@@ -29,14 +29,21 @@ exports.filterReadableRecord = filterReadableRecord;
|
|
|
29
29
|
exports.filterSchemaEntries = filterSchemaEntries;
|
|
30
30
|
exports.filterAggregateResult = filterAggregateResult;
|
|
31
31
|
exports.runWithFieldPolicyConfiguration = runWithFieldPolicyConfiguration;
|
|
32
|
+
exports.currentFieldPolicyConfiguration = currentFieldPolicyConfiguration;
|
|
32
33
|
exports.isAllFieldSelection = isAllFieldSelection;
|
|
33
34
|
exports.fieldSelectionToSysparmFields = fieldSelectionToSysparmFields;
|
|
34
35
|
exports.isSensitiveFieldName = isSensitiveFieldName;
|
|
36
|
+
exports.typeHiddenFieldNames = typeHiddenFieldNames;
|
|
37
|
+
exports.queryDeniedFields = queryDeniedFields;
|
|
38
|
+
exports.queryDeniedForSelection = queryDeniedForSelection;
|
|
39
|
+
exports.readableSelectionForTable = readableSelectionForTable;
|
|
35
40
|
exports.describeFieldPolicy = describeFieldPolicy;
|
|
36
41
|
exports.validateFieldPolicyConfiguration = validateFieldPolicyConfiguration;
|
|
37
42
|
exports.fieldPolicyInputFromEnvironment = fieldPolicyInputFromEnvironment;
|
|
38
43
|
const node_async_hooks_1 = require("node:async_hooks");
|
|
39
44
|
const node_util_1 = require("node:util");
|
|
45
|
+
const hidden_values_js_1 = require("./hidden-values.js");
|
|
46
|
+
const table_policy_js_1 = require("./table-policy.js");
|
|
40
47
|
const FIELD_NAME = /^[a-z][a-z0-9_]{0,79}$/u;
|
|
41
48
|
/** @deprecated Field authorization no longer caps the number of selected fields. */
|
|
42
49
|
exports.MAX_FIELDS_PER_OPERATION = 10_000;
|
|
@@ -636,6 +643,58 @@ const POLICY_DEFINITIONS = {
|
|
|
636
643
|
readable: ["sys_id", "name", "status", "browser_name", "browser_version", "os_name", "os_version", "sys_updated_on"],
|
|
637
644
|
writable: [],
|
|
638
645
|
},
|
|
646
|
+
// The named-only tables (NAMED_ONLY_TABLES in table-policy.ts). A "*" table
|
|
647
|
+
// grant never covers them: a profile reaches them only by naming them in
|
|
648
|
+
// tableAccess. For field policy they belong to the profile, like the ITSM
|
|
649
|
+
// tables, so a profile's "*" field entry narrows them. Each default
|
|
650
|
+
// projection names the record and field a row is about and leaves the value
|
|
651
|
+
// columns to be asked for by name.
|
|
652
|
+
//
|
|
653
|
+
// The audit and journal tables hold the old and new values of other tables'
|
|
654
|
+
// fields, and their comments and work notes (oldvalue, newvalue, value).
|
|
655
|
+
sys_audit: {
|
|
656
|
+
defaults: ["sys_id", "tablename", "documentkey", "fieldname", "user", "sys_created_on"],
|
|
657
|
+
readable: ["sys_id", "tablename", "documentkey", "fieldname", "oldvalue", "newvalue", "user", "reason", "sys_created_on"],
|
|
658
|
+
writable: [],
|
|
659
|
+
},
|
|
660
|
+
sys_journal_field: {
|
|
661
|
+
defaults: ["sys_id", "name", "element_id", "element", "sys_created_by", "sys_created_on"],
|
|
662
|
+
readable: ["sys_id", "name", "element_id", "element", "value", "sys_created_by", "sys_created_on"],
|
|
663
|
+
writable: [],
|
|
664
|
+
},
|
|
665
|
+
// The history built from audit for a record's history view. Value columns:
|
|
666
|
+
// old, new, old_value, new_value. user_id and email name the actor and stay
|
|
667
|
+
// out of the default projection.
|
|
668
|
+
sys_history_line: {
|
|
669
|
+
defaults: ["sys_id", "set", "field", "label", "update", "update_time", "type"],
|
|
670
|
+
readable: ["sys_id", "set", "field", "label", "update", "update_time", "type", "user_name", "old", "new", "old_value", "new_value", "sys_created_on"],
|
|
671
|
+
writable: [],
|
|
672
|
+
},
|
|
673
|
+
// A deleted record, kept whole. Value column: payload (the record's XML).
|
|
674
|
+
sys_audit_delete: {
|
|
675
|
+
defaults: ["sys_id", "tablename", "documentkey", "display_value", "sys_created_on", "sys_created_by"],
|
|
676
|
+
readable: ["sys_id", "tablename", "documentkey", "display_value", "payload", "sys_created_on", "sys_created_by"],
|
|
677
|
+
writable: [],
|
|
678
|
+
},
|
|
679
|
+
// Attachment content, in chunks. Value column: data. sn_attach does not read
|
|
680
|
+
// this table: it uses the Attachment API, under the grants of sys_attachment
|
|
681
|
+
// and the parent table.
|
|
682
|
+
sys_attachment_doc: {
|
|
683
|
+
defaults: ["sys_id", "sys_attachment", "position", "length", "sys_created_on"],
|
|
684
|
+
readable: ["sys_id", "sys_attachment", "position", "length", "data", "sys_created_on"],
|
|
685
|
+
writable: [],
|
|
686
|
+
},
|
|
687
|
+
// Notification copies. Content columns: body, body_text, subject,
|
|
688
|
+
// recipients, copied, blind_copied, reply_to, headers, error_string.
|
|
689
|
+
sys_email: {
|
|
690
|
+
defaults: ["sys_id", "type", "state", "target_table", "instance", "sys_created_on"],
|
|
691
|
+
readable: [
|
|
692
|
+
"sys_id", "type", "state", "notification_type", "target_table", "instance", "mailbox",
|
|
693
|
+
"subject", "body", "body_text", "recipients", "copied", "blind_copied", "reply_to",
|
|
694
|
+
"headers", "error_string", "sys_created_on",
|
|
695
|
+
],
|
|
696
|
+
writable: [],
|
|
697
|
+
},
|
|
639
698
|
};
|
|
640
699
|
/**
|
|
641
700
|
* The policy base.
|
|
@@ -652,9 +711,9 @@ const POLICY_DEFINITIONS = {
|
|
|
652
711
|
* a granted custom table needs no field-policy entry to be usable.
|
|
653
712
|
*
|
|
654
713
|
* A profile's own "*" entry reaches further: it also covers the ITSM tables
|
|
655
|
-
* (ITSM_TABLES)
|
|
656
|
-
* table's own entry is silent.
|
|
657
|
-
* never covered by a "*" entry.
|
|
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.
|
|
716
|
+
* Only the system tables (SYSTEM_TABLES) are never covered by a "*" entry.
|
|
658
717
|
*/
|
|
659
718
|
const FIELD_POLICY_BASE = Object.freeze({
|
|
660
719
|
...Object.fromEntries(Object.entries(POLICY_DEFINITIONS).map(([table, definition]) => [
|
|
@@ -700,8 +759,9 @@ const ITSM_TABLES = new Set([
|
|
|
700
759
|
*
|
|
701
760
|
* This list is written out rather than derived as "built-in minus ITSM", so
|
|
702
761
|
* a new built-in entry never escapes every profile's "*" entry by default.
|
|
703
|
-
* Each built-in entry must be in exactly one of ITSM_TABLES
|
|
704
|
-
*
|
|
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
|
|
764
|
+
* BUILT_IN_TABLE_CLASSES.
|
|
705
765
|
*/
|
|
706
766
|
const SYSTEM_TABLES = new Set([
|
|
707
767
|
"sys_user",
|
|
@@ -729,6 +789,16 @@ const SYSTEM_TABLES = new Set([
|
|
|
729
789
|
"sys_atf_test_result_step",
|
|
730
790
|
"sys_atf_agent",
|
|
731
791
|
]);
|
|
792
|
+
/**
|
|
793
|
+
* Built-in tables that a "*" table grant never covers (NAMED_ONLY_TABLES, in
|
|
794
|
+
* table-policy.ts, the one list). For field policy they are profile-owned like
|
|
795
|
+
* the ITSM tables: `readable` and `writable` resolve from the profile's own
|
|
796
|
+
* entry for the table, then its "*" entry, then the built-in "*" (open), so a
|
|
797
|
+
* profile that narrows reads with "*" narrows these too. Their built-in
|
|
798
|
+
* `defaults` leave out the value columns and are clamped to the effective
|
|
799
|
+
* readable set. A table's own entry still narrows or widens it.
|
|
800
|
+
*/
|
|
801
|
+
const NAMED_ONLY_BUILT_INS = new Set(table_policy_js_1.NAMED_ONLY_TABLES);
|
|
732
802
|
/**
|
|
733
803
|
* The built-in tables and how each is classified for a profile's "*" entry.
|
|
734
804
|
* Frozen copies for tests; the policy reads the sets above.
|
|
@@ -737,6 +807,7 @@ exports.BUILT_IN_TABLE_CLASSES = Object.freeze({
|
|
|
737
807
|
builtIn: Object.freeze(Object.keys(POLICY_DEFINITIONS)),
|
|
738
808
|
itsm: Object.freeze([...ITSM_TABLES]),
|
|
739
809
|
system: Object.freeze([...SYSTEM_TABLES]),
|
|
810
|
+
namedOnly: Object.freeze([...NAMED_ONLY_BUILT_INS]),
|
|
740
811
|
});
|
|
741
812
|
const GENERIC_RECORD_TABLES = new Set([
|
|
742
813
|
"incident",
|
|
@@ -818,7 +889,11 @@ function fieldPolicyDenialMessage(error) {
|
|
|
818
889
|
`fieldPolicy.${table}, or a fieldPolicy."*" fallback, to allow it.`
|
|
819
890
|
: "Access denied by policy: the requested table has no field policy entry.";
|
|
820
891
|
case "sensitive_field":
|
|
892
|
+
// The same text for a name and a type denial: saying which would tell
|
|
893
|
+
// the caller a field's type, which is what the type rule keeps back.
|
|
821
894
|
return "Access denied by policy: a requested field is denied by name as sensitive and cannot be granted by configuration.";
|
|
895
|
+
case "field_types_unavailable":
|
|
896
|
+
return hidden_values_js_1.FIELD_TYPES_UNAVAILABLE_MESSAGE;
|
|
822
897
|
case "explicit_field_required":
|
|
823
898
|
// Only the EXPLICIT_WRITE_FIELDS names reach this case; each is a fixed
|
|
824
899
|
// name that passed FIELD_NAME.
|
|
@@ -877,15 +952,17 @@ function resolveReadableFields(tableCandidate, input = {}) {
|
|
|
877
952
|
const canonicalInput = snapshotPlainDataArguments(input);
|
|
878
953
|
const responseFormat = normalizeResponseFormat(canonicalInput.responseFormat);
|
|
879
954
|
const requested = canonicalInput.fields;
|
|
955
|
+
const hidden = typeHiddenFields(policy.table);
|
|
956
|
+
const queryDenied = canonicalInput.purpose === "query" ? (0, hidden_values_js_1.rowValueRule)(policy.table)?.queryDenied : undefined;
|
|
880
957
|
if (requested === undefined) {
|
|
881
|
-
return requireNonEmptySelection(responseFormat === "detailed" ? readableSelection(policy) : policy.defaults);
|
|
958
|
+
return visibleSelection(policy.table, requireNonEmptySelection(responseFormat === "detailed" ? readableSelection(policy) : policy.defaults));
|
|
882
959
|
}
|
|
883
960
|
if (typeof requested !== "string") {
|
|
884
961
|
throw new FieldPolicyError("invalid_field_selection");
|
|
885
962
|
}
|
|
886
963
|
const trimmed = requested.trim();
|
|
887
964
|
if (trimmed.toLowerCase() === "all") {
|
|
888
|
-
return requireNonEmptySelection(readableSelection(policy));
|
|
965
|
+
return visibleSelection(policy.table, requireNonEmptySelection(readableSelection(policy)));
|
|
889
966
|
}
|
|
890
967
|
if (!trimmed)
|
|
891
968
|
throw new FieldPolicyError("invalid_field_selection");
|
|
@@ -895,7 +972,10 @@ function resolveReadableFields(tableCandidate, input = {}) {
|
|
|
895
972
|
const field = normalizeFieldName(candidate);
|
|
896
973
|
if (seen.has(field))
|
|
897
974
|
throw new FieldPolicyError("invalid_field_selection");
|
|
898
|
-
|
|
975
|
+
// A hidden-typed field is refused exactly like a sensitive name, with the
|
|
976
|
+
// same message, before the readable check, so the refusal says nothing
|
|
977
|
+
// about the field's type or whether a configuration could grant it.
|
|
978
|
+
if (isSensitiveFieldName(field) || hidden.has(field) || queryDenied?.has(field)) {
|
|
899
979
|
throw new FieldPolicyError("sensitive_field", { table: policy.table });
|
|
900
980
|
}
|
|
901
981
|
if (!fieldSetAllows(policy.readable, policy.allowAnyReadable, field)) {
|
|
@@ -904,7 +984,7 @@ function resolveReadableFields(tableCandidate, input = {}) {
|
|
|
904
984
|
seen.add(field);
|
|
905
985
|
selected.push(field);
|
|
906
986
|
}
|
|
907
|
-
return
|
|
987
|
+
return boundSelection(policy.table, selected);
|
|
908
988
|
}
|
|
909
989
|
/** Validate and clone one Table API write map using the separate write set. */
|
|
910
990
|
function validateWritableFields(tableCandidate, payloadCandidate) {
|
|
@@ -932,7 +1012,7 @@ function validateWritableFields(tableCandidate, payloadCandidate) {
|
|
|
932
1012
|
if (Object.hasOwn(output, field)) {
|
|
933
1013
|
throw new FieldPolicyError("invalid_write_payload");
|
|
934
1014
|
}
|
|
935
|
-
if (isSensitiveFieldName(field)) {
|
|
1015
|
+
if (isSensitiveFieldName(field) || typeHiddenFields(policy.table).has(field)) {
|
|
936
1016
|
throw new FieldPolicyError("sensitive_field", { table: policy.table });
|
|
937
1017
|
}
|
|
938
1018
|
// policy.writable holds only explicitly listed names; it is empty when
|
|
@@ -1024,7 +1104,8 @@ function preparedReadableFields(args, tableCandidate) {
|
|
|
1024
1104
|
if (!Array.isArray(fields) || !Object.isFrozen(fields))
|
|
1025
1105
|
return undefined;
|
|
1026
1106
|
if (isAllFieldSelection(fields)) {
|
|
1027
|
-
|
|
1107
|
+
// The entry's own wildcard, which carries its table's hidden fields.
|
|
1108
|
+
return policy.allowAnyReadable ? fields : undefined;
|
|
1028
1109
|
}
|
|
1029
1110
|
if (fields.some((field) => typeof field !== "string" ||
|
|
1030
1111
|
!fieldSetAllows(policy.readable, policy.allowAnyReadable, field))) {
|
|
@@ -1040,12 +1121,12 @@ function preparedReadableFields(args, tableCandidate) {
|
|
|
1040
1121
|
function filterReadableRecord(candidate, readableFields) {
|
|
1041
1122
|
if (node_util_1.types.isProxy(readableFields))
|
|
1042
1123
|
return null;
|
|
1124
|
+
const context = selectionContext(readableFields);
|
|
1043
1125
|
const state = responseTraversalState();
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
return filterRecordNode(candidate, approved, state, 0);
|
|
1126
|
+
const filtered = isAllFieldSelection(readableFields)
|
|
1127
|
+
? sanitizeNestedValue(candidate, state, 0)
|
|
1128
|
+
: filterRecordNode(candidate, new Set(readableFields.map(normalizeFieldName)), state, 0);
|
|
1129
|
+
return context === undefined ? filtered : applyHiddenRules(filtered, context);
|
|
1049
1130
|
}
|
|
1050
1131
|
/** Remove metadata entries for fields the caller is not permitted to discover. */
|
|
1051
1132
|
function filterSchemaEntries(candidate, readableFields) {
|
|
@@ -1106,15 +1187,26 @@ function filterSchemaEntries(candidate, readableFields) {
|
|
|
1106
1187
|
function filterAggregateResult(candidate, readableFields) {
|
|
1107
1188
|
if (node_util_1.types.isProxy(readableFields))
|
|
1108
1189
|
return null;
|
|
1190
|
+
const hidden = selectionContext(readableFields)?.hidden ?? EMPTY_FIELDS;
|
|
1109
1191
|
const state = responseTraversalState();
|
|
1110
1192
|
if (isAllFieldSelection(readableFields)) {
|
|
1111
|
-
|
|
1193
|
+
const sanitized = sanitizeNestedValue(candidate, state, 0);
|
|
1194
|
+
return hidden.size === 0 ? sanitized : withoutAggregateFields(sanitized, hidden, 0);
|
|
1112
1195
|
}
|
|
1113
|
-
const approved = new Set(readableFields.map(normalizeFieldName));
|
|
1196
|
+
const approved = new Set(readableFields.map(normalizeFieldName).filter((field) => !hidden.has(field)));
|
|
1114
1197
|
return filterAggregateNode(candidate, approved, state, 0);
|
|
1115
1198
|
}
|
|
1116
1199
|
function runWithFieldPolicyConfiguration(configuration, callback) {
|
|
1117
|
-
return FIELD_POLICY_CONFIGURATION_SCOPE.run(configuration ??
|
|
1200
|
+
return FIELD_POLICY_CONFIGURATION_SCOPE.run(configuration ?? NO_FIELD_POLICY_CONFIGURATION, callback);
|
|
1201
|
+
}
|
|
1202
|
+
const NO_FIELD_POLICY_CONFIGURATION = Object.freeze({});
|
|
1203
|
+
/**
|
|
1204
|
+
* The field-policy configuration in force, as an identity: two preparations
|
|
1205
|
+
* that see the same object were checked against the same policy. Undefined
|
|
1206
|
+
* outside a configuration scope.
|
|
1207
|
+
*/
|
|
1208
|
+
function currentFieldPolicyConfiguration() {
|
|
1209
|
+
return FIELD_POLICY_CONFIGURATION_SCOPE.getStore();
|
|
1118
1210
|
}
|
|
1119
1211
|
/** True when a field selection means ServiceNow should return all fields. */
|
|
1120
1212
|
function isAllFieldSelection(selection) {
|
|
@@ -1134,6 +1226,194 @@ function isSensitiveFieldName(candidate) {
|
|
|
1134
1226
|
return (/(?:^|_)(?:password|passwd|credential|credentials|secret|token|api_key|private_key|encryption_key|ssn)(?:_|$)/u.test(normalized) ||
|
|
1135
1227
|
normalized === "social_security_number");
|
|
1136
1228
|
}
|
|
1229
|
+
const EMPTY_FIELDS = Object.freeze(new Set());
|
|
1230
|
+
/**
|
|
1231
|
+
* Type hiding. The dispatcher resolves each table's hidden-typed fields
|
|
1232
|
+
* (`hidden-values.ts`) before a call's plan is prepared and runs the plan and
|
|
1233
|
+
* the handler inside that scope. Every check above then treats a hidden-typed
|
|
1234
|
+
* field like a sensitive name: refused when named (with the same message),
|
|
1235
|
+
* dropped from a wildcard or configured projection, never written, and never
|
|
1236
|
+
* used to filter, order or group. Outside a dispatched call there is no scope
|
|
1237
|
+
* and only names are checked.
|
|
1238
|
+
*/
|
|
1239
|
+
function typeHiddenFields(table) {
|
|
1240
|
+
const scope = (0, hidden_values_js_1.currentHiddenFieldScope)();
|
|
1241
|
+
if (scope === undefined)
|
|
1242
|
+
return EMPTY_FIELDS;
|
|
1243
|
+
const hidden = scope.tables.get(table);
|
|
1244
|
+
if (hidden !== undefined)
|
|
1245
|
+
return hidden;
|
|
1246
|
+
if (scope.unresolved === "names_only")
|
|
1247
|
+
return EMPTY_FIELDS;
|
|
1248
|
+
// A table outside the call's resolved plan has unknown types: refuse.
|
|
1249
|
+
throw new FieldPolicyError("field_types_unavailable", { table });
|
|
1250
|
+
}
|
|
1251
|
+
/** The hidden-typed fields of `table` in the running call; empty outside one. */
|
|
1252
|
+
function typeHiddenFieldNames(tableCandidate) {
|
|
1253
|
+
return typeHiddenFields(normalizeTableName(tableCandidate));
|
|
1254
|
+
}
|
|
1255
|
+
/**
|
|
1256
|
+
* 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.
|
|
1259
|
+
*/
|
|
1260
|
+
function queryDeniedFields(tableCandidate) {
|
|
1261
|
+
const table = normalizeTableName(tableCandidate);
|
|
1262
|
+
const hidden = typeHiddenFields(table);
|
|
1263
|
+
const rule = (0, hidden_values_js_1.rowValueRule)(table);
|
|
1264
|
+
return rule === undefined ? hidden : new Set([...hidden, ...rule.queryDenied]);
|
|
1265
|
+
}
|
|
1266
|
+
/** {@link queryDeniedFields} for the table a selection was resolved on. */
|
|
1267
|
+
function queryDeniedForSelection(selection) {
|
|
1268
|
+
const context = selectionContext(selection);
|
|
1269
|
+
if (context === undefined)
|
|
1270
|
+
return EMPTY_FIELDS;
|
|
1271
|
+
return context.rule === undefined
|
|
1272
|
+
? context.hidden
|
|
1273
|
+
: new Set([...context.hidden, ...context.rule.queryDenied]);
|
|
1274
|
+
}
|
|
1275
|
+
/**
|
|
1276
|
+
* Bind a projection the caller built itself (the bounded all-fields list) to
|
|
1277
|
+
* its table, without its hidden-typed fields, so the response filter applies
|
|
1278
|
+
* the table's rules to it.
|
|
1279
|
+
*/
|
|
1280
|
+
function readableSelectionForTable(tableCandidate, fields,
|
|
1281
|
+
/** A selection this one extends; fields it added to fetch a type stay removed. */
|
|
1282
|
+
extending) {
|
|
1283
|
+
const table = normalizeTableName(tableCandidate);
|
|
1284
|
+
const inherited = extending === undefined ? undefined : SELECTION_CONTEXTS.get(extending)?.companions;
|
|
1285
|
+
return preparedSelection(table, fields, typeHiddenFields(table), inherited);
|
|
1286
|
+
}
|
|
1287
|
+
const SELECTION_CONTEXTS = new WeakMap();
|
|
1288
|
+
/** A frozen selection that remembers its table's hidden fields and row rule. */
|
|
1289
|
+
function boundSelection(table, fields, hidden = typeHiddenFields(table), companions = EMPTY_FIELDS) {
|
|
1290
|
+
const selection = Object.freeze([...fields]);
|
|
1291
|
+
const rule = (0, hidden_values_js_1.rowValueRule)(table);
|
|
1292
|
+
SELECTION_CONTEXTS.set(selection, Object.freeze({ hidden, ...(rule === undefined ? {} : { rule }), companions }));
|
|
1293
|
+
return selection;
|
|
1294
|
+
}
|
|
1295
|
+
/**
|
|
1296
|
+
* Bound copies of policy-chosen projections, per source list, table and
|
|
1297
|
+
* hidden set, so repeated resolutions in one scope return the same frozen
|
|
1298
|
+
* object (as they did before selections were bound).
|
|
1299
|
+
*/
|
|
1300
|
+
const VISIBLE_SELECTIONS = new WeakMap();
|
|
1301
|
+
/** A policy-chosen projection (defaults, or "all") without hidden-typed fields. */
|
|
1302
|
+
function visibleSelection(table, selection) {
|
|
1303
|
+
const hidden = typeHiddenFields(table);
|
|
1304
|
+
let byTable = VISIBLE_SELECTIONS.get(selection);
|
|
1305
|
+
if (!byTable)
|
|
1306
|
+
VISIBLE_SELECTIONS.set(selection, (byTable = new Map()));
|
|
1307
|
+
let byHidden = byTable.get(table);
|
|
1308
|
+
if (!byHidden)
|
|
1309
|
+
byTable.set(table, (byHidden = new WeakMap()));
|
|
1310
|
+
const cached = byHidden.get(hidden);
|
|
1311
|
+
if (cached)
|
|
1312
|
+
return cached;
|
|
1313
|
+
const bound = isAllFieldSelection(selection)
|
|
1314
|
+
? boundSelection(table, ALL_FIELDS_SELECTION, hidden)
|
|
1315
|
+
: boundSelection(table, requireNonEmptySelection(selection.filter((field) => !hidden.has(field))), hidden);
|
|
1316
|
+
byHidden.set(hidden, bound);
|
|
1317
|
+
return bound;
|
|
1318
|
+
}
|
|
1319
|
+
/**
|
|
1320
|
+
* The projection a prepared marker carries: hidden-typed fields removed, and
|
|
1321
|
+
* a row rule's type field added when its value field is selected, so each
|
|
1322
|
+
* row's type comes back to decide the value (the type is dropped from the
|
|
1323
|
+
* output again).
|
|
1324
|
+
*/
|
|
1325
|
+
function preparedSelection(table, readableFields, hidden, inheritedCompanions = EMPTY_FIELDS) {
|
|
1326
|
+
if (isAllFieldSelection(readableFields)) {
|
|
1327
|
+
return boundSelection(table, ALL_FIELDS_SELECTION, hidden);
|
|
1328
|
+
}
|
|
1329
|
+
let fields = readableFields.filter((field) => !hidden.has(field));
|
|
1330
|
+
if (fields.length === 0)
|
|
1331
|
+
fields = [...WRITE_ONLY_RESPONSE_FIELDS];
|
|
1332
|
+
const rule = (0, hidden_values_js_1.rowValueRule)(table);
|
|
1333
|
+
if (rule !== undefined &&
|
|
1334
|
+
fields.includes(rule.valueField) &&
|
|
1335
|
+
!fields.includes(rule.typeField) &&
|
|
1336
|
+
!hidden.has(rule.typeField) &&
|
|
1337
|
+
typeFieldReadable(table, rule.typeField)) {
|
|
1338
|
+
return boundSelection(table, [...fields, rule.typeField], hidden, new Set([...inheritedCompanions, rule.typeField]));
|
|
1339
|
+
}
|
|
1340
|
+
return boundSelection(table, fields, hidden, inheritedCompanions);
|
|
1341
|
+
}
|
|
1342
|
+
function typeFieldReadable(table, field) {
|
|
1343
|
+
try {
|
|
1344
|
+
const policy = requirePolicy(table);
|
|
1345
|
+
return (!isSensitiveFieldName(field) &&
|
|
1346
|
+
fieldSetAllows(policy.readable, policy.allowAnyReadable, field));
|
|
1347
|
+
}
|
|
1348
|
+
catch {
|
|
1349
|
+
return false;
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
/**
|
|
1353
|
+
* The rules for a selection: its own table's when it was resolved here, else,
|
|
1354
|
+
* inside a dispatched call, the union over the call's tables (a projection
|
|
1355
|
+
* built elsewhere is held to what any table of the call hides).
|
|
1356
|
+
*/
|
|
1357
|
+
function selectionContext(selection) {
|
|
1358
|
+
if (typeof selection === "object" && selection !== null) {
|
|
1359
|
+
const bound = SELECTION_CONTEXTS.get(selection);
|
|
1360
|
+
if (bound !== undefined)
|
|
1361
|
+
return bound;
|
|
1362
|
+
}
|
|
1363
|
+
const scope = (0, hidden_values_js_1.currentHiddenFieldScope)();
|
|
1364
|
+
if (scope === undefined)
|
|
1365
|
+
return undefined;
|
|
1366
|
+
const hidden = new Set();
|
|
1367
|
+
let rule;
|
|
1368
|
+
for (const [table, fields] of scope.tables) {
|
|
1369
|
+
for (const field of fields)
|
|
1370
|
+
hidden.add(field);
|
|
1371
|
+
rule ??= (0, hidden_values_js_1.rowValueRule)(table);
|
|
1372
|
+
}
|
|
1373
|
+
return { hidden, ...(rule === undefined ? {} : { rule }), companions: EMPTY_FIELDS };
|
|
1374
|
+
}
|
|
1375
|
+
/** Drop hidden-typed fields, apply the row rule, drop companions: per record. */
|
|
1376
|
+
function applyHiddenRules(filtered, context) {
|
|
1377
|
+
if (context.hidden.size === 0 && context.rule === undefined && context.companions.size === 0) {
|
|
1378
|
+
return filtered;
|
|
1379
|
+
}
|
|
1380
|
+
return Array.isArray(filtered)
|
|
1381
|
+
? filtered.map((record) => hideInRecord(record, context))
|
|
1382
|
+
: hideInRecord(filtered, context);
|
|
1383
|
+
}
|
|
1384
|
+
function hideInRecord(record, context) {
|
|
1385
|
+
if (typeof record !== "object" || record === null || Array.isArray(record))
|
|
1386
|
+
return record;
|
|
1387
|
+
const output = (0, hidden_values_js_1.withoutFields)(record, context.hidden);
|
|
1388
|
+
const rule = context.rule;
|
|
1389
|
+
if (rule !== undefined && Object.hasOwn(output, rule.valueField) && (0, hidden_values_js_1.rowValueHidden)(rule, output)) {
|
|
1390
|
+
Reflect.deleteProperty(output, rule.valueField);
|
|
1391
|
+
}
|
|
1392
|
+
for (const companion of context.companions)
|
|
1393
|
+
Reflect.deleteProperty(output, companion);
|
|
1394
|
+
return output;
|
|
1395
|
+
}
|
|
1396
|
+
/** Remove hidden fields from already-sanitized aggregate data, at any depth. */
|
|
1397
|
+
function withoutAggregateFields(candidate, hidden, depth) {
|
|
1398
|
+
if (typeof candidate !== "object" || candidate === null || depth > exports.MAX_FIELD_VALUE_DEPTH) {
|
|
1399
|
+
return candidate;
|
|
1400
|
+
}
|
|
1401
|
+
if (Array.isArray(candidate)) {
|
|
1402
|
+
return candidate
|
|
1403
|
+
.filter((entry) => {
|
|
1404
|
+
if (typeof entry !== "object" || entry === null || Array.isArray(entry))
|
|
1405
|
+
return true;
|
|
1406
|
+
const field = entry.field;
|
|
1407
|
+
return typeof field !== "string" || !hidden.has(field.trim().toLowerCase());
|
|
1408
|
+
})
|
|
1409
|
+
.map((entry) => withoutAggregateFields(entry, hidden, depth + 1));
|
|
1410
|
+
}
|
|
1411
|
+
const output = {};
|
|
1412
|
+
for (const [key, value] of Object.entries((0, hidden_values_js_1.withoutFields)(candidate, hidden))) {
|
|
1413
|
+
safeDefine(output, key, withoutAggregateFields(value, hidden, depth + 1));
|
|
1414
|
+
}
|
|
1415
|
+
return output;
|
|
1416
|
+
}
|
|
1137
1417
|
/** Names the writable wildcard never covers; a profile must list each one. */
|
|
1138
1418
|
exports.EXPLICIT_WRITE_FIELD_NAMES = Object.freeze([
|
|
1139
1419
|
...EXPLICIT_WRITE_FIELDS,
|
|
@@ -1235,8 +1515,9 @@ function isDeepFrozen(candidate, depth) {
|
|
|
1235
1515
|
}
|
|
1236
1516
|
function mergeFieldPolicyDefinitions(base, configured) {
|
|
1237
1517
|
const merged = { ...base };
|
|
1238
|
-
// A profile's "*" entry also covers the ITSM tables
|
|
1239
|
-
// they are merged even without an entry of their
|
|
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.
|
|
1240
1521
|
const profileWildcard = Object.hasOwn(configured, FIELD_POLICY_WILDCARD)
|
|
1241
1522
|
? configured[FIELD_POLICY_WILDCARD]
|
|
1242
1523
|
: undefined;
|
|
@@ -1244,13 +1525,15 @@ function mergeFieldPolicyDefinitions(base, configured) {
|
|
|
1244
1525
|
if (profileWildcard !== undefined) {
|
|
1245
1526
|
for (const table of ITSM_TABLES)
|
|
1246
1527
|
tables.add(table);
|
|
1528
|
+
for (const table of NAMED_ONLY_BUILT_INS)
|
|
1529
|
+
tables.add(table);
|
|
1247
1530
|
}
|
|
1248
1531
|
for (const table of tables) {
|
|
1249
1532
|
const definition = Object.hasOwn(configured, table)
|
|
1250
1533
|
? configured[table]
|
|
1251
1534
|
: {};
|
|
1252
1535
|
const existing = merged[table];
|
|
1253
|
-
// Every table but the system tables (ITSM and custom alike) resolves each
|
|
1536
|
+
// Every table but the system tables (ITSM, named-only and custom alike) resolves each
|
|
1254
1537
|
// set from its own entry, then the profile's "*" entry, then the base. A
|
|
1255
1538
|
// named custom table therefore cannot escape a narrowing "*" by stating
|
|
1256
1539
|
// only the other key. System tables never take the "*" entry.
|
|
@@ -1780,11 +2063,11 @@ function normalizePolicyFields(candidates, location) {
|
|
|
1780
2063
|
function issuePreparedAccess(args, table, readableFields) {
|
|
1781
2064
|
const normalizedTable = normalizeTableName(table);
|
|
1782
2065
|
const previous = issuedPreparedEntries(args).filter((entry) => entry.table !== normalizedTable);
|
|
2066
|
+
const hidden = typeHiddenFields(normalizedTable);
|
|
1783
2067
|
const entry = Object.freeze({
|
|
1784
2068
|
table: normalizedTable,
|
|
1785
|
-
readableFields:
|
|
1786
|
-
|
|
1787
|
-
: Object.freeze([...readableFields]),
|
|
2069
|
+
readableFields: preparedSelection(normalizedTable, readableFields, hidden),
|
|
2070
|
+
hiddenFields: Object.freeze([...hidden].sort()),
|
|
1788
2071
|
});
|
|
1789
2072
|
const marker = Object.freeze({
|
|
1790
2073
|
entries: Object.freeze([...previous, entry]),
|