@ultimat3/policy 31.48.0 → 31.50.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/package.json +2 -2
- package/src/errors.ts +1 -1
- package/src/permissions.ts +6 -0
- package/src/policy.ts +18 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultimat3/policy",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.50.0",
|
|
4
4
|
"description": "The one authz rule, evaluated identically in every surface",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ultimate",
|
|
@@ -42,6 +42,6 @@
|
|
|
42
42
|
"test": "bun test"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@ultimat3/core": "31.
|
|
45
|
+
"@ultimat3/core": "31.50.0"
|
|
46
46
|
}
|
|
47
47
|
}
|
package/src/errors.ts
CHANGED
|
@@ -108,7 +108,7 @@ export const policyForbidden = (label: string, reason: string): PolicyError =>
|
|
|
108
108
|
// `x policy list --json` is what `X_DECLARATION_UNKNOWN`'s own fix falls back to, so a reader
|
|
109
109
|
// who follows either one lands in the same place.
|
|
110
110
|
fix: BARE_PERMISSION.test(label)
|
|
111
|
-
? `x policy explain ${renderFixShellArg(label, '<permission>')} --json # shows which clause decided and why`
|
|
111
|
+
? `x policy explain ${renderFixShellArg(label, '<permission>')} --input '<the request input as JSON>' --json # shows which clause decided and why; --input decides a predicate that reads the request`
|
|
112
112
|
: `x policy list --json # then: x policy explain <permission> --json for the clause that decided`,
|
|
113
113
|
// The remote caller's half: it holds a credential, not the policy file.
|
|
114
114
|
callerFix: deniedCallerFix(BARE_PERMISSION.test(label) ? label : undefined),
|
package/src/permissions.ts
CHANGED
|
@@ -42,6 +42,12 @@ const sites = new Map<string, Set<string>>();
|
|
|
42
42
|
|
|
43
43
|
export const knownPermissions = (): readonly string[] => [...declared].sort();
|
|
44
44
|
|
|
45
|
+
/**
|
|
46
|
+
* Whether the declared set is nonempty — `can()`'s deferred check asks it per decision. A
|
|
47
|
+
* `definePermissions([])` leaves it empty, so it is not the same as "a declaration ran".
|
|
48
|
+
*/
|
|
49
|
+
export const permissionSetDeclared = (): boolean => declared.size > 0;
|
|
50
|
+
|
|
45
51
|
/**
|
|
46
52
|
* Where each permission was declared: one stack frame per distinct declaring call, as
|
|
47
53
|
* `roleDeclarationSites()` answers for roles. ALL of them rather than the first, because the
|
package/src/policy.ts
CHANGED
|
@@ -4,7 +4,12 @@
|
|
|
4
4
|
import type { Ctx } from '@ultimat3/core';
|
|
5
5
|
import { emptyClauseList } from './errors';
|
|
6
6
|
import { actorHas } from './grant-index';
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
assertPermission,
|
|
9
|
+
type KnownPermission,
|
|
10
|
+
type Permission,
|
|
11
|
+
permissionSetDeclared,
|
|
12
|
+
} from './permissions';
|
|
8
13
|
import { markPreInput, type PreInputRun, preInputRun } from './pre-input-brand';
|
|
9
14
|
import type { Actor } from './roles';
|
|
10
15
|
import type { PolicyScope } from './scope';
|
|
@@ -132,10 +137,22 @@ export const can = <I = unknown, R = unknown>(
|
|
|
132
137
|
): Policy<I, R> => {
|
|
133
138
|
assertPermission(permission);
|
|
134
139
|
const label = permission;
|
|
140
|
+
// Built while no permission was declared — a rule at module scope imported ahead of the app's
|
|
141
|
+
// permission module — the check above had nothing to check against and let the name through.
|
|
142
|
+
// So it is made again at the first decision after the declared set becomes nonempty (an empty
|
|
143
|
+
// `definePermissions([])` does not count): a name that set lacks is `X_PERMISSION_UNKNOWN` there,
|
|
144
|
+
// never a deny for every actor with no reason given. Decisions before that stay unchecked.
|
|
145
|
+
let vetted = permissionSetDeclared();
|
|
146
|
+
const vet = (): void => {
|
|
147
|
+
if (vetted || !permissionSetDeclared()) return;
|
|
148
|
+
assertPermission(permission);
|
|
149
|
+
vetted = true;
|
|
150
|
+
};
|
|
135
151
|
// The actor half of the rule, on its own: it reads nothing the caller sent, which is what lets
|
|
136
152
|
// the before-input gate (`pre-input.ts`) refuse a caller who may never call this before their
|
|
137
153
|
// payload is parsed — and a 403 then says nothing about the input schema.
|
|
138
154
|
const gate = (actor: Actor | null): PolicyDecision | undefined => {
|
|
155
|
+
vet();
|
|
139
156
|
if (actor === null) return denied(`no actor for ${label}`, 'X_UNAUTHENTICATED');
|
|
140
157
|
if (!actorHas(actor, permission as Permission)) return denied(`actor lacks ${label}`);
|
|
141
158
|
return undefined;
|