@zvenigora/ng-eval-core 0.10.0 → 0.10.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/CHANGELOG.md CHANGED
@@ -14,6 +14,39 @@ Versions 0.1.104–0.1.107 are on npm without entries here.
14
14
 
15
15
  ---
16
16
 
17
+ ## [0.10.1] - 2026-10-05
18
+
19
+ **A security fix: an expression no longer resolves a name on the prototype-pollution blocklist
20
+ against its context.** A patch for every version up to 0.10.0, with no exported symbol changed.
21
+ It is a patch although an expression that names such a key of its context now throws where it
22
+ used to read a value: the names are `Object.prototype`'s own, a context key with one of them is
23
+ rare, and the defect is a security one. `eval-signals` 0.3.0 and `eval-forms` 0.3.x admit it in
24
+ their peer ranges.
25
+
26
+ ### Security
27
+ - **An expression no longer resolves a name on the prototype-pollution blocklist against its
28
+ context** (B6 in the repository's backlog). An identifier is resolved against the context, and
29
+ for a context built from a plain object or a class instance the lookup was a bare property
30
+ access, so an identifier resolved the members the context inherits from `Object.prototype`; so
31
+ did `this.k` and `this["k"]`. The blocklist guarded member access to the objects an expression
32
+ holds, not resolution against the context, and through `Object`'s own static functions an
33
+ expression could then modify shared prototypes. Every published version up to 0.10.0 is
34
+ affected.
35
+ - **Now refused before any lookup**, with the error the member visitor throws for any other
36
+ object, `Access to dangerous property "constructor" is blocked for security reasons`:
37
+ `__proto__`, `constructor`, `prototype`, the four `__define…` and `__lookup…` accessors,
38
+ `hasOwnProperty`, `isPrototypeOf`, `propertyIsEnumerable`, `toString`, `valueOf` and
39
+ `toLocaleString`, as an identifier, as `this.k` or `this["k"]`, or as a member of an
40
+ `EvalScope` held in the context. This applies over every kind of context: a plain object, a
41
+ `Registry`, a class instance, an `EvalContext`, a prior scope or a signal context. Under
42
+ `caseInsensitive` the key the lookup matched is checked too, so `CONSTRUCTOR` over a context
43
+ that holds `constructor` is refused.
44
+ - **A context key with one of those names can no longer be read by an expression**, even where
45
+ the context holds it as a key of its own, as a `Registry` or a signal context's source can.
46
+ Rename the key. An arrow parameter or a `let` with one of these names was already refused.
47
+
48
+ ---
49
+
17
50
  ## [0.10.0] - 2026-10-03
18
51
 
19
52
  **An opt-in member-write policy on `EvalContext`, and three fixes.** Nothing changes for a context
@@ -928,6 +928,261 @@ var RecursiveVisitorResultType;
928
928
  RecursiveVisitorResultType[RecursiveVisitorResultType["Registry"] = 1] = "Registry";
929
929
  })(RecursiveVisitorResultType || (RecursiveVisitorResultType = {}));
930
930
 
931
+ /**
932
+ * Prototype Pollution Prevention Utilities
933
+ *
934
+ * This module provides safeguards against prototype pollution attacks
935
+ * by controlling access to dangerous property names and ensuring safe
936
+ * object operations.
937
+ */
938
+ /**
939
+ * Set of property names that are dangerous for prototype pollution attacks
940
+ */
941
+ const DANGEROUS_PROPERTY_NAMES = new Set([
942
+ '__proto__',
943
+ 'constructor',
944
+ 'prototype',
945
+ '__defineGetter__',
946
+ '__defineSetter__',
947
+ '__lookupGetter__',
948
+ '__lookupSetter__',
949
+ 'hasOwnProperty',
950
+ 'isPrototypeOf',
951
+ 'propertyIsEnumerable',
952
+ 'toString',
953
+ 'valueOf',
954
+ 'toLocaleString'
955
+ ]);
956
+ /**
957
+ * The subset of DANGEROUS_PROPERTY_NAMES refused on a string, number or
958
+ * boolean receiver: the names that reach a global constructor, a built-in
959
+ * prototype or an accessor definer. The other six - `toString`, `valueOf`,
960
+ * `toLocaleString`, `hasOwnProperty`, `isPrototypeOf`,
961
+ * `propertyIsEnumerable` - are ordinary reads on a primitive and stay
962
+ * readable.
963
+ *
964
+ * Matched by exact key, under `caseInsensitive` too: a primitive receiver is
965
+ * never case-corrected, so a variant such as `s.CONSTRUCTOR` is a missing
966
+ * property, not a route to `String`.
967
+ */
968
+ const DANGEROUS_PRIMITIVE_PROPERTY_NAMES = new Set([
969
+ '__proto__',
970
+ 'constructor',
971
+ 'prototype',
972
+ '__defineGetter__',
973
+ '__defineSetter__',
974
+ '__lookupGetter__',
975
+ '__lookupSetter__'
976
+ ]);
977
+ /**
978
+ * DANGEROUS_PROPERTY_NAMES lower-cased, for {@link mayMatchDangerousProperty}.
979
+ */
980
+ const LOWERED_DANGEROUS_PROPERTY_NAMES = new Set(Array.from(DANGEROUS_PROPERTY_NAMES, (name) => name.toLowerCase()));
981
+ /**
982
+ * Any UTF-16 code unit outside ASCII, for {@link mayMatchDangerousProperty}.
983
+ */
984
+ const NON_ASCII = /[\u0080-￿]/;
985
+ /**
986
+ * Set of constructor names that should be blocked from modification
987
+ */
988
+ const DANGEROUS_CONSTRUCTORS$1 = new Set([
989
+ 'Object',
990
+ 'Function',
991
+ 'Array',
992
+ 'String',
993
+ 'Number',
994
+ 'Boolean',
995
+ 'Date',
996
+ 'RegExp',
997
+ 'Error',
998
+ 'Promise'
999
+ ]);
1000
+ /**
1001
+ * Checks if a property name is dangerous for prototype pollution
1002
+ * @param key The property name to check
1003
+ * @returns true if the property is dangerous, false otherwise
1004
+ */
1005
+ const isDangerousProperty = (key) => {
1006
+ if (typeof key === 'string') {
1007
+ return DANGEROUS_PROPERTY_NAMES.has(key);
1008
+ }
1009
+ return false;
1010
+ };
1011
+ /**
1012
+ * Checks if a property name is dangerous on a primitive receiver
1013
+ * @param key The property name to check
1014
+ * @returns true if the property is in the primitive subset, false otherwise
1015
+ */
1016
+ const isDangerousPrimitiveProperty = (key) => {
1017
+ if (typeof key === 'string') {
1018
+ return DANGEROUS_PRIMITIVE_PROPERTY_NAMES.has(key);
1019
+ }
1020
+ return false;
1021
+ };
1022
+ /**
1023
+ * Whether a name, matched against a context under `caseInsensitive`, could
1024
+ * match a key in DANGEROUS_PROPERTY_NAMES: the cheap filter ahead of
1025
+ * `EvalContext.getKey`, which says which key it did match. False means it
1026
+ * cannot, so an identifier pays for `getKey` only when it is near a dangerous
1027
+ * name.
1028
+ *
1029
+ * A context matches another spelling in two ways. A case-insensitive
1030
+ * `Registry`, and an `eval-signals` source, compare `toLowerCase()` forms, so
1031
+ * a name can match a dangerous key only if its own lower-case form is one. A
1032
+ * prior scope's namespace is compared by `localeCompare` at base sensitivity,
1033
+ * which ignores accents as well as case: on ASCII identifier characters that
1034
+ * is the same comparison, but a name with any other character may match a
1035
+ * dangerous key - `cönstructor` matches `constructor` - so such a name always
1036
+ * answers true.
1037
+ * @param name The name as written
1038
+ * @returns false if the name cannot match a dangerous key, true otherwise
1039
+ */
1040
+ const mayMatchDangerousProperty = (name) => NON_ASCII.test(name) || LOWERED_DANGEROUS_PROPERTY_NAMES.has(name.toLowerCase());
1041
+ /**
1042
+ * Checks if an object is a dangerous constructor that shouldn't be modified
1043
+ * @param obj The object to check
1044
+ * @returns true if the object is a dangerous constructor, false otherwise
1045
+ */
1046
+ const isDangerousConstructor = (obj) => {
1047
+ if (typeof obj === 'function' && obj.name) {
1048
+ return DANGEROUS_CONSTRUCTORS$1.has(obj.name);
1049
+ }
1050
+ return false;
1051
+ };
1052
+ /**
1053
+ * Safely sets a property on an object with prototype pollution protection.
1054
+ * Refuses a dangerous target or key, then assigns - so a setter runs, and a
1055
+ * write the object refuses throws, prefixed "Failed to set property".
1056
+ * @param target The target object
1057
+ * @param key The property key
1058
+ * @param value The property value
1059
+ * @throws Error if the operation would cause prototype pollution, or if the
1060
+ * object refuses the write
1061
+ */
1062
+ const safeSetProperty = (target, key, value) => {
1063
+ if (!target || (typeof target !== 'object' && typeof target !== 'function')) {
1064
+ throw new Error(`Cannot set property on non-object: ${typeof target}`);
1065
+ }
1066
+ if (isDangerousProperty(key)) {
1067
+ throw new Error(`Access to dangerous property "${String(key)}" is blocked for security reasons`);
1068
+ }
1069
+ // Additional protection: don't allow setting properties on built-in prototypes
1070
+ if (isDangerousConstructor(target)) {
1071
+ throw new Error(`Modification of built-in constructor "${target.name}" is blocked for security reasons`);
1072
+ }
1073
+ // Check if we're trying to modify prototype chain
1074
+ if (target === Object.prototype ||
1075
+ target === Function.prototype ||
1076
+ target === Array.prototype ||
1077
+ target === String.prototype ||
1078
+ target === Number.prototype ||
1079
+ target === Boolean.prototype) {
1080
+ throw new Error(`Modification of built-in prototype is blocked for security reasons`);
1081
+ }
1082
+ // Convert key to PropertyKey for safe operations
1083
+ let propertyKey;
1084
+ if (typeof key === 'string' || typeof key === 'number' || typeof key === 'symbol') {
1085
+ propertyKey = key;
1086
+ }
1087
+ else {
1088
+ // For other types, try to convert to string
1089
+ propertyKey = String(key);
1090
+ }
1091
+ // An assignment, after every refusal above - not a definition. Up to 0.9.x
1092
+ // this was `Object.defineProperty` with a writable, enumerable, configurable
1093
+ // descriptor (`docs/backlog-retired.md` A23), which a write in JavaScript is
1094
+ // not: it replaced an own accessor and hid an inherited one, so no setter
1095
+ // ever ran; it made a non-enumerable property enumerable; and it refused
1096
+ // every non-configurable property, `lastIndex` and an array's `length`
1097
+ // included. Reads already ran the caller's getters, so running its setters
1098
+ // here is the one behaviour this adds. This module is strict, so a write the
1099
+ // object refuses - frozen, non-writable, an accessor with no setter - throws
1100
+ // rather than failing silently, and is reported below.
1101
+ try {
1102
+ target[propertyKey] = value;
1103
+ }
1104
+ catch (error) {
1105
+ throw new Error(`Failed to set property "${String(key)}": ${error instanceof Error ? error.message : String(error)}`);
1106
+ }
1107
+ };
1108
+ /**
1109
+ * Safely gets a property from an object with prototype pollution protection
1110
+ * @param target The target object
1111
+ * @param key The property key
1112
+ * @returns The property value or undefined
1113
+ */
1114
+ const safeGetProperty = (target, key) => {
1115
+ if (!target || (typeof target !== 'object' && typeof target !== 'function')) {
1116
+ return undefined;
1117
+ }
1118
+ if (isDangerousProperty(key)) {
1119
+ throw new Error(`Access to dangerous property "${String(key)}" is blocked for security reasons`);
1120
+ }
1121
+ // Convert key to PropertyKey for safe operations
1122
+ let propertyKey;
1123
+ if (typeof key === 'string' || typeof key === 'number' || typeof key === 'symbol') {
1124
+ propertyKey = key;
1125
+ }
1126
+ else {
1127
+ // For other types, try to convert to string
1128
+ propertyKey = String(key);
1129
+ }
1130
+ // Direct property access using bracket notation (safer than complex prototype walking)
1131
+ try {
1132
+ return target[propertyKey];
1133
+ }
1134
+ catch {
1135
+ // If property access fails, return undefined
1136
+ return undefined;
1137
+ }
1138
+ };
1139
+ /**
1140
+ * Creates a safe object without dangerous prototype pollution vectors
1141
+ * @param entries Key-value pairs to populate the object
1142
+ * @returns A new safe object
1143
+ */
1144
+ const createSafeObject = (entries = []) => {
1145
+ // Create object with normal prototype for compatibility, but validate contents
1146
+ const obj = {};
1147
+ for (const [key, value] of entries) {
1148
+ if (isDangerousProperty(key)) {
1149
+ throw new Error(`Cannot create object with dangerous property "${String(key)}"`);
1150
+ }
1151
+ // Safely set the property
1152
+ if (typeof key === 'string' || typeof key === 'number') {
1153
+ obj[key] = value;
1154
+ }
1155
+ else if (typeof key === 'symbol') {
1156
+ obj[key] = value;
1157
+ }
1158
+ }
1159
+ return obj;
1160
+ };
1161
+ /**
1162
+ * Validates that an object is safe from prototype pollution
1163
+ * @param obj The object to validate
1164
+ * @throws Error if the object contains dangerous properties
1165
+ */
1166
+ const validateSafeObject = (obj) => {
1167
+ if (!obj || typeof obj !== 'object') {
1168
+ return;
1169
+ }
1170
+ const keys = Object.getOwnPropertyNames(obj);
1171
+ for (const key of keys) {
1172
+ if (isDangerousProperty(key)) {
1173
+ throw new Error(`Object contains dangerous property "${key}" that could lead to prototype pollution`);
1174
+ }
1175
+ }
1176
+ // Also check symbol properties
1177
+ const symbols = Object.getOwnPropertySymbols(obj);
1178
+ for (const symbol of symbols) {
1179
+ const description = symbol.description;
1180
+ if (description && isDangerousProperty(description)) {
1181
+ throw new Error(`Object contains dangerous symbol property "${description}" that could lead to prototype pollution`);
1182
+ }
1183
+ }
1184
+ };
1185
+
931
1186
  const literals = Registry.fromObject({
932
1187
  'undefined': undefined,
933
1188
  'null': null,
@@ -974,11 +1229,50 @@ const emitRead = (node, st, value) => {
974
1229
  ...(scoped ? { scoped: true } : {})
975
1230
  });
976
1231
  };
1232
+ /**
1233
+ * Refuses an identifier whose name is on the prototype-pollution blocklist,
1234
+ * before any lookup, with the member visitor's error.
1235
+ *
1236
+ * An identifier is resolved against the context, and `EvalContext.get` reads a
1237
+ * plain object there - the original, or a scope - with a bare property access.
1238
+ * So up to 0.10.0 a name on the blocklist resolved to what the context inherits
1239
+ * from `Object.prototype` (`docs/backlog-retired.md` B6): the blocklist guarded
1240
+ * member access to the objects an expression holds, and the context is not one
1241
+ * of them. Every kind of context is refused alike, including those - a
1242
+ * `Registry`, a signal context's source - that hold such a name only as a key
1243
+ * of their own.
1244
+ */
1245
+ const refuseDangerousName = (node) => {
1246
+ if (isDangerousProperty(node.name)) {
1247
+ throw new Error(`Access to dangerous property "${node.name}" is blocked for security reasons`);
1248
+ }
1249
+ };
1250
+ /**
1251
+ * Under `caseInsensitive`, refuses an identifier whose lookup matched a key on
1252
+ * the blocklist - `CONSTRUCTOR` over a context holding `constructor` - as the
1253
+ * member visitor re-checks `foundKey` for another object.
1254
+ *
1255
+ * The matched key is asked of `getKey`, which answers the key `get` resolves,
1256
+ * and only for a name `mayMatchDangerousProperty` lets through. Any other name
1257
+ * cannot match a blocklisted key, and an identifier must not pay a second
1258
+ * resolution for nothing: the performance spec's read-emission guard asserts
1259
+ * that, with no read hook, `getKey` is not called per identifier.
1260
+ */
1261
+ const refuseDangerousMatch = (node, st) => {
1262
+ if (!st.context || !mayMatchDangerousProperty(node.name)) {
1263
+ return;
1264
+ }
1265
+ const matched = st.context.getKey(node.name);
1266
+ if (isDangerousProperty(matched)) {
1267
+ throw new Error(`Access to dangerous property "${String(matched)}" is blocked for security reasons`);
1268
+ }
1269
+ };
977
1270
  const identifierVisitor = (node, st) => {
978
1271
  if (st.options?.caseInsensitive) {
979
1272
  return identifierVisitorCaseInsensitive(node, st);
980
1273
  }
981
1274
  beforeVisitor(node, st);
1275
+ refuseDangerousName(node);
982
1276
  const context = st.context;
983
1277
  const isThis = node.name === 'this';
984
1278
  const value = isThis
@@ -995,8 +1289,12 @@ const identifierVisitor = (node, st) => {
995
1289
  };
996
1290
  const identifierVisitorCaseInsensitive = (node, st) => {
997
1291
  beforeVisitor(node, st);
1292
+ refuseDangerousName(node);
998
1293
  const context = st.context;
999
1294
  const isThis = !!equalIgnoreCase(node.name, 'this');
1295
+ if (!isThis) {
1296
+ refuseDangerousMatch(node, st);
1297
+ }
1000
1298
  const value = isThis
1001
1299
  ? st.context
1002
1300
  : context?.get(node.name) ?? literals.get(node.name);
@@ -1192,234 +1490,6 @@ const binaryExpressionVisitor = (node, st, callback) => {
1192
1490
  afterVisitor(node, st);
1193
1491
  };
1194
1492
 
1195
- /**
1196
- * Prototype Pollution Prevention Utilities
1197
- *
1198
- * This module provides safeguards against prototype pollution attacks
1199
- * by controlling access to dangerous property names and ensuring safe
1200
- * object operations.
1201
- */
1202
- /**
1203
- * Set of property names that are dangerous for prototype pollution attacks
1204
- */
1205
- const DANGEROUS_PROPERTY_NAMES = new Set([
1206
- '__proto__',
1207
- 'constructor',
1208
- 'prototype',
1209
- '__defineGetter__',
1210
- '__defineSetter__',
1211
- '__lookupGetter__',
1212
- '__lookupSetter__',
1213
- 'hasOwnProperty',
1214
- 'isPrototypeOf',
1215
- 'propertyIsEnumerable',
1216
- 'toString',
1217
- 'valueOf',
1218
- 'toLocaleString'
1219
- ]);
1220
- /**
1221
- * The subset of DANGEROUS_PROPERTY_NAMES refused on a string, number or
1222
- * boolean receiver: the names that reach a global constructor, a built-in
1223
- * prototype or an accessor definer. The other six - `toString`, `valueOf`,
1224
- * `toLocaleString`, `hasOwnProperty`, `isPrototypeOf`,
1225
- * `propertyIsEnumerable` - are ordinary reads on a primitive and stay
1226
- * readable.
1227
- *
1228
- * Matched by exact key, under `caseInsensitive` too: a primitive receiver is
1229
- * never case-corrected, so a variant such as `s.CONSTRUCTOR` is a missing
1230
- * property, not a route to `String`.
1231
- */
1232
- const DANGEROUS_PRIMITIVE_PROPERTY_NAMES = new Set([
1233
- '__proto__',
1234
- 'constructor',
1235
- 'prototype',
1236
- '__defineGetter__',
1237
- '__defineSetter__',
1238
- '__lookupGetter__',
1239
- '__lookupSetter__'
1240
- ]);
1241
- /**
1242
- * Set of constructor names that should be blocked from modification
1243
- */
1244
- const DANGEROUS_CONSTRUCTORS$1 = new Set([
1245
- 'Object',
1246
- 'Function',
1247
- 'Array',
1248
- 'String',
1249
- 'Number',
1250
- 'Boolean',
1251
- 'Date',
1252
- 'RegExp',
1253
- 'Error',
1254
- 'Promise'
1255
- ]);
1256
- /**
1257
- * Checks if a property name is dangerous for prototype pollution
1258
- * @param key The property name to check
1259
- * @returns true if the property is dangerous, false otherwise
1260
- */
1261
- const isDangerousProperty = (key) => {
1262
- if (typeof key === 'string') {
1263
- return DANGEROUS_PROPERTY_NAMES.has(key);
1264
- }
1265
- return false;
1266
- };
1267
- /**
1268
- * Checks if a property name is dangerous on a primitive receiver
1269
- * @param key The property name to check
1270
- * @returns true if the property is in the primitive subset, false otherwise
1271
- */
1272
- const isDangerousPrimitiveProperty = (key) => {
1273
- if (typeof key === 'string') {
1274
- return DANGEROUS_PRIMITIVE_PROPERTY_NAMES.has(key);
1275
- }
1276
- return false;
1277
- };
1278
- /**
1279
- * Checks if an object is a dangerous constructor that shouldn't be modified
1280
- * @param obj The object to check
1281
- * @returns true if the object is a dangerous constructor, false otherwise
1282
- */
1283
- const isDangerousConstructor = (obj) => {
1284
- if (typeof obj === 'function' && obj.name) {
1285
- return DANGEROUS_CONSTRUCTORS$1.has(obj.name);
1286
- }
1287
- return false;
1288
- };
1289
- /**
1290
- * Safely sets a property on an object with prototype pollution protection.
1291
- * Refuses a dangerous target or key, then assigns - so a setter runs, and a
1292
- * write the object refuses throws, prefixed "Failed to set property".
1293
- * @param target The target object
1294
- * @param key The property key
1295
- * @param value The property value
1296
- * @throws Error if the operation would cause prototype pollution, or if the
1297
- * object refuses the write
1298
- */
1299
- const safeSetProperty = (target, key, value) => {
1300
- if (!target || (typeof target !== 'object' && typeof target !== 'function')) {
1301
- throw new Error(`Cannot set property on non-object: ${typeof target}`);
1302
- }
1303
- if (isDangerousProperty(key)) {
1304
- throw new Error(`Access to dangerous property "${String(key)}" is blocked for security reasons`);
1305
- }
1306
- // Additional protection: don't allow setting properties on built-in prototypes
1307
- if (isDangerousConstructor(target)) {
1308
- throw new Error(`Modification of built-in constructor "${target.name}" is blocked for security reasons`);
1309
- }
1310
- // Check if we're trying to modify prototype chain
1311
- if (target === Object.prototype ||
1312
- target === Function.prototype ||
1313
- target === Array.prototype ||
1314
- target === String.prototype ||
1315
- target === Number.prototype ||
1316
- target === Boolean.prototype) {
1317
- throw new Error(`Modification of built-in prototype is blocked for security reasons`);
1318
- }
1319
- // Convert key to PropertyKey for safe operations
1320
- let propertyKey;
1321
- if (typeof key === 'string' || typeof key === 'number' || typeof key === 'symbol') {
1322
- propertyKey = key;
1323
- }
1324
- else {
1325
- // For other types, try to convert to string
1326
- propertyKey = String(key);
1327
- }
1328
- // An assignment, after every refusal above - not a definition. Up to 0.9.x
1329
- // this was `Object.defineProperty` with a writable, enumerable, configurable
1330
- // descriptor (`docs/backlog-retired.md` A23), which a write in JavaScript is
1331
- // not: it replaced an own accessor and hid an inherited one, so no setter
1332
- // ever ran; it made a non-enumerable property enumerable; and it refused
1333
- // every non-configurable property, `lastIndex` and an array's `length`
1334
- // included. Reads already ran the caller's getters, so running its setters
1335
- // here is the one behaviour this adds. This module is strict, so a write the
1336
- // object refuses - frozen, non-writable, an accessor with no setter - throws
1337
- // rather than failing silently, and is reported below.
1338
- try {
1339
- target[propertyKey] = value;
1340
- }
1341
- catch (error) {
1342
- throw new Error(`Failed to set property "${String(key)}": ${error instanceof Error ? error.message : String(error)}`);
1343
- }
1344
- };
1345
- /**
1346
- * Safely gets a property from an object with prototype pollution protection
1347
- * @param target The target object
1348
- * @param key The property key
1349
- * @returns The property value or undefined
1350
- */
1351
- const safeGetProperty = (target, key) => {
1352
- if (!target || (typeof target !== 'object' && typeof target !== 'function')) {
1353
- return undefined;
1354
- }
1355
- if (isDangerousProperty(key)) {
1356
- throw new Error(`Access to dangerous property "${String(key)}" is blocked for security reasons`);
1357
- }
1358
- // Convert key to PropertyKey for safe operations
1359
- let propertyKey;
1360
- if (typeof key === 'string' || typeof key === 'number' || typeof key === 'symbol') {
1361
- propertyKey = key;
1362
- }
1363
- else {
1364
- // For other types, try to convert to string
1365
- propertyKey = String(key);
1366
- }
1367
- // Direct property access using bracket notation (safer than complex prototype walking)
1368
- try {
1369
- return target[propertyKey];
1370
- }
1371
- catch {
1372
- // If property access fails, return undefined
1373
- return undefined;
1374
- }
1375
- };
1376
- /**
1377
- * Creates a safe object without dangerous prototype pollution vectors
1378
- * @param entries Key-value pairs to populate the object
1379
- * @returns A new safe object
1380
- */
1381
- const createSafeObject = (entries = []) => {
1382
- // Create object with normal prototype for compatibility, but validate contents
1383
- const obj = {};
1384
- for (const [key, value] of entries) {
1385
- if (isDangerousProperty(key)) {
1386
- throw new Error(`Cannot create object with dangerous property "${String(key)}"`);
1387
- }
1388
- // Safely set the property
1389
- if (typeof key === 'string' || typeof key === 'number') {
1390
- obj[key] = value;
1391
- }
1392
- else if (typeof key === 'symbol') {
1393
- obj[key] = value;
1394
- }
1395
- }
1396
- return obj;
1397
- };
1398
- /**
1399
- * Validates that an object is safe from prototype pollution
1400
- * @param obj The object to validate
1401
- * @throws Error if the object contains dangerous properties
1402
- */
1403
- const validateSafeObject = (obj) => {
1404
- if (!obj || typeof obj !== 'object') {
1405
- return;
1406
- }
1407
- const keys = Object.getOwnPropertyNames(obj);
1408
- for (const key of keys) {
1409
- if (isDangerousProperty(key)) {
1410
- throw new Error(`Object contains dangerous property "${key}" that could lead to prototype pollution`);
1411
- }
1412
- }
1413
- // Also check symbol properties
1414
- const symbols = Object.getOwnPropertySymbols(obj);
1415
- for (const symbol of symbols) {
1416
- const description = symbol.description;
1417
- if (description && isDangerousProperty(description)) {
1418
- throw new Error(`Object contains dangerous symbol property "${description}" that could lead to prototype pollution`);
1419
- }
1420
- }
1421
- };
1422
-
1423
1493
  /**
1424
1494
  * Property Lookup Cache
1425
1495
  *
@@ -1633,10 +1703,22 @@ const evaluateMember = (node, st, callback) => {
1633
1703
  }
1634
1704
  // Get the value with context-aware or prototype pollution protection
1635
1705
  if (object === st.context) {
1706
+ // `this.k` resolves `k` against the context, as an identifier does, so it
1707
+ // is refused as one is (`identifier.ts`, `docs/backlog-retired.md` B6): a
1708
+ // blocklisted key before the lookup, and under `caseInsensitive` a
1709
+ // blocklisted key the lookup matched. Up to 0.10.0 neither was checked,
1710
+ // and `this.constructor` over a plain object was `Object`.
1711
+ if (isDangerousProperty(key)) {
1712
+ throw new Error(`Access to dangerous property "${String(key)}" is blocked for security reasons`);
1713
+ }
1636
1714
  // For context objects, preserve case-insensitive behavior
1637
- const contextKey = st.options?.caseInsensitive && typeof key === 'string'
1638
- ? st.context.getKey(key)
1639
- : key;
1715
+ let contextKey = key;
1716
+ if (st.options?.caseInsensitive && typeof key === 'string') {
1717
+ contextKey = st.context.getKey(key);
1718
+ if (isDangerousProperty(contextKey)) {
1719
+ throw new Error(`Access to dangerous property "${String(contextKey)}" is blocked for security reasons`);
1720
+ }
1721
+ }
1640
1722
  const value = st.context.get(contextKey);
1641
1723
  const thisValue = st.context.getThis(contextKey);
1642
1724
  if (st.hasHooks && st.hooks.hasReadHooks) {
@@ -1653,6 +1735,11 @@ const evaluateMember = (node, st, callback) => {
1653
1735
  return [thisValue ?? object, contextKey, value];
1654
1736
  }
1655
1737
  else if (object instanceof EvalScope) {
1738
+ // A global scope reads its object as the context does, with a bare
1739
+ // property access, so a blocklisted key is refused here as it is above.
1740
+ if (isDangerousProperty(key)) {
1741
+ throw new Error(`Access to dangerous property "${String(key)}" is blocked for security reasons`);
1742
+ }
1656
1743
  // For scope objects, preserve original behavior (no getKey method)
1657
1744
  const value = object.get(key);
1658
1745
  const thisValue = object;