@i4e/invest4edu-access-core 0.4.0 → 0.4.1
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 +1 -1
- package/src/tenant-plugin.js +8 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@i4e/invest4edu-access-core",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Shared access-control primitives (Track 3: tenant keystone, role capabilities, reportee tree, feature flags) for NeoFindesk backends.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
package/src/tenant-plugin.js
CHANGED
|
@@ -5,9 +5,11 @@
|
|
|
5
5
|
* injects `account_id` from the request's ALS store (tenant-context.js), so a query cannot
|
|
6
6
|
* reach Mongo without the caller's tenant boundary — even if the controller forgot it.
|
|
7
7
|
*
|
|
8
|
-
* Modes (env `TENANT_ENFORCEMENT`, default `
|
|
9
|
-
* -
|
|
10
|
-
* -
|
|
8
|
+
* Modes (env `TENANT_ENFORCEMENT`, default `off`):
|
|
9
|
+
* - `off` (DEFAULT) → literal no-op; behaviour identical to pre-Track-3. Safe merge baseline.
|
|
10
|
+
* - `warn` → inject `account_id` when identity present; log identity-less reads.
|
|
11
|
+
* - `enforce` → inject when present; THROW on identity-less reads (fail-closed).
|
|
12
|
+
* Rollout ladder: off → warn (burn-in, watch `[tenant] identity-less`) → enforce.
|
|
11
13
|
*
|
|
12
14
|
* Bypass: `runAsSystem(fn)` or `.setOptions({ skipTenant: true })` for legitimately
|
|
13
15
|
* cross-tenant reads. NOT covered: aggregation pipelines and write ops (reads are C0 scope).
|
|
@@ -18,9 +20,11 @@
|
|
|
18
20
|
import als from "./tenant-context.js";
|
|
19
21
|
|
|
20
22
|
const READ_OPS = ["find", "findOne", "countDocuments"];
|
|
21
|
-
const mode = () => (process.env.TENANT_ENFORCEMENT || "
|
|
23
|
+
const mode = () => (process.env.TENANT_ENFORCEMENT || "off").toLowerCase();
|
|
22
24
|
|
|
23
25
|
function tenantHook() {
|
|
26
|
+
if (mode() === "off") return; // literal no-op — identical to pre-Track-3
|
|
27
|
+
|
|
24
28
|
const opts = typeof this.getOptions === "function" ? this.getOptions() : this.options || {};
|
|
25
29
|
if (opts && opts.skipTenant) return;
|
|
26
30
|
|