Skip to content

Commit 82503a3

Browse files
committed
fix by review
1 parent 1ab7b73 commit 82503a3

2 files changed

Lines changed: 26 additions & 4 deletions

File tree

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,15 @@ export const compileGetter = function (expr) {
7070
const path = getPathParts(expr);
7171
const unsafeFragment = path.find(isUnsafePathFragment);
7272

73-
return function (obj, options) {
74-
if (unsafeFragment !== undefined) {
73+
if (unsafeFragment !== undefined) {
74+
return function () {
7575
errors.log('E0123', unsafeFragment);
76+
// eslint-disable-next-line no-useless-return
7677
return;
77-
}
78+
};
79+
}
7880

81+
return function (obj, options) {
7982
options = prepareOptions(options);
8083
const functionAsIs = options.functionsAsIs;
8184
const hasDefaultValue = 'defaultValue' in options;
@@ -179,6 +182,8 @@ export const compileSetter = function (expr) {
179182
if (unsafeFragment !== undefined) {
180183
return function () {
181184
errors.log('E0123', unsafeFragment);
185+
// eslint-disable-next-line no-useless-return
186+
return;
182187
};
183188
}
184189

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,24 @@ QUnit.module('prototype pollution protection', {
527527
assert.strictEqual(errors.log.called, false, 'should not log for safe paths');
528528
});
529529

530-
test('compileGetter logs error and returns undefined for __proto__ path fragment (T1330839)', function(assert) {
530+
test('compileSetter blocks unsafe fragment written in bracket notation (T1330839)', function(assert) {
531+
const obj = {};
532+
SETTER('a[constructor][prototype].pp_dx')(obj, 'yes', { functionsAsIs: true });
533+
534+
assert.strictEqual(errors.log.calledWith('E0123', 'constructor'), true, 'should log E0123 for constructor in bracket notation');
535+
assert.strictEqual(({}).pp_dx, undefined, 'Object.prototype must not be polluted');
536+
});
537+
538+
test('compileSetter blocks unsafe fragment in non-first position (T1330839)', function(assert) {
539+
const obj = { a: { b: {} } };
540+
SETTER('a.b.__proto__')(obj, { pp_dx: 'yes' }, { functionsAsIs: true });
541+
542+
assert.strictEqual(errors.log.calledWith('E0123', '__proto__'), true, 'should log E0123 for __proto__ in non-first position');
543+
assert.strictEqual(obj.a.b.pp_dx, undefined, 'nested object must not inherit a polluted property');
544+
assert.strictEqual(({}).pp_dx, undefined, 'Object.prototype must not be polluted');
545+
});
546+
547+
test('compileGetter logs error and returns undefined for __proto__ path fragent (T1330839)', function(assert) {
531548
const result = GETTER('__proto__.pp_dx')({});
532549

533550
assert.strictEqual(errors.log.calledWith('E0123', '__proto__'), true, 'should log E0123 for __proto__');

0 commit comments

Comments
 (0)