@memberjunction/server 6.1.0-edge.5 → 6.1.0-edge.7
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/README.md +30 -11
- package/dist/.tsbuildinfo +1 -1
- package/dist/agentSessions/SessionJanitor.js +2 -2
- package/dist/agentSessions/SessionJanitor.js.map +1 -1
- package/dist/auth/exampleNewUserSubClass.d.ts.map +1 -1
- package/dist/auth/exampleNewUserSubClass.js +9 -4
- package/dist/auth/exampleNewUserSubClass.js.map +1 -1
- package/dist/auth/magicLink/MagicLinkService.d.ts.map +1 -1
- package/dist/auth/magicLink/MagicLinkService.js +2 -8
- package/dist/auth/magicLink/MagicLinkService.js.map +1 -1
- package/dist/auth/newUsers.d.ts.map +1 -1
- package/dist/auth/newUsers.js +4 -12
- package/dist/auth/newUsers.js.map +1 -1
- package/dist/auth/principals.d.ts +92 -0
- package/dist/auth/principals.d.ts.map +1 -0
- package/dist/auth/principals.js +193 -0
- package/dist/auth/principals.js.map +1 -0
- package/dist/config.d.ts +106 -12
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +41 -4
- package/dist/config.js.map +1 -1
- package/dist/entitySubclasses/MJEntityPermissionEntityServer.server.d.ts +30 -0
- package/dist/entitySubclasses/MJEntityPermissionEntityServer.server.d.ts.map +1 -1
- package/dist/entitySubclasses/MJEntityPermissionEntityServer.server.js +58 -5
- package/dist/entitySubclasses/MJEntityPermissionEntityServer.server.js.map +1 -1
- package/dist/generated/graphql-schemas/__mj.d.ts +7607 -6853
- package/dist/generated/graphql-schemas/__mj.d.ts.map +1 -1
- package/dist/generated/graphql-schemas/__mj.js +25141 -21645
- package/dist/generated/graphql-schemas/__mj.js.map +1 -1
- package/dist/generic/ResolverBase.d.ts +152 -2
- package/dist/generic/ResolverBase.d.ts.map +1 -1
- package/dist/generic/ResolverBase.js +389 -10
- package/dist/generic/ResolverBase.js.map +1 -1
- package/dist/generic/RunViewResolver.d.ts.map +1 -1
- package/dist/generic/RunViewResolver.js +26 -2
- package/dist/generic/RunViewResolver.js.map +1 -1
- package/dist/generic/refusalExtensions.d.ts +52 -0
- package/dist/generic/refusalExtensions.d.ts.map +1 -0
- package/dist/generic/refusalExtensions.js +16 -0
- package/dist/generic/refusalExtensions.js.map +1 -0
- package/dist/index.d.ts +11 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +131 -93
- package/dist/index.js.map +1 -1
- package/dist/realtimeWidget/WidgetSessionService.d.ts.map +1 -1
- package/dist/realtimeWidget/WidgetSessionService.js +2 -12
- package/dist/realtimeWidget/WidgetSessionService.js.map +1 -1
- package/dist/realtimeWidget/visitorIdentity.d.ts.map +1 -1
- package/dist/realtimeWidget/visitorIdentity.js +20 -5
- package/dist/realtimeWidget/visitorIdentity.js.map +1 -1
- package/dist/resolvers/EntityRecordNameResolver.d.ts +34 -5
- package/dist/resolvers/EntityRecordNameResolver.d.ts.map +1 -1
- package/dist/resolvers/EntityRecordNameResolver.js +64 -7
- package/dist/resolvers/EntityRecordNameResolver.js.map +1 -1
- package/dist/resolvers/FileCategoryResolver.d.ts.map +1 -1
- package/dist/resolvers/FileCategoryResolver.js +1 -2
- package/dist/resolvers/FileCategoryResolver.js.map +1 -1
- package/dist/resolvers/IntegrationDiscoveryResolver.d.ts.map +1 -1
- package/dist/resolvers/IntegrationDiscoveryResolver.js +2 -0
- package/dist/resolvers/IntegrationDiscoveryResolver.js.map +1 -1
- package/dist/resolvers/QuerySystemUserResolver.js +1 -1
- package/dist/resolvers/QuerySystemUserResolver.js.map +1 -1
- package/dist/resolvers/RealtimeClientSessionResolver.d.ts +10 -2
- package/dist/resolvers/RealtimeClientSessionResolver.d.ts.map +1 -1
- package/dist/resolvers/RealtimeClientSessionResolver.js +80 -4
- package/dist/resolvers/RealtimeClientSessionResolver.js.map +1 -1
- package/dist/resolvers/RemoteBrowserActionResolver.d.ts +13 -8
- package/dist/resolvers/RemoteBrowserActionResolver.d.ts.map +1 -1
- package/dist/resolvers/RemoteBrowserActionResolver.js +45 -8
- package/dist/resolvers/RemoteBrowserActionResolver.js.map +1 -1
- package/dist/resolvers/SyncRolesUsersResolver.d.ts.map +1 -1
- package/dist/resolvers/SyncRolesUsersResolver.js +11 -2
- package/dist/resolvers/SyncRolesUsersResolver.js.map +1 -1
- package/dist/resolvers/UserViewResolver.d.ts.map +1 -1
- package/dist/resolvers/UserViewResolver.js +8 -4
- package/dist/resolvers/UserViewResolver.js.map +1 -1
- package/dist/rest/EntityCRUDHandler.d.ts +2 -1
- package/dist/rest/EntityCRUDHandler.d.ts.map +1 -1
- package/dist/rest/EntityCRUDHandler.js +3 -18
- package/dist/rest/EntityCRUDHandler.js.map +1 -1
- package/dist/rest/RESTEndpointHandler.d.ts +2 -1
- package/dist/rest/RESTEndpointHandler.d.ts.map +1 -1
- package/dist/rest/RESTEndpointHandler.js +3 -16
- package/dist/rest/RESTEndpointHandler.js.map +1 -1
- package/dist/rest/RealtimeSdpBrokerHandler.d.ts +23 -0
- package/dist/rest/RealtimeSdpBrokerHandler.d.ts.map +1 -0
- package/dist/rest/RealtimeSdpBrokerHandler.js +78 -0
- package/dist/rest/RealtimeSdpBrokerHandler.js.map +1 -0
- package/dist/serverExtensionReservedRoots.d.ts.map +1 -1
- package/dist/serverExtensionReservedRoots.js +2 -3
- package/dist/serverExtensionReservedRoots.js.map +1 -1
- package/package.json +92 -91
- package/src/__tests__/EntityCRUDHandler.test.ts +18 -5
- package/src/__tests__/EntityRecordNameResolver.fieldSecurity.test.ts +118 -0
- package/src/__tests__/RealtimeClientSessionResolver.test.ts +20 -0
- package/src/__tests__/RealtimeSdpBrokerHandler.test.ts +191 -0
- package/src/__tests__/RemoteBrowserAudioStream.test.ts +81 -2
- package/src/__tests__/ResolverBase.filterEscaping.test.ts +190 -3
- package/src/__tests__/ResolverBase.readableFieldsTransport.test.ts +106 -0
- package/src/__tests__/UserViewResolver.updateWhereClause.test.ts +114 -0
- package/src/__tests__/WidgetSessionService.test.ts +4 -1
- package/src/__tests__/generatedGraphQLSchema.structural.test.ts +46 -0
- package/src/__tests__/newUserRolesDefault.test.ts +81 -0
- package/src/__tests__/newUsers.test.ts +36 -14
- package/src/__tests__/principals.callSites.test.ts +112 -0
- package/src/__tests__/principals.logging.test.ts +160 -0
- package/src/__tests__/principals.test.ts +305 -0
- package/src/__tests__/resolverBase.fls.test.ts +483 -0
- package/src/__tests__/resolverBase.recordChangesFls.test.ts +358 -0
- package/src/__tests__/resolverBase.refusalExtensions.test.ts +101 -0
- package/src/__tests__/resolverBase.refusalMessage.test.ts +88 -0
- package/src/__tests__/serverExtensionReservedRoots.test.ts +79 -11
- package/src/__tests__/visitorIdentity.resolve.test.ts +61 -0
- package/src/agentSessions/SessionJanitor.ts +2 -2
- package/src/auth/exampleNewUserSubClass.ts +9 -6
- package/src/auth/magicLink/MagicLinkService.ts +2 -8
- package/src/auth/newUsers.ts +7 -15
- package/src/auth/principals.ts +257 -0
- package/src/config.ts +44 -4
- package/src/entitySubclasses/MJEntityPermissionEntityServer.server.ts +65 -6
- package/src/generated/graphql-schemas/__mj.ts +18966 -16452
- package/src/generic/ResolverBase.ts +467 -9
- package/src/generic/RunViewResolver.ts +28 -2
- package/src/generic/refusalExtensions.ts +59 -0
- package/src/index.ts +154 -102
- package/src/realtimeWidget/WidgetSessionService.ts +2 -14
- package/src/realtimeWidget/visitorIdentity.ts +21 -6
- package/src/resolvers/EntityRecordNameResolver.ts +74 -8
- package/src/resolvers/FileCategoryResolver.ts +2 -3
- package/src/resolvers/IntegrationDiscoveryResolver.ts +2 -0
- package/src/resolvers/QuerySystemUserResolver.ts +1 -1
- package/src/resolvers/RealtimeClientSessionResolver.ts +128 -2
- package/src/resolvers/RemoteBrowserActionResolver.ts +47 -8
- package/src/resolvers/SyncRolesUsersResolver.ts +11 -2
- package/src/resolvers/UserViewResolver.ts +8 -4
- package/src/rest/EntityCRUDHandler.ts +3 -19
- package/src/rest/RESTEndpointHandler.ts +3 -17
- package/src/rest/RealtimeSdpBrokerHandler.ts +101 -0
- package/src/serverExtensionReservedRoots.ts +2 -3
- package/dist/resolvers/RingCentralTelephonyResolver.d.ts +0 -27
- package/dist/resolvers/RingCentralTelephonyResolver.d.ts.map +0 -1
- package/dist/resolvers/RingCentralTelephonyResolver.js +0 -87
- package/dist/resolvers/RingCentralTelephonyResolver.js.map +0 -1
- package/dist/resolvers/TeamsMeetingsResolver.d.ts +0 -28
- package/dist/resolvers/TeamsMeetingsResolver.d.ts.map +0 -1
- package/dist/resolvers/TeamsMeetingsResolver.js +0 -91
- package/dist/resolvers/TeamsMeetingsResolver.js.map +0 -1
- package/dist/resolvers/TelephonyResolver.d.ts +0 -26
- package/dist/resolvers/TelephonyResolver.d.ts.map +0 -1
- package/dist/resolvers/TelephonyResolver.js +0 -86
- package/dist/resolvers/TelephonyResolver.js.map +0 -1
- package/dist/resolvers/VonageTelephonyResolver.d.ts +0 -26
- package/dist/resolvers/VonageTelephonyResolver.d.ts.map +0 -1
- package/dist/resolvers/VonageTelephonyResolver.js +0 -86
- package/dist/resolvers/VonageTelephonyResolver.js.map +0 -1
- package/dist/telephony/RingCentralTelephonyService.d.ts +0 -115
- package/dist/telephony/RingCentralTelephonyService.d.ts.map +0 -1
- package/dist/telephony/RingCentralTelephonyService.js +0 -262
- package/dist/telephony/RingCentralTelephonyService.js.map +0 -1
- package/dist/telephony/TeamsMeetingsRouter.d.ts +0 -40
- package/dist/telephony/TeamsMeetingsRouter.d.ts.map +0 -1
- package/dist/telephony/TeamsMeetingsRouter.js +0 -96
- package/dist/telephony/TeamsMeetingsRouter.js.map +0 -1
- package/dist/telephony/TeamsMeetingsService.d.ts +0 -113
- package/dist/telephony/TeamsMeetingsService.d.ts.map +0 -1
- package/dist/telephony/TeamsMeetingsService.js +0 -196
- package/dist/telephony/TeamsMeetingsService.js.map +0 -1
- package/dist/telephony/TwilioTelephonyRouter.d.ts +0 -36
- package/dist/telephony/TwilioTelephonyRouter.d.ts.map +0 -1
- package/dist/telephony/TwilioTelephonyRouter.js +0 -143
- package/dist/telephony/TwilioTelephonyRouter.js.map +0 -1
- package/dist/telephony/TwilioTelephonyService.d.ts +0 -95
- package/dist/telephony/TwilioTelephonyService.d.ts.map +0 -1
- package/dist/telephony/TwilioTelephonyService.js +0 -193
- package/dist/telephony/TwilioTelephonyService.js.map +0 -1
- package/dist/telephony/VonageTelephonyRouter.d.ts +0 -41
- package/dist/telephony/VonageTelephonyRouter.d.ts.map +0 -1
- package/dist/telephony/VonageTelephonyRouter.js +0 -201
- package/dist/telephony/VonageTelephonyRouter.js.map +0 -1
- package/dist/telephony/VonageTelephonyService.d.ts +0 -90
- package/dist/telephony/VonageTelephonyService.d.ts.map +0 -1
- package/dist/telephony/VonageTelephonyService.js +0 -191
- package/dist/telephony/VonageTelephonyService.js.map +0 -1
- package/dist/telephony/calendar-scheduler.d.ts +0 -67
- package/dist/telephony/calendar-scheduler.d.ts.map +0 -1
- package/dist/telephony/calendar-scheduler.js +0 -133
- package/dist/telephony/calendar-scheduler.js.map +0 -1
- package/dist/telephony/index.d.ts +0 -29
- package/dist/telephony/index.d.ts.map +0 -1
- package/dist/telephony/index.js +0 -38
- package/dist/telephony/index.js.map +0 -1
- package/dist/telephony/media-upgrade-router.d.ts +0 -47
- package/dist/telephony/media-upgrade-router.d.ts.map +0 -1
- package/dist/telephony/media-upgrade-router.js +0 -72
- package/dist/telephony/media-upgrade-router.js.map +0 -1
- package/dist/telephony/ringcentral-runtime.d.ts +0 -14
- package/dist/telephony/ringcentral-runtime.d.ts.map +0 -1
- package/dist/telephony/ringcentral-runtime.js +0 -18
- package/dist/telephony/ringcentral-runtime.js.map +0 -1
- package/dist/telephony/teams-meetings-runtime.d.ts +0 -16
- package/dist/telephony/teams-meetings-runtime.d.ts.map +0 -1
- package/dist/telephony/teams-meetings-runtime.js +0 -20
- package/dist/telephony/teams-meetings-runtime.js.map +0 -1
- package/dist/telephony/teamsAcsMediaRegistry.d.ts +0 -69
- package/dist/telephony/teamsAcsMediaRegistry.d.ts.map +0 -1
- package/dist/telephony/teamsAcsMediaRegistry.js +0 -118
- package/dist/telephony/teamsAcsMediaRegistry.js.map +0 -1
- package/dist/telephony/telephony-runtime.d.ts +0 -14
- package/dist/telephony/telephony-runtime.d.ts.map +0 -1
- package/dist/telephony/telephony-runtime.js +0 -18
- package/dist/telephony/telephony-runtime.js.map +0 -1
- package/dist/telephony/twilioMediaRegistry.d.ts +0 -60
- package/dist/telephony/twilioMediaRegistry.d.ts.map +0 -1
- package/dist/telephony/twilioMediaRegistry.js +0 -106
- package/dist/telephony/twilioMediaRegistry.js.map +0 -1
- package/dist/telephony/vonage-runtime.d.ts +0 -14
- package/dist/telephony/vonage-runtime.d.ts.map +0 -1
- package/dist/telephony/vonage-runtime.js +0 -18
- package/dist/telephony/vonage-runtime.js.map +0 -1
- package/dist/telephony/vonageMediaRegistry.d.ts +0 -78
- package/dist/telephony/vonageMediaRegistry.d.ts.map +0 -1
- package/dist/telephony/vonageMediaRegistry.js +0 -158
- package/dist/telephony/vonageMediaRegistry.js.map +0 -1
- package/src/__tests__/media-upgrade-router.test.ts +0 -43
- package/src/__tests__/teams-meetings-service.test.ts +0 -65
- package/src/__tests__/teamsAcsMediaRegistry.test.ts +0 -82
- package/src/__tests__/twilio-telephony-service.test.ts +0 -23
- package/src/__tests__/twilioMediaRegistry.test.ts +0 -103
- package/src/__tests__/vonageMediaRegistry.test.ts +0 -180
- package/src/resolvers/RingCentralTelephonyResolver.ts +0 -64
- package/src/resolvers/TeamsMeetingsResolver.ts +0 -68
- package/src/resolvers/TelephonyResolver.ts +0 -63
- package/src/resolvers/VonageTelephonyResolver.ts +0 -63
- package/src/telephony/RingCentralTelephonyService.ts +0 -342
- package/src/telephony/TeamsMeetingsRouter.ts +0 -124
- package/src/telephony/TeamsMeetingsService.ts +0 -268
- package/src/telephony/TwilioTelephonyRouter.ts +0 -184
- package/src/telephony/TwilioTelephonyService.ts +0 -261
- package/src/telephony/VonageTelephonyRouter.ts +0 -239
- package/src/telephony/VonageTelephonyService.ts +0 -259
- package/src/telephony/calendar-scheduler.ts +0 -176
- package/src/telephony/index.ts +0 -43
- package/src/telephony/media-upgrade-router.ts +0 -79
- package/src/telephony/ringcentral-runtime.ts +0 -22
- package/src/telephony/teams-meetings-runtime.ts +0 -24
- package/src/telephony/teamsAcsMediaRegistry.ts +0 -152
- package/src/telephony/telephony-runtime.ts +0 -22
- package/src/telephony/twilioMediaRegistry.ts +0 -137
- package/src/telephony/vonage-runtime.ts +0 -22
- package/src/telephony/vonageMediaRegistry.ts +0 -200
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { BaseEntity, BaseEntityEvent, CompositeKey, EntityFieldTSType, LogDebug, LogError, LogStatus, Metadata, } from '@memberjunction/core';
|
|
1
|
+
import { BaseEntity, BaseEntityEvent, CompositeKey, EntityFieldTSType, LogDebug, LogError, LogStatus, Metadata, ReadableFieldsTransportKey, RecordChangeFieldSecurityProjector, RecordChangePayloadFields, } from '@memberjunction/core';
|
|
2
2
|
import { UserCache } from '@memberjunction/generic-database-provider';
|
|
3
3
|
import { AuthorizationError } from 'type-graphql';
|
|
4
4
|
import { GraphQLError } from 'graphql';
|
|
5
|
+
import { RefusalExtensions } from './refusalExtensions.js';
|
|
5
6
|
import { GetAPIKeyEngine } from '@memberjunction/api-keys';
|
|
6
7
|
import { httpTransport, CloudEvent, emitterFor } from 'cloudevents';
|
|
7
8
|
import { DeleteOptionsInput } from './DeleteOptionsInput.js';
|
|
8
9
|
import { MJEventType, MJGlobal, ENCRYPTED_SENTINEL, EscapeSQLString, IsValueEncrypted, IsOnlyTimezoneShift } from '@memberjunction/global';
|
|
10
|
+
import { SQLParser } from '@memberjunction/sql-parser';
|
|
11
|
+
import { PostgreSQLDialect, SQLServerDialect } from '@memberjunction/sql-dialect';
|
|
9
12
|
import { EncryptionEngine } from '@memberjunction/encryption';
|
|
10
13
|
import { publishStatusUpdate } from './PushStatusResolver.js';
|
|
11
14
|
import { CACHE_INVALIDATION_TOPIC } from './CacheInvalidationResolver.js';
|
|
@@ -48,7 +51,7 @@ export class ResolverBase {
|
|
|
48
51
|
* @param contextUser - Optional user context for decryption (required for encrypted fields)
|
|
49
52
|
* @returns A new object in transport shape, or null when there is nothing to map
|
|
50
53
|
*/
|
|
51
|
-
async MapFieldNamesToCodeNames(entityName, dataObject, contextUser, provider) {
|
|
54
|
+
async MapFieldNamesToCodeNames(entityName, dataObject, contextUser, provider, deniedReadFields, recordChangeProjector) {
|
|
52
55
|
// Return null for empty objects (e.g. when no rows found due to RLS filtering)
|
|
53
56
|
if (!dataObject || Object.keys(dataObject).length === 0) {
|
|
54
57
|
return null;
|
|
@@ -66,17 +69,63 @@ export class ResolverBase {
|
|
|
66
69
|
if (!entityInfo)
|
|
67
70
|
throw new Error(`Entity ${entityName} not found in metadata`);
|
|
68
71
|
// const fields = entityInfo.Fields.filter((f) => f.Name !== f.CodeName || f.Name.startsWith('__mj_'));
|
|
72
|
+
// FIELD-LEVEL SECURITY — this is the authoritative read boundary for every GraphQL
|
|
73
|
+
// return path (single-record resolvers, external-data-source loads, and anything else
|
|
74
|
+
// routed through here), sitting exactly where encryption masking already lives.
|
|
75
|
+
//
|
|
76
|
+
// The denied set is normally computed ONCE per (entity, user) by the caller and passed
|
|
77
|
+
// in: this method runs once per ROW, so resolving it here would cost fields x rows
|
|
78
|
+
// aggregations. We fall back to computing it when a caller doesn't supply it (the
|
|
79
|
+
// single-record resolvers, where "once per row" and "once per request" are the same
|
|
80
|
+
// thing) rather than failing open — a missing argument must never mean missing security.
|
|
81
|
+
const denied = deniedReadFields ?? (entityInfo.EnableFieldLevelSecurity && contextUser
|
|
82
|
+
? entityInfo.GetDeniedReadFields(contextUser)
|
|
83
|
+
: null);
|
|
69
84
|
const mapper = new FieldMapper();
|
|
70
85
|
entityInfo.Fields.forEach((f) => {
|
|
71
86
|
if (dataObject.hasOwnProperty(f.Name)) {
|
|
72
87
|
// GraphQL doesn't allow us to pass back fields with __ so we are mapping our special field cases that start with __mj_ to _mj__ for transport - they are converted back on the other side automatically
|
|
73
88
|
const mappedFieldName = mapper.MapFieldName(f.CodeName);
|
|
89
|
+
if (denied?.has(f.Name.trim().toLowerCase())) {
|
|
90
|
+
// Omit entirely rather than nulling — a null is indistinguishable from a real
|
|
91
|
+
// null value, and the client should see the field as absent, not as empty.
|
|
92
|
+
// Both key shapes are removed because callers reach this method with rows keyed
|
|
93
|
+
// either way depending on whether mapping has already run.
|
|
94
|
+
delete dataObject[f.Name];
|
|
95
|
+
delete dataObject[mappedFieldName];
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
74
98
|
if (mappedFieldName !== f.Name) {
|
|
75
99
|
dataObject[mappedFieldName] = dataObject[f.Name];
|
|
76
100
|
delete dataObject[f.Name];
|
|
77
101
|
}
|
|
78
102
|
}
|
|
79
103
|
});
|
|
104
|
+
// Field security, second half: say IN-BAND which fields this caller may read. Deleting the
|
|
105
|
+
// key above is not enough on its own — GraphQL emits every SELECTED field regardless, so a
|
|
106
|
+
// denied field the client asked for arrives as an explicit null it cannot tell apart from a
|
|
107
|
+
// genuine one. The client must not settle that from its own metadata: during the window
|
|
108
|
+
// after a permission change its copy disagrees with ours, and once metadata filtering lands
|
|
109
|
+
// (issue #3485) it may not hold the permission rows at all. Null for unrestricted callers,
|
|
110
|
+
// which is nearly every request.
|
|
111
|
+
const readableFields = this.BuildReadableFieldsTransportValue(entityInfo, denied);
|
|
112
|
+
if (readableFields) {
|
|
113
|
+
dataObject[ReadableFieldsTransportKey] = readableFields;
|
|
114
|
+
}
|
|
115
|
+
// Field security, third part — the audit trail. A 'MJ: Record Changes' row carries the old
|
|
116
|
+
// and new values of ANOTHER entity's fields, and its own EnableFieldLevelSecurity flag is
|
|
117
|
+
// off, so everything above is a no-op for it and the payload would flow out untouched. The
|
|
118
|
+
// projector recomputes the denied set against the entity each row is about; see
|
|
119
|
+
// RecordChangeFieldSecurityProjector for what each payload column gets.
|
|
120
|
+
//
|
|
121
|
+
// Same "a missing argument must never mean missing security" rule as the denied set above:
|
|
122
|
+
// the projector is normally built ONCE per request by the array caller and passed in, and
|
|
123
|
+
// we build one here when it wasn't — the single-record resolvers, where once-per-row and
|
|
124
|
+
// once-per-request are the same thing.
|
|
125
|
+
if (contextUser && RecordChangeFieldSecurityProjector.IsRecordChangesEntity(entityInfo)) {
|
|
126
|
+
const projector = recordChangeProjector ?? new RecordChangeFieldSecurityProjector(md, contextUser);
|
|
127
|
+
dataObject = projector.ProjectRow(dataObject);
|
|
128
|
+
}
|
|
80
129
|
// Handle encrypted fields - data from raw SQL queries is still encrypted
|
|
81
130
|
const encryptedFields = entityInfo.EncryptedFields;
|
|
82
131
|
if (encryptedFields.length > 0) {
|
|
@@ -175,12 +224,47 @@ export class ResolverBase {
|
|
|
175
224
|
if (!dataObjectArray || dataObjectArray.length === 0) {
|
|
176
225
|
return dataObjectArray;
|
|
177
226
|
}
|
|
227
|
+
// Resolve the field-security denied set ONCE for the whole array and pass it into the
|
|
228
|
+
// per-row mapper. MapFieldNamesToCodeNames runs once per row, so computing this inside
|
|
229
|
+
// the loop would be fields x rows aggregations — 40,000 for a 1,000-row x 40-column
|
|
230
|
+
// result, each re-scanning the user's roles and allocating. Gated on the entity-level
|
|
231
|
+
// flag so non-FLS entities (nearly all of them) don't even resolve the entity twice.
|
|
232
|
+
const md = provider ?? new Metadata();
|
|
233
|
+
const entityInfo = md.EntityByName(entityName);
|
|
234
|
+
const deniedReadFields = entityInfo?.EnableFieldLevelSecurity && contextUser
|
|
235
|
+
? entityInfo.GetDeniedReadFields(contextUser)
|
|
236
|
+
: undefined;
|
|
237
|
+
// Record Changes payload security is resolved per DISTINCT target entity, and one array can
|
|
238
|
+
// span many — so the projector, which owns that memo, must outlive the row loop. Built once
|
|
239
|
+
// here for the same reason the denied set above is: GetDeniedReadFields walks every field on
|
|
240
|
+
// an entity and must never be called per row.
|
|
241
|
+
const recordChangeProjector = contextUser && RecordChangeFieldSecurityProjector.IsRecordChangesEntity(entityInfo)
|
|
242
|
+
? new RecordChangeFieldSecurityProjector(md, contextUser)
|
|
243
|
+
: undefined;
|
|
178
244
|
const mapped = [];
|
|
179
245
|
for (const element of dataObjectArray) {
|
|
180
|
-
mapped.push(await this.MapFieldNamesToCodeNames(entityName, element, contextUser, provider));
|
|
246
|
+
mapped.push(await this.MapFieldNamesToCodeNames(entityName, element, contextUser, provider, deniedReadFields, recordChangeProjector));
|
|
181
247
|
}
|
|
182
248
|
return mapped;
|
|
183
249
|
}
|
|
250
|
+
/**
|
|
251
|
+
* The CodeNames this user may read on this entity, for the field-security transport key — or
|
|
252
|
+
* null when there is nothing to state (no denials, so every field is readable and the client
|
|
253
|
+
* needs no help distinguishing a withheld null from a genuine one).
|
|
254
|
+
*
|
|
255
|
+
* Carries entity field NAMES, not CodeNames and not the `_mj__` transport shape. The client
|
|
256
|
+
* consumes this after it has already reversed the transport mapping, and it matches names
|
|
257
|
+
* against `EntityFieldInfo.Name` — the same key the denied set itself is built from. Sending
|
|
258
|
+
* the one shape both sides already agree on avoids a second mapping that could drift.
|
|
259
|
+
*/
|
|
260
|
+
BuildReadableFieldsTransportValue(entityInfo, deniedReadFields) {
|
|
261
|
+
if (!deniedReadFields || deniedReadFields.size === 0) {
|
|
262
|
+
return null;
|
|
263
|
+
}
|
|
264
|
+
return entityInfo.Fields
|
|
265
|
+
.filter((f) => !deniedReadFields.has(f.Name.trim().toLowerCase()))
|
|
266
|
+
.map((f) => f.Name);
|
|
267
|
+
}
|
|
184
268
|
/**
|
|
185
269
|
* Loads a single external-data-source-backed entity record by primary key and returns it in
|
|
186
270
|
* GraphQL field-name (CodeName) shape, or null if not found.
|
|
@@ -628,6 +712,124 @@ export class ResolverBase {
|
|
|
628
712
|
`Denial reason: ${result.Reason}`);
|
|
629
713
|
}
|
|
630
714
|
}
|
|
715
|
+
/**
|
|
716
|
+
* SECURITY — GraphQL-boundary screen for one client-supplied SQL clause fragment.
|
|
717
|
+
*
|
|
718
|
+
* `ValidateUserProvidedSQLClause` still blocks stacked statements, DML, comments, UNION
|
|
719
|
+
* and WAITFOR, and still permits SELECT (server-internal engines pass richer filters).
|
|
720
|
+
* A keyword ban on SELECT/EXISTS at this boundary (#4253) broke first-party clients that
|
|
721
|
+
* use `IN (SELECT … FROM <entity base view>)` — that is a legitimate ExtraFilter.
|
|
722
|
+
*
|
|
723
|
+
* This screen uses `@memberjunction/sql-parser` (same wrap as EDS `assertReadOnlyClause`):
|
|
724
|
+
* wrap the fragment as a single SELECT, fail closed if it does not parse as a read, then
|
|
725
|
+
* allow a FROM only when it is an entity **BaseView**. Base tables (`Meeting`, `__mj.User`)
|
|
726
|
+
* and catalogs are rejected. Server-internal RunView callers never hit this.
|
|
727
|
+
*
|
|
728
|
+
* RLS is applied by RunView as an outer WHERE around the entity being queried, not compiled
|
|
729
|
+
* into the view. Subqueries against another entity's BaseView therefore do not inherit that
|
|
730
|
+
* entity's RLS; they are still restricted to the view (not the table).
|
|
731
|
+
*/
|
|
732
|
+
assertClientClauseUsesEntityBaseViews(clause, label, provider) {
|
|
733
|
+
if (!clause?.trim())
|
|
734
|
+
return;
|
|
735
|
+
const dialect = this.dialectForProvider(provider);
|
|
736
|
+
if (SQLParser.HasStackedStatements(clause, dialect)) {
|
|
737
|
+
throw new Error(`Invalid ${label}: multiple statements are not permitted in client-supplied filters`);
|
|
738
|
+
}
|
|
739
|
+
const wrapped = label === 'OrderBy'
|
|
740
|
+
? `SELECT 1 FROM __mj_clause_screen ORDER BY ${clause}`
|
|
741
|
+
: `SELECT 1 FROM __mj_clause_screen WHERE (${clause})`;
|
|
742
|
+
const parser = new SQLParser(wrapped, dialect);
|
|
743
|
+
if (!parser.IsValid || parser.HasWriteStatement || parser.StatementKind !== 'select') {
|
|
744
|
+
throw new Error(`Invalid ${label}: not a safe read-only filter fragment — refusing under uncertainty`);
|
|
745
|
+
}
|
|
746
|
+
if (this.astContainsWriteNode(parser.AST)) {
|
|
747
|
+
throw new Error(`Invalid ${label}: write/DDL nested in a subquery is not permitted`);
|
|
748
|
+
}
|
|
749
|
+
const allowed = this.entityBaseViewAllowList(provider);
|
|
750
|
+
const tables = SQLParser.ExtractTableRefs(wrapped, dialect);
|
|
751
|
+
for (const t of tables) {
|
|
752
|
+
const table = this.stripSqlIdent(t.TableName);
|
|
753
|
+
const schema = this.stripSqlIdent(t.SchemaName);
|
|
754
|
+
if (table.toLowerCase() === '__mj_clause_screen')
|
|
755
|
+
continue;
|
|
756
|
+
const qualified = `${schema}.${table}`.toLowerCase();
|
|
757
|
+
const bare = table.toLowerCase();
|
|
758
|
+
if (allowed.qualified.has(qualified) || allowed.bare.has(bare))
|
|
759
|
+
continue;
|
|
760
|
+
throw new Error(`Invalid ${label}: subquery must use an entity base view, not '${schema}.${table}'`);
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
/**
|
|
764
|
+
* Applies {@link assertClientClauseUsesEntityBaseViews} to every client-supplied clause
|
|
765
|
+
* a view request can carry that is actually a SQL fragment. GraphQL entry points
|
|
766
|
+
* (RunViewByName, RunViewByID, RunDynamicView, RunViews) funnel through
|
|
767
|
+
* RunViewGenericInternal / RunViewsGenericInternal.
|
|
768
|
+
*
|
|
769
|
+
* 🚨 `UserSearchString` is deliberately NOT screened here (#4392). It is not a clause — it is
|
|
770
|
+
* the free text a person typed into a search box, and it never reaches SQL as a fragment.
|
|
771
|
+
* `GenericDatabaseProvider.createViewUserSearchSQL` builds the predicate itself from
|
|
772
|
+
* `IncludeInUserSearchAPI` metadata and lands the text only as a literal, doubling single
|
|
773
|
+
* quotes and escaping LIKE metacharacters with an explicit `ESCAPE`. Running it through a
|
|
774
|
+
* screen that parses its argument as SQL and fails closed rejected every term that is not
|
|
775
|
+
* coincidentally valid SQL: `Marcus Chen` parses as nothing, `O'Leary` as an unterminated
|
|
776
|
+
* literal — so essentially every real name search returned 0 rows.
|
|
777
|
+
*
|
|
778
|
+
* The provider-level denylist does NOT back this up — it was removed from `UserSearchString`
|
|
779
|
+
* in the same change, for the same reason (it refused `Union Pacific`). What protects the value
|
|
780
|
+
* is that it is never SQL: it reaches the database only as a quoted, quote-doubled literal.
|
|
781
|
+
* The single place that is not true is a field carrying `UserSearchParamFormatAPI`, whose
|
|
782
|
+
* admin-authored format may splice the term in unquoted; `createViewUserSearchSQL` re-applies
|
|
783
|
+
* `ValidateUserProvidedSQLClause` for exactly those entities.
|
|
784
|
+
*/
|
|
785
|
+
screenClientViewClauses(clauses, provider) {
|
|
786
|
+
this.assertClientClauseUsesEntityBaseViews(clauses.extraFilter, 'ExtraFilter', provider);
|
|
787
|
+
this.assertClientClauseUsesEntityBaseViews(clauses.orderBy, 'OrderBy', provider);
|
|
788
|
+
this.assertClientClauseUsesEntityBaseViews(clauses.overrideExcludeFilter, 'OverrideExcludeFilter', provider);
|
|
789
|
+
}
|
|
790
|
+
/** Same write-node walk as EDS `sqlReadOnlyScreen.astContainsWriteNode`. */
|
|
791
|
+
astContainsWriteNode(node) {
|
|
792
|
+
if (!node || typeof node !== 'object')
|
|
793
|
+
return false;
|
|
794
|
+
if (Array.isArray(node))
|
|
795
|
+
return node.some((n) => this.astContainsWriteNode(n));
|
|
796
|
+
const obj = node;
|
|
797
|
+
const type = obj.type;
|
|
798
|
+
if (typeof type === 'string' && ResolverBase.WRITE_NODE_TYPES.has(type.toLowerCase())) {
|
|
799
|
+
return true;
|
|
800
|
+
}
|
|
801
|
+
return Object.values(obj).some((v) => this.astContainsWriteNode(v));
|
|
802
|
+
}
|
|
803
|
+
static { this.WRITE_NODE_TYPES = new Set([
|
|
804
|
+
'insert', 'update', 'delete', 'merge', 'replace', 'drop', 'create', 'alter', 'truncate',
|
|
805
|
+
'rename', 'call', 'exec', 'execute', 'grant', 'revoke', 'use', 'load', 'copy', 'do',
|
|
806
|
+
]); }
|
|
807
|
+
dialectForProvider(provider) {
|
|
808
|
+
const name = provider?.constructor?.name ?? '';
|
|
809
|
+
if (/postgres/i.test(name))
|
|
810
|
+
return new PostgreSQLDialect();
|
|
811
|
+
return new SQLServerDialect();
|
|
812
|
+
}
|
|
813
|
+
stripSqlIdent(name) {
|
|
814
|
+
if (!name)
|
|
815
|
+
return '';
|
|
816
|
+
return name.replace(/^\[|\]$/g, '').replace(/^"|"$/g, '').replace(/^`|`$/g, '');
|
|
817
|
+
}
|
|
818
|
+
entityBaseViewAllowList(provider) {
|
|
819
|
+
const qualified = new Set();
|
|
820
|
+
const bare = new Set();
|
|
821
|
+
const entities = provider?.Entities ?? [];
|
|
822
|
+
for (const e of entities) {
|
|
823
|
+
const view = this.stripSqlIdent(e.BaseView);
|
|
824
|
+
if (!view)
|
|
825
|
+
continue;
|
|
826
|
+
const schema = this.stripSqlIdent(e.SchemaName);
|
|
827
|
+
bare.add(view.toLowerCase());
|
|
828
|
+
if (schema)
|
|
829
|
+
qualified.add(`${schema}.${view}`.toLowerCase());
|
|
830
|
+
}
|
|
831
|
+
return { qualified, bare };
|
|
832
|
+
}
|
|
631
833
|
/**
|
|
632
834
|
* Optimized RunViewGenericInternal implementation with:
|
|
633
835
|
* - Field filtering at source (Fix #7)
|
|
@@ -637,6 +839,9 @@ export class ResolverBase {
|
|
|
637
839
|
try {
|
|
638
840
|
if (!viewInfo || !userPayload)
|
|
639
841
|
return null;
|
|
842
|
+
// SECURITY: GraphQL ExtraFilter may contain IN (SELECT … FROM <base view>).
|
|
843
|
+
// Screen at this boundary: parse, reject writes, allow only entity BaseViews.
|
|
844
|
+
this.screenClientViewClauses({ extraFilter, orderBy, userSearchString, overrideExcludeFilter }, provider);
|
|
640
845
|
// Check API key scope authorization for view operations
|
|
641
846
|
await this.CheckAPIKeyScopeAuthorization('view:run', viewInfo.Entity, userPayload);
|
|
642
847
|
const md = provider;
|
|
@@ -777,6 +982,13 @@ export class ResolverBase {
|
|
|
777
982
|
md = params[0].provider;
|
|
778
983
|
// Transform parameters
|
|
779
984
|
for (const param of params) {
|
|
985
|
+
// SECURITY: same GraphQL-boundary BaseView screen as RunViewGenericInternal.
|
|
986
|
+
this.screenClientViewClauses({
|
|
987
|
+
extraFilter: param.extraFilter,
|
|
988
|
+
orderBy: param.orderBy,
|
|
989
|
+
userSearchString: param.userSearchString,
|
|
990
|
+
overrideExcludeFilter: param.overrideExcludeFilter,
|
|
991
|
+
}, md);
|
|
780
992
|
if (param.viewInfo) {
|
|
781
993
|
// Validate entity only once per entity type
|
|
782
994
|
const entityName = param.viewInfo.Entity;
|
|
@@ -1046,8 +1258,10 @@ export class ResolverBase {
|
|
|
1046
1258
|
}
|
|
1047
1259
|
// save failed, throw error with message
|
|
1048
1260
|
else {
|
|
1261
|
+
// The message is the prose a toast shows; `validationErrors` is the same refusal with its
|
|
1262
|
+
// field names intact, so the client can paint the fields a server-side ValidateAsync named.
|
|
1049
1263
|
throw new GraphQLError(entityObject.LatestResult?.CompleteMessage ?? 'Unknown error creating record', {
|
|
1050
|
-
extensions:
|
|
1264
|
+
extensions: RefusalExtensions('CREATE_ENTITY_ERROR', entityName, entityObject.LatestResult),
|
|
1051
1265
|
});
|
|
1052
1266
|
}
|
|
1053
1267
|
}
|
|
@@ -1076,8 +1290,20 @@ export class ResolverBase {
|
|
|
1076
1290
|
clientNewValues[key] = input[key];
|
|
1077
1291
|
}
|
|
1078
1292
|
});
|
|
1079
|
-
|
|
1080
|
-
|
|
1293
|
+
// Field-level security: any value the client sends for a field it cannot READ is
|
|
1294
|
+
// fabricated by construction (the field was stripped from every payload the client ever
|
|
1295
|
+
// received), so strip such values before anything applies them. When any field is
|
|
1296
|
+
// denied we also force the truth-load branch below — client OldValues for denied fields
|
|
1297
|
+
// are equally fabricated, so hydrating from them (the no-DB-load path) would write
|
|
1298
|
+
// fabricated state into the denied columns on save.
|
|
1299
|
+
const hasDeniedReadFields = this.StripDeniedReadFieldsFromClientInput(entityInfo, userInfo, input, clientNewValues);
|
|
1300
|
+
// The audit-trail equivalent. Its `true` matters most on THIS entity: 'MJ: Record Changes'
|
|
1301
|
+
// has TrackRecordChanges off, so without it a client sending OldValues takes the branch below
|
|
1302
|
+
// that hydrates from those values — never loading what the database actually holds.
|
|
1303
|
+
const hasNarrowedAuditPayload = this.StripRecordChangePayloadFromClientInput(entityInfo, userInfo, input, clientNewValues);
|
|
1304
|
+
if (this.MustLoadTruthFromDatabase(entityInfo, input, hasDeniedReadFields, hasNarrowedAuditPayload)) {
|
|
1305
|
+
// We get here because the entity tracks record changes, OR the client did not provide OldValues,
|
|
1306
|
+
// OR field-level security is in play — in every case we need the true old values from the DB
|
|
1081
1307
|
const cKey = new CompositeKey(entityInfo.PrimaryKeys.map((pk) => {
|
|
1082
1308
|
return {
|
|
1083
1309
|
FieldName: pk.Name,
|
|
@@ -1125,8 +1351,16 @@ export class ResolverBase {
|
|
|
1125
1351
|
return await this.MapFieldNamesToCodeNames(entityName, entityObject.GetAll(), userInfo);
|
|
1126
1352
|
}
|
|
1127
1353
|
else {
|
|
1128
|
-
|
|
1129
|
-
|
|
1354
|
+
// CompleteMessage, not Message. A validation refusal puts its reasons in `Errors` and leaves
|
|
1355
|
+
// `Message` unset, so reading `Message` here fell through to 'Unknown error' and discarded
|
|
1356
|
+
// every field-named explanation the entity had just produced. CreateRecord already read
|
|
1357
|
+
// CompleteMessage; this path did not, which is why the SAME rule on the SAME entity explained
|
|
1358
|
+
// itself on a create and said nothing on an update. CompleteMessage is a strict superset — it
|
|
1359
|
+
// starts from `Message`, then appends `Error` and `Errors` — so nothing previously reported is
|
|
1360
|
+
// lost, and it still yields undefined when there is genuinely nothing to say, leaving the
|
|
1361
|
+
// fallback below to fire rather than showing the user a blank error.
|
|
1362
|
+
throw new GraphQLError(entityObject.LatestResult?.CompleteMessage ?? 'Unknown error', {
|
|
1363
|
+
extensions: RefusalExtensions('SAVE_ENTITY_ERROR', entityName, entityObject.LatestResult),
|
|
1130
1364
|
});
|
|
1131
1365
|
}
|
|
1132
1366
|
}
|
|
@@ -1135,6 +1369,147 @@ export class ResolverBase {
|
|
|
1135
1369
|
extensions: { code: 'SAVE_ENTITY_ERROR', entityName },
|
|
1136
1370
|
});
|
|
1137
1371
|
}
|
|
1372
|
+
/**
|
|
1373
|
+
* Whether `UpdateRecord` must hydrate the entity from the DATABASE rather than from the
|
|
1374
|
+
* client's `OldValues___`.
|
|
1375
|
+
*
|
|
1376
|
+
* The `OldValues___` path exists as an optimization: when nothing needs the true prior state,
|
|
1377
|
+
* the client already holds it and a round trip is wasted. Each condition below is a reason
|
|
1378
|
+
* that assumption fails.
|
|
1379
|
+
*
|
|
1380
|
+
* `EnableFieldLevelSecurity` is the security-critical one, and it is NOT redundant with
|
|
1381
|
+
* `hasDeniedReadFields`. That flag reports READ denials, and the canonical FLS configuration is
|
|
1382
|
+
* Read Allow + Update Deny — which leaves it false. Such a caller would be hydrated from its own
|
|
1383
|
+
* `OldValues___`, and a value it supplies there for an update-denied field arrives through
|
|
1384
|
+
* `LoadFromData`, which the `EntityField` setter records as that field's INITIAL value. The
|
|
1385
|
+
* field is therefore not dirty, `BaseEntity.CheckFieldLevelUpdatePermissions` only rejects
|
|
1386
|
+
* `field.Dirty && denied`, and `GenerateSaveSQL` sends every `IsSPParameter` field regardless of
|
|
1387
|
+
* dirtiness (it skips only `NotLoaded`). The fabricated value reached `spUpdate` having passed
|
|
1388
|
+
* every check: pinning a value in `OldValues___` was a write to a field the caller may not write.
|
|
1389
|
+
*
|
|
1390
|
+
* Forcing the truth-load closes that rather than relocating it. The entity is hydrated by
|
|
1391
|
+
* `InnerLoad` from the real row, and `TestAndSetClientOldValuesToDBValues` reads the client's
|
|
1392
|
+
* OldValues only to detect concurrent-edit overlap before ending in `SetMany(clientNewValues)` —
|
|
1393
|
+
* it never applies them to the entity. An update-denied field can then only become dirty by being
|
|
1394
|
+
* named in the mutation input itself, which is precisely the case that check does catch.
|
|
1395
|
+
*
|
|
1396
|
+
* Ordered so the boolean flag is evaluated last: the extra load lands only on entities that have
|
|
1397
|
+
* the feature switched on, which is almost none of them.
|
|
1398
|
+
*/
|
|
1399
|
+
MustLoadTruthFromDatabase(entityInfo, input, hasDeniedReadFields, hasNarrowedAuditPayload) {
|
|
1400
|
+
return (entityInfo.TrackRecordChanges ||
|
|
1401
|
+
!input.OldValues___ ||
|
|
1402
|
+
hasDeniedReadFields ||
|
|
1403
|
+
hasNarrowedAuditPayload ||
|
|
1404
|
+
entityInfo.EnableFieldLevelSecurity);
|
|
1405
|
+
}
|
|
1406
|
+
/**
|
|
1407
|
+
* Field-level security guard for the update path.
|
|
1408
|
+
*
|
|
1409
|
+
* Every denied-read field is stripped — new values AND OldValues. A field the user cannot
|
|
1410
|
+
* read was absent from every payload that client ever received, so any value coming back for
|
|
1411
|
+
* it is the transport's invention rather than user intent, and applying it would silently
|
|
1412
|
+
* overwrite the real column. Stripping is what makes "load a record, edit an unrelated field,
|
|
1413
|
+
* save" safe for a restricted user.
|
|
1414
|
+
*
|
|
1415
|
+
* There is no split by update permission: Read is required for Update, so a user denied read
|
|
1416
|
+
* is denied update too and denied-read ∩ denied-update is just denied-read.
|
|
1417
|
+
*
|
|
1418
|
+
* Silent narrowing, not rejection — consistent with the output projection the client already
|
|
1419
|
+
* experiences, and with the ambiguous-error rule (naming the field would confirm it exists
|
|
1420
|
+
* and is restricted).
|
|
1421
|
+
*
|
|
1422
|
+
* Returns true when the user has a non-empty denied-read set on this entity. The caller
|
|
1423
|
+
* must then hydrate the entity from the DATABASE (never from client OldValues), so denied
|
|
1424
|
+
* fields hold true values that an omitted key leaves untouched.
|
|
1425
|
+
*/
|
|
1426
|
+
StripDeniedReadFieldsFromClientInput(entityInfo, userInfo, input, clientNewValues) {
|
|
1427
|
+
if (!entityInfo.EnableFieldLevelSecurity || !userInfo) {
|
|
1428
|
+
return false;
|
|
1429
|
+
}
|
|
1430
|
+
const deniedReadNames = entityInfo.GetDeniedReadFields(userInfo);
|
|
1431
|
+
if (deniedReadNames.size === 0) {
|
|
1432
|
+
return false;
|
|
1433
|
+
}
|
|
1434
|
+
// Input keys are entity CodeNames (post ReverseMapInputFieldNames); the denied set holds
|
|
1435
|
+
// lowercased field Names — bridge via the field metadata once.
|
|
1436
|
+
const deniedReadCodeNames = new Set();
|
|
1437
|
+
for (const field of entityInfo.Fields) {
|
|
1438
|
+
if (deniedReadNames.has(field.Name.trim().toLowerCase())) {
|
|
1439
|
+
deniedReadCodeNames.add(field.CodeName.trim().toLowerCase());
|
|
1440
|
+
}
|
|
1441
|
+
}
|
|
1442
|
+
const stripped = [];
|
|
1443
|
+
for (const key of Object.keys(clientNewValues)) {
|
|
1444
|
+
if (deniedReadCodeNames.has(key.trim().toLowerCase())) {
|
|
1445
|
+
delete clientNewValues[key];
|
|
1446
|
+
delete input[key];
|
|
1447
|
+
stripped.push(key);
|
|
1448
|
+
}
|
|
1449
|
+
}
|
|
1450
|
+
if (Array.isArray(input.OldValues___)) {
|
|
1451
|
+
input.OldValues___ = input.OldValues___.filter((item) => !deniedReadCodeNames.has(String(item.Key).trim().toLowerCase()));
|
|
1452
|
+
}
|
|
1453
|
+
if (stripped.length > 0) {
|
|
1454
|
+
LogDebug(`[FieldSecurity] UpdateRecord on '${entityInfo.Name}' for user ${userInfo.Email}: ` +
|
|
1455
|
+
`stripped client-sent value(s) for denied-read field(s) ${stripped.join(', ')}`);
|
|
1456
|
+
}
|
|
1457
|
+
return true;
|
|
1458
|
+
}
|
|
1459
|
+
/**
|
|
1460
|
+
* Refuses a client-sent `MJ: Record Changes` payload column from a caller who carries field
|
|
1461
|
+
* denials, and forces the update onto the load-truth-from-DB branch.
|
|
1462
|
+
*
|
|
1463
|
+
* This is the write half of the audit-trail projection, and without it that projection would
|
|
1464
|
+
* itself destroy audit history. A restricted caller is served a NARROWED `ChangesJSON` /
|
|
1465
|
+
* `FullRecordJSON` and no `ChangesDescription`. Those values hydrate a client-side entity as
|
|
1466
|
+
* ordinary loaded values, and `GenerateSaveSQL` writes EVERY `IsSPParameter` field rather than
|
|
1467
|
+
* only dirty ones — so a user who edits `Comments` on that record and saves would silently
|
|
1468
|
+
* overwrite the stored payload with the narrowed one they were shown. The row would keep looking
|
|
1469
|
+
* like a complete audit entry while the pruned fields were gone for everyone, permanently.
|
|
1470
|
+
*
|
|
1471
|
+
* The rule is the one field security already applies elsewhere: **a value a client could not
|
|
1472
|
+
* have seen in full is not user intent, it is a transport artifact, and it is ignored.** Here
|
|
1473
|
+
* that is widened from "fields the caller cannot read" to "the audit payload of a caller who
|
|
1474
|
+
* carries any denial", because the column is readable — it is its CONTENTS that were narrowed,
|
|
1475
|
+
* and which row's target entity did the narrowing is not knowable from the input alone.
|
|
1476
|
+
*
|
|
1477
|
+
* Returning true routes the caller through `InnerLoad`, so the stored values are restored from
|
|
1478
|
+
* the database before the save. Legitimate payload writes are unaffected: they happen
|
|
1479
|
+
* server-side (`SnapshotBuilder`, replay) and never through this resolver.
|
|
1480
|
+
*/
|
|
1481
|
+
StripRecordChangePayloadFromClientInput(entityInfo, userInfo, input, clientNewValues, provider) {
|
|
1482
|
+
if (!userInfo || !RecordChangeFieldSecurityProjector.IsRecordChangesEntity(entityInfo)) {
|
|
1483
|
+
return false;
|
|
1484
|
+
}
|
|
1485
|
+
const md = provider ?? new Metadata();
|
|
1486
|
+
if (!new RecordChangeFieldSecurityProjector(md, userInfo).CallerCarriesAnyDenial()) {
|
|
1487
|
+
return false; // this caller was served the payload whole, so what they send back is theirs
|
|
1488
|
+
}
|
|
1489
|
+
const payloadKeys = new Set(RecordChangePayloadFields.map((f) => f.toLowerCase()));
|
|
1490
|
+
const stripped = [];
|
|
1491
|
+
for (const key of Object.keys(clientNewValues)) {
|
|
1492
|
+
if (payloadKeys.has(key.trim().toLowerCase())) {
|
|
1493
|
+
delete clientNewValues[key];
|
|
1494
|
+
delete input[key];
|
|
1495
|
+
stripped.push(key);
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1498
|
+
// OldValues too: a narrowed payload in the client's old values is not what the database holds,
|
|
1499
|
+
// so leaving it would read as a concurrent-edit conflict on a field nobody edited.
|
|
1500
|
+
if (Array.isArray(input.OldValues___)) {
|
|
1501
|
+
input.OldValues___ = input.OldValues___.filter((item) => !payloadKeys.has(String(item.Key).trim().toLowerCase()));
|
|
1502
|
+
}
|
|
1503
|
+
if (stripped.length > 0) {
|
|
1504
|
+
LogDebug(`[FieldSecurity] UpdateRecord on '${entityInfo.Name}' for user ${userInfo.Email}: ` +
|
|
1505
|
+
`ignored client-sent audit payload column(s) ${stripped.join(', ')} — the caller carries field ` +
|
|
1506
|
+
`denials, so the value they hold may be a narrowed projection rather than the stored one`);
|
|
1507
|
+
}
|
|
1508
|
+
// True even when nothing was stripped: the DB truth-load is what guarantees the payload the
|
|
1509
|
+
// save writes is the stored one, and a client that sent no payload key at all would otherwise
|
|
1510
|
+
// fall through to the OldValues branch and write whatever it did send.
|
|
1511
|
+
return true;
|
|
1512
|
+
}
|
|
1138
1513
|
/**
|
|
1139
1514
|
* This routine compares the OldValues property in the input object to the values in the DB that we just loaded. If there are differences, we need to check to see if the client
|
|
1140
1515
|
* is trying to update any of those fields (e.g. overlap). If there is overlap, we throw an error. If there is no overlap, we can proceed with the update even if the DB Values
|
|
@@ -1335,8 +1710,12 @@ export class ResolverBase {
|
|
|
1335
1710
|
return returnValue;
|
|
1336
1711
|
}
|
|
1337
1712
|
else {
|
|
1338
|
-
|
|
1339
|
-
|
|
1713
|
+
// CompleteMessage, for the same reason as the update path above. It matters more going
|
|
1714
|
+
// forward: apps already refuse deletes by overriding Delete() and returning false with the
|
|
1715
|
+
// reason on LatestResult, and #3971 proposes a first-class delete-validation seam. Every one
|
|
1716
|
+
// of those reasons was being replaced by 'Unknown error' at the API boundary.
|
|
1717
|
+
throw new GraphQLError(entityObject.LatestResult?.CompleteMessage ?? 'Unknown error', {
|
|
1718
|
+
extensions: RefusalExtensions('DELETE_ENTITY_ERROR', entityName, entityObject.LatestResult),
|
|
1340
1719
|
});
|
|
1341
1720
|
}
|
|
1342
1721
|
}
|