casbin 5.29.0 → 5.31.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/CHANGELOG.md +14 -0
- package/lib/cjs/config.js +5 -0
- package/lib/cjs/coreEnforcer.js +13 -11
- package/lib/cjs/model/model.js +7 -3
- package/lib/esm/config.js +5 -0
- package/lib/esm/coreEnforcer.js +13 -11
- package/lib/esm/model/model.js +7 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
# [5.31.0](https://github.com/casbin/node-casbin/compare/v5.30.0...v5.31.0) (2024-09-28)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* prevent duplicated sections and invalid operators in config and model ([#484](https://github.com/casbin/node-casbin/issues/484)) ([79e0f1c](https://github.com/casbin/node-casbin/commit/79e0f1c8fa551ce456b97729d52a49c762d91169))
|
|
7
|
+
|
|
8
|
+
# [5.30.0](https://github.com/casbin/node-casbin/compare/v5.29.0...v5.30.0) (2024-04-26)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* ensure eft and priority are respected in p2, r2, etc ([#475](https://github.com/casbin/node-casbin/issues/475)) ([8ef3deb](https://github.com/casbin/node-casbin/commit/8ef3debae7d8f081629b038d78e3d869c32be7f2)), closes [#474](https://github.com/casbin/node-casbin/issues/474)
|
|
14
|
+
|
|
1
15
|
# [5.29.0](https://github.com/casbin/node-casbin/compare/v5.28.0...v5.29.0) (2024-04-10)
|
|
2
16
|
|
|
3
17
|
|
package/lib/cjs/config.js
CHANGED
|
@@ -85,6 +85,7 @@ class Config {
|
|
|
85
85
|
const linesCount = lines.length;
|
|
86
86
|
let section = '';
|
|
87
87
|
let currentLine = '';
|
|
88
|
+
const seenSections = new Set();
|
|
88
89
|
lines.forEach((n, index) => {
|
|
89
90
|
let commentPos = n.indexOf(Config.DEFAULT_COMMENT);
|
|
90
91
|
if (commentPos > -1) {
|
|
@@ -105,6 +106,10 @@ class Config {
|
|
|
105
106
|
currentLine = '';
|
|
106
107
|
}
|
|
107
108
|
section = line.substring(1, line.length - 1);
|
|
109
|
+
if (seenSections.has(section)) {
|
|
110
|
+
throw new Error(`Duplicated section: ${section} at line ${lineNumber}`);
|
|
111
|
+
}
|
|
112
|
+
seenSections.add(section);
|
|
108
113
|
}
|
|
109
114
|
else {
|
|
110
115
|
let shouldWrite = false;
|
package/lib/cjs/coreEnforcer.js
CHANGED
|
@@ -172,17 +172,19 @@ class CoreEnforcer {
|
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
174
|
sortPolicies() {
|
|
175
|
-
var _a
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
175
|
+
var _a;
|
|
176
|
+
(_a = this.model.model.get('p')) === null || _a === void 0 ? void 0 : _a.forEach((value, key) => {
|
|
177
|
+
const policy = value.policy;
|
|
178
|
+
const tokens = value.tokens;
|
|
179
|
+
if (policy && tokens) {
|
|
180
|
+
const priorityIndex = tokens.indexOf(`${key}_priority`);
|
|
181
|
+
if (priorityIndex !== -1) {
|
|
182
|
+
policy.sort((a, b) => {
|
|
183
|
+
return parseInt(a[priorityIndex], 10) - parseInt(b[priorityIndex], 10);
|
|
184
|
+
});
|
|
185
|
+
}
|
|
184
186
|
}
|
|
185
|
-
}
|
|
187
|
+
});
|
|
186
188
|
}
|
|
187
189
|
/**
|
|
188
190
|
* loadPolicy reloads the policy from file/database.
|
|
@@ -442,7 +444,7 @@ class CoreEnforcer {
|
|
|
442
444
|
default:
|
|
443
445
|
throw new Error('matcher result should only be of type boolean, number, or string');
|
|
444
446
|
}
|
|
445
|
-
const eft = parameters[
|
|
447
|
+
const eft = parameters[`${enforceContext.pType}_eft`];
|
|
446
448
|
if (eft && eftRes === effect_1.Effect.Allow) {
|
|
447
449
|
if (eft === 'allow') {
|
|
448
450
|
eftRes = effect_1.Effect.Allow;
|
package/lib/cjs/model/model.js
CHANGED
|
@@ -107,6 +107,10 @@ class Model {
|
|
|
107
107
|
stringArguments.forEach((n, index) => {
|
|
108
108
|
value = value.replace(`$<${index}>`, n);
|
|
109
109
|
});
|
|
110
|
+
const invalidOperators = /(?<![&|])&(?!&)|(?<![&|])\|(?!\|)|&{3,}|\|{3,}/g;
|
|
111
|
+
if (invalidOperators.test(value)) {
|
|
112
|
+
throw new Error(`Invalid operator in matcher`);
|
|
113
|
+
}
|
|
110
114
|
ast.value = value;
|
|
111
115
|
}
|
|
112
116
|
else {
|
|
@@ -234,7 +238,7 @@ class Model {
|
|
|
234
238
|
}
|
|
235
239
|
const policy = ast.policy;
|
|
236
240
|
const tokens = ast.tokens;
|
|
237
|
-
const priorityIndex = tokens.indexOf(
|
|
241
|
+
const priorityIndex = tokens.indexOf(`${key}_priority`);
|
|
238
242
|
if (priorityIndex !== -1) {
|
|
239
243
|
const priorityRule = rule[priorityIndex];
|
|
240
244
|
const insertIndex = policy.findIndex((oneRule) => oneRule[priorityIndex] >= priorityRule);
|
|
@@ -264,7 +268,7 @@ class Model {
|
|
|
264
268
|
return [false, []];
|
|
265
269
|
}
|
|
266
270
|
}
|
|
267
|
-
const priorityFlag = ast.tokens.indexOf(
|
|
271
|
+
const priorityFlag = ast.tokens.indexOf(`${ptype}_priority`) !== -1;
|
|
268
272
|
if (priorityFlag) {
|
|
269
273
|
rules.forEach((rule) => {
|
|
270
274
|
this.addPolicy(sec, ptype, rule);
|
|
@@ -286,7 +290,7 @@ class Model {
|
|
|
286
290
|
if (index === -1) {
|
|
287
291
|
return false;
|
|
288
292
|
}
|
|
289
|
-
const priorityIndex = ast.tokens.indexOf(
|
|
293
|
+
const priorityIndex = ast.tokens.indexOf(`${ptype}_priority`);
|
|
290
294
|
if (priorityIndex !== -1) {
|
|
291
295
|
if (oldRule[priorityIndex] === newRule[priorityIndex]) {
|
|
292
296
|
ast.policy[index] = newRule;
|
package/lib/esm/config.js
CHANGED
|
@@ -82,6 +82,7 @@ export class Config {
|
|
|
82
82
|
const linesCount = lines.length;
|
|
83
83
|
let section = '';
|
|
84
84
|
let currentLine = '';
|
|
85
|
+
const seenSections = new Set();
|
|
85
86
|
lines.forEach((n, index) => {
|
|
86
87
|
let commentPos = n.indexOf(Config.DEFAULT_COMMENT);
|
|
87
88
|
if (commentPos > -1) {
|
|
@@ -102,6 +103,10 @@ export class Config {
|
|
|
102
103
|
currentLine = '';
|
|
103
104
|
}
|
|
104
105
|
section = line.substring(1, line.length - 1);
|
|
106
|
+
if (seenSections.has(section)) {
|
|
107
|
+
throw new Error(`Duplicated section: ${section} at line ${lineNumber}`);
|
|
108
|
+
}
|
|
109
|
+
seenSections.add(section);
|
|
105
110
|
}
|
|
106
111
|
else {
|
|
107
112
|
let shouldWrite = false;
|
package/lib/esm/coreEnforcer.js
CHANGED
|
@@ -169,17 +169,19 @@ export class CoreEnforcer {
|
|
|
169
169
|
}
|
|
170
170
|
}
|
|
171
171
|
sortPolicies() {
|
|
172
|
-
var _a
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
172
|
+
var _a;
|
|
173
|
+
(_a = this.model.model.get('p')) === null || _a === void 0 ? void 0 : _a.forEach((value, key) => {
|
|
174
|
+
const policy = value.policy;
|
|
175
|
+
const tokens = value.tokens;
|
|
176
|
+
if (policy && tokens) {
|
|
177
|
+
const priorityIndex = tokens.indexOf(`${key}_priority`);
|
|
178
|
+
if (priorityIndex !== -1) {
|
|
179
|
+
policy.sort((a, b) => {
|
|
180
|
+
return parseInt(a[priorityIndex], 10) - parseInt(b[priorityIndex], 10);
|
|
181
|
+
});
|
|
182
|
+
}
|
|
181
183
|
}
|
|
182
|
-
}
|
|
184
|
+
});
|
|
183
185
|
}
|
|
184
186
|
/**
|
|
185
187
|
* loadPolicy reloads the policy from file/database.
|
|
@@ -439,7 +441,7 @@ export class CoreEnforcer {
|
|
|
439
441
|
default:
|
|
440
442
|
throw new Error('matcher result should only be of type boolean, number, or string');
|
|
441
443
|
}
|
|
442
|
-
const eft = parameters[
|
|
444
|
+
const eft = parameters[`${enforceContext.pType}_eft`];
|
|
443
445
|
if (eft && eftRes === Effect.Allow) {
|
|
444
446
|
if (eft === 'allow') {
|
|
445
447
|
eftRes = Effect.Allow;
|
package/lib/esm/model/model.js
CHANGED
|
@@ -85,6 +85,10 @@ export class Model {
|
|
|
85
85
|
stringArguments.forEach((n, index) => {
|
|
86
86
|
value = value.replace(`$<${index}>`, n);
|
|
87
87
|
});
|
|
88
|
+
const invalidOperators = /(?<![&|])&(?!&)|(?<![&|])\|(?!\|)|&{3,}|\|{3,}/g;
|
|
89
|
+
if (invalidOperators.test(value)) {
|
|
90
|
+
throw new Error(`Invalid operator in matcher`);
|
|
91
|
+
}
|
|
88
92
|
ast.value = value;
|
|
89
93
|
}
|
|
90
94
|
else {
|
|
@@ -212,7 +216,7 @@ export class Model {
|
|
|
212
216
|
}
|
|
213
217
|
const policy = ast.policy;
|
|
214
218
|
const tokens = ast.tokens;
|
|
215
|
-
const priorityIndex = tokens.indexOf(
|
|
219
|
+
const priorityIndex = tokens.indexOf(`${key}_priority`);
|
|
216
220
|
if (priorityIndex !== -1) {
|
|
217
221
|
const priorityRule = rule[priorityIndex];
|
|
218
222
|
const insertIndex = policy.findIndex((oneRule) => oneRule[priorityIndex] >= priorityRule);
|
|
@@ -242,7 +246,7 @@ export class Model {
|
|
|
242
246
|
return [false, []];
|
|
243
247
|
}
|
|
244
248
|
}
|
|
245
|
-
const priorityFlag = ast.tokens.indexOf(
|
|
249
|
+
const priorityFlag = ast.tokens.indexOf(`${ptype}_priority`) !== -1;
|
|
246
250
|
if (priorityFlag) {
|
|
247
251
|
rules.forEach((rule) => {
|
|
248
252
|
this.addPolicy(sec, ptype, rule);
|
|
@@ -264,7 +268,7 @@ export class Model {
|
|
|
264
268
|
if (index === -1) {
|
|
265
269
|
return false;
|
|
266
270
|
}
|
|
267
|
-
const priorityIndex = ast.tokens.indexOf(
|
|
271
|
+
const priorityIndex = ast.tokens.indexOf(`${ptype}_priority`);
|
|
268
272
|
if (priorityIndex !== -1) {
|
|
269
273
|
if (oldRule[priorityIndex] === newRule[priorityIndex]) {
|
|
270
274
|
ast.policy[index] = newRule;
|
package/package.json
CHANGED