Lucene search

K
githubGitHub Advisory DatabaseGHSA-82JV-9WJW-PQH6
HistoryApr 17, 2024 - 10:26 p.m.

Prototype pollution in emit function

2024-04-1722:26:37
CWE-1321
GitHub Advisory Database
github.com
8
prototype pollution
derby application
unsanitized variable
javascript object
application crash
security patch

7 High

AI Score

Confidence

High

Summary

A prototype pollution in derby can crash the application, if the application author has atypical HTML templates that feed user input into an object key.

Attribute keys are almost always developer-controlled, not end-user-controlled, so this shouldn’t be an issue in practice for most applications.

Details

emit(context: Context, target: T) {
  const node = traverseAndCreate(context.controller, this.segments);
    node[this.lastSegment] = target;
    this.addListeners(target, node, this.lastSegment);
}

The emit() function in src/templates/templates.ts is called without sanitizing the variable this.lastSegment . The variable this.lastSegment can be set to __proto__, and this will pollute the prototype of Javascipt Object (node['__proto__'] = target).

PoC

To reproduce this vulnerability, you can adjust the test case ignores DOM mutations in components\' create() in test/dom/ComponentHarness.mocha.js.

it('ignores DOM mutations in components\' create()', function() {
      function Box() {}
      Box.view = {
        is: 'box',
-        source: '&lt;index:&gt;<div></div>'
+        source: '&lt;index:&gt;<div></div>'
      };
      Box.prototype.create = function() {
        this.boxElement.className = 'box-changed-in-create';
      };
      var harness = runner.createHarness('&lt;view is="box" /&gt;', Box);
      expect(harness).to.render('<div></div>');
});

When as attribute is controlled by attackers, the variable in this.lastSegment will exactly take value __proto__ and prototype pollution happens.

Patch

Add a check on this.lastSegment can prevent this attack.

emit(context: Context, target: T) {
  const node = traverseAndCreate(context.controller, this.segments);
+  if (this.lastSegment.includes('__proto__') || this.lastSegment.includes('prototype')) {
+    throw new Error('Unsafe code detected');
+  }
    node[this.lastSegment] = target;
    this.addListeners(target, node, this.lastSegment);
}

Affected configurations

Vulners
Node
apachederbyRange4.0.0-beta.10
OR
apachederbyRange3.0.1
OR
apachederbyRange2.3.1
CPENameOperatorVersion
derbyle4.0.0-beta.10
derbyle3.0.1
derbyle2.3.1

7 High

AI Score

Confidence

High