Skip to content

Commit 9239cd3

Browse files
committed
fix by copilot's review
1 parent 565b2a2 commit 9239cd3

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

packages/devextreme/js/__internal/core/utils/m_data.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,16 @@ export const compileSetter = function (expr) {
186186

187187
return function (obj, value, options) {
188188
options = prepareOptions(options);
189+
190+
const unsafeFragment = expr.find(isUnsafePathFragment);
191+
if (unsafeFragment !== undefined) {
192+
errors.log('E0123', unsafeFragment);
193+
return;
194+
}
195+
189196
let currentValue = unwrap(obj, options);
190197

191198
expr.forEach(function (propertyName, levelIndex) {
192-
if (isUnsafePathFragment(propertyName)) {
193-
errors.log('E0123', propertyName);
194-
return;
195-
}
196-
197199
let propertyValue = readPropValue(currentValue, propertyName, options);
198200
const isPropertyFunc = !options.functionsAsIs && isFunction(propertyValue) && !isWrapped(propertyValue);
199201

packages/devextreme/testing/tests/DevExpress.core/utils.data.tests.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,16 +493,20 @@ QUnit.module('prototype pollution protection', {
493493
}, () => {
494494

495495
test('compileSetter logs error and skips assignment for __proto__ path fragment', function(assert) {
496-
SETTER('__proto__.pp_dx')({}, 'yes', { functionsAsIs: true });
496+
const obj = {};
497+
SETTER('__proto__.pp_dx')(obj, 'yes', { functionsAsIs: true });
497498

498499
assert.strictEqual(errors.log.calledWith('E0123', '__proto__'), true, 'should log E0123 for __proto__');
500+
assert.strictEqual(obj.pp_dx, undefined, 'target object must not be modified');
499501
assert.strictEqual(({}).pp_dx, undefined, 'Object.prototype must not be polluted');
500502
});
501503

502504
test('compileSetter logs error and skips assignment for constructor path fragment', function(assert) {
503-
SETTER('constructor.prototype.pp_dx')({}, 'yes', { functionsAsIs: true });
505+
const obj = {};
506+
SETTER('constructor.prototype.pp_dx')(obj, 'yes', { functionsAsIs: true });
504507

505508
assert.strictEqual(errors.log.calledWith('E0123', 'constructor'), true, 'should log E0123 for constructor');
509+
assert.strictEqual(obj.pp_dx, undefined, 'target object must not be modified');
506510
assert.strictEqual(({}).pp_dx, undefined, 'Object.prototype must not be polluted');
507511
});
508512

@@ -511,6 +515,7 @@ QUnit.module('prototype pollution protection', {
511515
SETTER('prototype.pp_dx')(fn, 'yes', { functionsAsIs: true });
512516

513517
assert.strictEqual(errors.log.calledWith('E0123', 'prototype'), true, 'should log E0123 for prototype');
518+
assert.strictEqual(fn.pp_dx, undefined, 'function object must not be modified');
514519
assert.strictEqual(fn.prototype.pp_dx, undefined, 'function prototype must not be modified');
515520
});
516521

0 commit comments

Comments
 (0)