@sasjs/api 0.43.0 → 0.44.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.
- package/build/browser.js +545 -193
- package/build/cjs/corpus/drive.js +305 -26
- package/build/cjs/host/dispatch.js +44 -18
- package/build/cjs/identity/records.js +10 -0
- package/build/cjs/routes/generated.js +48 -0
- package/build/esm/corpus/drive.d.ts +1 -1
- package/build/esm/corpus/drive.d.ts.map +1 -1
- package/build/esm/corpus/drive.js +305 -26
- package/build/esm/host/dispatch.d.ts +5 -1
- package/build/esm/host/dispatch.d.ts.map +1 -1
- package/build/esm/host/dispatch.js +44 -18
- package/build/esm/identity/records.d.ts +3 -2
- package/build/esm/identity/records.d.ts.map +1 -1
- package/build/esm/identity/records.js +10 -0
- package/build/esm/routes/generated.d.ts.map +1 -1
- package/build/esm/routes/generated.js +48 -0
- package/package.json +1 -1
|
@@ -6,6 +6,7 @@ const deploymentFile_js_1 = require("../drive/deploymentFile.js");
|
|
|
6
6
|
const service_js_1 = require("../appstream/service.js");
|
|
7
7
|
const web_js_1 = require("../appstream/web.js");
|
|
8
8
|
const bundle_js_1 = require("../appstream/bundle.js");
|
|
9
|
+
const routeAccess_js_1 = require("../identity/routeAccess.js");
|
|
9
10
|
const types_js_1 = require("../types.js");
|
|
10
11
|
const deploy_js_1 = require("../drive/deploy.js");
|
|
11
12
|
/** The defaults sasjs/server's Client schema applies to an omitted lifetime. */
|
|
@@ -27,16 +28,22 @@ const RUN_ROUTES = [
|
|
|
27
28
|
'POST /SASjsApi/code/trigger'
|
|
28
29
|
];
|
|
29
30
|
/**
|
|
30
|
-
* The
|
|
31
|
+
* The operations a permission rule addresses.
|
|
31
32
|
*
|
|
32
|
-
* The
|
|
33
|
-
*
|
|
33
|
+
* The inventory less the two entries that name a whole surface rather than an
|
|
34
|
+
* operation: `/SASjsApi` and `/AppStream` are prefixes a rule can cover
|
|
35
|
+
* everything beneath with, not routes a request is dispatched to. This is the
|
|
36
|
+
* server's `isAuthorizingRoute` - the same inventory, minus the routes every
|
|
37
|
+
* caller sees - so a request meets a rule check on exactly the calls it does
|
|
38
|
+
* there: the run routes, the drive routes, and the app stream's own paths.
|
|
39
|
+
*
|
|
40
|
+
* The triggers are absent because the rules do not reach them, and the record,
|
|
41
|
+
* identity, info and admin routes are gated separately.
|
|
34
42
|
*/
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
];
|
|
43
|
+
const GRANTED_ROUTES = routeAccess_js_1.DEFAULT_GRANTABLE_ROUTES.filter((path) => !routeAccess_js_1.TOP_LEVEL_ROUTES.includes(path));
|
|
44
|
+
// The OpenAPI route table lowercases filetree; use the inventory's spelling
|
|
45
|
+
// when checking rules, so dispatch and myAuthorizedRoutes agree.
|
|
46
|
+
const grantPath = (path) => GRANTED_ROUTES.find((candidate) => candidate.toLowerCase() === path.toLowerCase());
|
|
40
47
|
/**
|
|
41
48
|
* The host's own reports, which the server mounts `verifyAdmin` in front of.
|
|
42
49
|
*
|
|
@@ -142,7 +149,12 @@ const dispatch = async (services, routeId, request = {}) => {
|
|
|
142
149
|
// permission rules address. Asked of the record service, so the answer a
|
|
143
150
|
// request meets is the one `myAuthorizedRoutes` reported for the same caller.
|
|
144
151
|
const adminScoped = ADMIN_ROUTES.includes(routeId) && Boolean(services.admin);
|
|
145
|
-
const grantScoped =
|
|
152
|
+
const grantScoped = grantPath(route.path);
|
|
153
|
+
// A host with identity is enforcing access and must not silently skip a
|
|
154
|
+
// permission gate when its record service is absent. A drive-only host has
|
|
155
|
+
// no identity model at all and retains its existing desktop-style behavior.
|
|
156
|
+
if (grantScoped && (identity || request.subject || request.token) && !records)
|
|
157
|
+
throw new types_js_1.ApiError(501, `This host has no record service, so it cannot answer ${routeId}.`);
|
|
146
158
|
// The administrator routes need the record service to answer the question the
|
|
147
159
|
// host's middleware answers on a server. A host that supplies the reports
|
|
148
160
|
// without one is told which capability it is missing, rather than serving its
|
|
@@ -170,16 +182,27 @@ const dispatch = async (services, routeId, request = {}) => {
|
|
|
170
182
|
if ((identityScoped && records) ||
|
|
171
183
|
(runtimeScoped && services.runtime) ||
|
|
172
184
|
adminScoped ||
|
|
173
|
-
grantScoped) {
|
|
185
|
+
(grantScoped && records)) {
|
|
174
186
|
const callerSubject = await caller();
|
|
187
|
+
let publicGrant = false;
|
|
175
188
|
if (!callerSubject) {
|
|
176
|
-
//
|
|
177
|
-
//
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
189
|
+
// An exact public-group grant also authenticates a tokenless caller on
|
|
190
|
+
// the server. Do not treat a parent grant as public authentication.
|
|
191
|
+
publicGrant = Boolean(grantScoped &&
|
|
192
|
+
records &&
|
|
193
|
+
!identityScoped &&
|
|
194
|
+
!runtimeScoped &&
|
|
195
|
+
!adminScoped &&
|
|
196
|
+
(await records.mayUseRoute(undefined, grantScoped)));
|
|
197
|
+
if (!publicGrant) {
|
|
198
|
+
// A host may serve records without a sign-in flow - it resolves the caller
|
|
199
|
+
// itself and passes `subject`. Without one it cannot authenticate at all,
|
|
200
|
+
// and a 401 would send every request round the login loop for ever, so it
|
|
201
|
+
// is told which capability it is missing instead.
|
|
202
|
+
if (!identity)
|
|
203
|
+
throw new types_js_1.ApiError(501, `This host has no identity service, so it cannot answer ${routeId}.`);
|
|
204
|
+
throw new types_js_1.ApiError(401, 'Unauthorized');
|
|
205
|
+
}
|
|
183
206
|
}
|
|
184
207
|
// `verifyAdmin`, in the wording a caller sees on a server - except for a
|
|
185
208
|
// caller the server refuses before that middleware runs, which meets the
|
|
@@ -193,7 +216,10 @@ const dispatch = async (services, routeId, request = {}) => {
|
|
|
193
216
|
}
|
|
194
217
|
// `authorize`: the rules this host's interface reads decide the call, not
|
|
195
218
|
// only the menu entry beside it
|
|
196
|
-
if (grantScoped &&
|
|
219
|
+
if (grantScoped &&
|
|
220
|
+
records &&
|
|
221
|
+
!publicGrant &&
|
|
222
|
+
!(await records.mayUseRoute(callerSubject, grantScoped)))
|
|
197
223
|
throw new types_js_1.ApiError(401, 'Unauthorized');
|
|
198
224
|
}
|
|
199
225
|
validate(route, request);
|
|
@@ -354,6 +354,16 @@ const createRecordService = (store, options = {}) => {
|
|
|
354
354
|
return Boolean(await readerOf(store, caller));
|
|
355
355
|
},
|
|
356
356
|
async mayUseRoute(caller, path) {
|
|
357
|
+
if (!caller) {
|
|
358
|
+
const rules = await store.permissions();
|
|
359
|
+
if (!rules.some((rule) => rule.group !== undefined))
|
|
360
|
+
return false;
|
|
361
|
+
const publicGroup = (await store.groups()).find((group) => group.name === PUBLIC_GROUP);
|
|
362
|
+
return Boolean(publicGroup &&
|
|
363
|
+
rules.some((rule) => rule.group === publicGroup.uid &&
|
|
364
|
+
rule.path === path &&
|
|
365
|
+
rule.setting === 'Grant'));
|
|
366
|
+
}
|
|
357
367
|
const reader = await readerOf(store, caller);
|
|
358
368
|
if (!reader)
|
|
359
369
|
return false;
|
|
@@ -558,6 +558,10 @@ exports.GENERATED_ROUTES = [
|
|
|
558
558
|
status: 400,
|
|
559
559
|
description: 'Invalid Format'
|
|
560
560
|
},
|
|
561
|
+
{
|
|
562
|
+
status: 401,
|
|
563
|
+
description: 'Unauthorized'
|
|
564
|
+
},
|
|
561
565
|
{
|
|
562
566
|
status: 404,
|
|
563
567
|
description: 'No app is published with that id'
|
|
@@ -624,6 +628,10 @@ exports.GENERATED_ROUTES = [
|
|
|
624
628
|
status: 400,
|
|
625
629
|
description: 'Invalid Format'
|
|
626
630
|
},
|
|
631
|
+
{
|
|
632
|
+
status: 401,
|
|
633
|
+
description: 'Unauthorized'
|
|
634
|
+
},
|
|
627
635
|
{
|
|
628
636
|
status: 413,
|
|
629
637
|
description: 'File tree exceeds the deploy limit'
|
|
@@ -694,6 +702,10 @@ exports.GENERATED_ROUTES = [
|
|
|
694
702
|
status: 400,
|
|
695
703
|
description: 'Invalid Format'
|
|
696
704
|
},
|
|
705
|
+
{
|
|
706
|
+
status: 401,
|
|
707
|
+
description: 'Unauthorized'
|
|
708
|
+
},
|
|
697
709
|
{
|
|
698
710
|
status: 413,
|
|
699
711
|
description: 'File tree exceeds the deploy limit'
|
|
@@ -728,6 +740,10 @@ exports.GENERATED_ROUTES = [
|
|
|
728
740
|
status: 400,
|
|
729
741
|
description: "Can't delete file outside drive"
|
|
730
742
|
},
|
|
743
|
+
{
|
|
744
|
+
status: 401,
|
|
745
|
+
description: 'Unauthorized'
|
|
746
|
+
},
|
|
731
747
|
{
|
|
732
748
|
status: 404,
|
|
733
749
|
description: "File doesn't exist"
|
|
@@ -768,6 +784,10 @@ exports.GENERATED_ROUTES = [
|
|
|
768
784
|
status: 400,
|
|
769
785
|
description: 'A path outside the drive, a refused extension, or a request naming neither or both'
|
|
770
786
|
},
|
|
787
|
+
{
|
|
788
|
+
status: 401,
|
|
789
|
+
description: 'Unauthorized'
|
|
790
|
+
},
|
|
771
791
|
{
|
|
772
792
|
status: 404,
|
|
773
793
|
description: "File doesn't exist"
|
|
@@ -810,6 +830,10 @@ exports.GENERATED_ROUTES = [
|
|
|
810
830
|
status: 400,
|
|
811
831
|
description: "Can't modify file outside drive"
|
|
812
832
|
},
|
|
833
|
+
{
|
|
834
|
+
status: 401,
|
|
835
|
+
description: 'Unauthorized'
|
|
836
|
+
},
|
|
813
837
|
{
|
|
814
838
|
status: 404,
|
|
815
839
|
description: "File doesn't exist"
|
|
@@ -852,6 +876,10 @@ exports.GENERATED_ROUTES = [
|
|
|
852
876
|
status: 400,
|
|
853
877
|
description: "Can't put file outside drive"
|
|
854
878
|
},
|
|
879
|
+
{
|
|
880
|
+
status: 401,
|
|
881
|
+
description: 'Unauthorized'
|
|
882
|
+
},
|
|
855
883
|
{
|
|
856
884
|
status: 409,
|
|
857
885
|
description: 'File already exists'
|
|
@@ -877,6 +905,10 @@ exports.GENERATED_ROUTES = [
|
|
|
877
905
|
{
|
|
878
906
|
status: 200,
|
|
879
907
|
description: 'Ok'
|
|
908
|
+
},
|
|
909
|
+
{
|
|
910
|
+
status: 401,
|
|
911
|
+
description: 'Unauthorized'
|
|
880
912
|
}
|
|
881
913
|
]
|
|
882
914
|
},
|
|
@@ -904,6 +936,10 @@ exports.GENERATED_ROUTES = [
|
|
|
904
936
|
status: 400,
|
|
905
937
|
description: "Can't delete folder outside drive"
|
|
906
938
|
},
|
|
939
|
+
{
|
|
940
|
+
status: 401,
|
|
941
|
+
description: 'Unauthorized'
|
|
942
|
+
},
|
|
907
943
|
{
|
|
908
944
|
status: 404,
|
|
909
945
|
description: "Folder doesn't exist"
|
|
@@ -934,6 +970,10 @@ exports.GENERATED_ROUTES = [
|
|
|
934
970
|
status: 400,
|
|
935
971
|
description: "Can't get folder outside drive"
|
|
936
972
|
},
|
|
973
|
+
{
|
|
974
|
+
status: 401,
|
|
975
|
+
description: 'Unauthorized'
|
|
976
|
+
},
|
|
937
977
|
{
|
|
938
978
|
status: 404,
|
|
939
979
|
description: "Folder doesn't exist"
|
|
@@ -964,6 +1004,10 @@ exports.GENERATED_ROUTES = [
|
|
|
964
1004
|
status: 400,
|
|
965
1005
|
description: "Can't put folder outside drive"
|
|
966
1006
|
},
|
|
1007
|
+
{
|
|
1008
|
+
status: 401,
|
|
1009
|
+
description: 'Unauthorized'
|
|
1010
|
+
},
|
|
967
1011
|
{
|
|
968
1012
|
status: 409,
|
|
969
1013
|
description: 'Folder already exists. The body is that message as plain text.'
|
|
@@ -1000,6 +1044,10 @@ exports.GENERATED_ROUTES = [
|
|
|
1000
1044
|
status: 400,
|
|
1001
1045
|
description: "Can't rename outside drive"
|
|
1002
1046
|
},
|
|
1047
|
+
{
|
|
1048
|
+
status: 401,
|
|
1049
|
+
description: 'Unauthorized'
|
|
1050
|
+
},
|
|
1003
1051
|
{
|
|
1004
1052
|
status: 404,
|
|
1005
1053
|
description: 'No file/folder found for provided path'
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* records each place the two disagree.
|
|
13
13
|
*/
|
|
14
14
|
import type { ApiRequest } from '../host/dispatch.js';
|
|
15
|
-
import type
|
|
15
|
+
import { type IdentityFixture } from '../identity/fixture.js';
|
|
16
16
|
import type { AppStreamEntry } from '../appstream/service.js';
|
|
17
17
|
export interface CorpusCase {
|
|
18
18
|
/** Stable name, used as the test's title. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"drive.d.ts","sourceRoot":"","sources":["../../../src/corpus/drive.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAErD,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"drive.d.ts","sourceRoot":"","sources":["../../../src/corpus/drive.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAErD,OAAO,EAAoB,KAAK,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAC/E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAE7D,MAAM,WAAW,UAAU;IACzB,6CAA6C;IAC7C,EAAE,EAAE,MAAM,CAAA;IACV,kEAAkE;IAClE,KAAK,EAAE,MAAM,CAAA;IACb,WAAW,EAAE,MAAM,CAAA;IACnB,kCAAkC;IAClC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAAC,CAAA;IAC1C,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,eAAe,CAAA;IAC1B;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,cAAc,EAAE,CAAA;IAC5B;;;;OAIG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB;;;;;;OAMG;IACH,SAAS,CAAC,EAAE;QAAE,QAAQ,EAAE,MAAM,GAAG,UAAU,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;IACnE,uEAAuE;IACvE,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB;;;;;;;;OAQG;IACH,SAAS,CAAC,EAAE,WAAW,GAAG,SAAS,CAAA;IACnC;;;;;;OAMG;IACH,WAAW,CAAC,EAAE;QACZ,uDAAuD;QACvD,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;QAClB,0EAA0E;QAC1E,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;KACnB,CAAA;IACD,OAAO,EAAE,UAAU,CAAA;IACnB,MAAM,EAAE;QACN,MAAM,EAAE,MAAM,CAAA;QACd,IAAI,CAAC,EAAE,OAAO,CAAA;QACd,QAAQ,CAAC,EAAE,MAAM,GAAG,UAAU,CAAA;QAC9B,yDAAyD;QACzD,KAAK,CAAC,EAAE,MAAM,CAAA;QACd;;;;WAIG;QACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QACjC;;;WAGG;QACH,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;QACf;;;;;;;;;WASG;QACH,KAAK,CAAC,EAAE;YACN,QAAQ,EAAE,MAAM,EAAE,CAAA;YAClB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;SACpB,CAAA;QACD;;;;;;;WAOG;QACH,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAC3B,CAAA;CACF;AA4DD,eAAO,MAAM,YAAY,EAAE,UAAU,EAusBpC,CAAA"}
|