CVE-2020-26237: Modification of Assumed-Immutable Data (MAID) (CWE-471)
value: Highlight.js is a syntax highlighter written in JavaScript. Highlight.js versions before 9.18.2 and 10.1.2 are vulnerable to Prototype Pollution. A malicious HTML code block can be crafted that will result in prototype pollution of the base object's prototype during highlighting. If you allow users to insert custom HTML code blocks into your page/app via parsing Markdown code blocks (or similar) and do not filter the language names the user can provide you may be vulnerable. The pollution should just be harmless data but this can cause problems for applications not expecting these properties to exist and can result in strange behavior or application crashes, i.e. a potential DOS vector. If your website or application does not render user provided data it should be unaffected. Versions 9.18.2 and 10.1.2 and newer include fixes for this vulnerability. If you are using version 7 or 8 you are encouraged to upgrade to a newer release.
CWE description: The product does not properly protect an assumed-immutable element from being modified by an attacker.
CVSS v3 base score: 8.7
Published: 2020-11-24T23:15Z
Repository: https://github.com/highlightjs/highlight.js
Language: JavaScript
Files changed: CHANGES.md, src/highlight.js, test/api/getLanguage.js
Commit date: 2020-07-23 16:58:53 -0400
Commit message: (parser) use null prototype objects for languages/aliases (#2636)

Fix: Discord uses getLanguage to validate that a language specified exists in highlightJS and retrieve metadata about the language for code block highlighting in chat. Because highlightJS returns prototype values instead of the highlight languages themselves, the result is a few different bugs in our clients which expect the return type to be only `Language | undefined`.

Diff: diff --git a/CHANGES.md b/CHANGES.md
index 7dde7b45..34a5e311 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -1,5 +1,14 @@
+## Version 10.1.2
+
+Fixes:
+
+- fix(night) Prevent object prototype values from being returned by `getLanguage` (#2636) [night][]
+
+[night]: https://github.com/night
+
+
 ## Version 10.1.1
 
 Fixes:
 
 - Resolve issue on Node 6 due to dangling comma (#2608) [Edwin Hoogerbeets][]
diff --git a/src/highlight.js b/src/highlight.js
index 4f98f38e..b16efe83 100644
--- a/src/highlight.js
+++ b/src/highlight.js
@@ -27,13 +27,13 @@ const HLJS = function(hljs) {
   /** @type {unknown[]} */
   var ArrayProto = [];
 
   // Global internal variables used within the highlight.js library.
   /** @type {Record<string, Language>} */
-  var languages = {};
+  var languages = Object.create(null);
   /** @type {Record<string, string>} */
-  var aliases = {};
+  var aliases = Object.create(null);
   /** @type {HLJSPlugin[]} */
   var plugins = [];
 
   // safe/production mode - swallows more errors, tries to keep running
   // even if a single syntax or parse hits a fatal error
diff --git a/test/api/getLanguage.js b/test/api/getLanguage.js
index d2654a4f..ae14ebb9 100644
--- a/test/api/getLanguage.js
+++ b/test/api/getLanguage.js
@@ -39,6 +39,18 @@ describe('.getLanguage()', () => {
 
     result.should.be.instanceOf(Object);
     result.should.have.property('aliases').with.containEql('cs');
     should.strictEqual(result, hljs.getLanguage('csharp'))
   });
+
+  it('should not succeed for constructor', () => {
+    const result = hljs.getLanguage('constructor');
+
+    should.strictEqual(result, undefined);
+  });
+
+  it('should not succeed for __proto__', () => {
+    const result = hljs.getLanguage('__proto__');
+
+    should.strictEqual(result, undefined);
+  });
 });

Vulnerable code:   var languages = {};
  var aliases = {};
Fixed code: ## Version 10.1.2

Fixes:

- fix(night) Prevent object prototype values from being returned by `getLanguage` (#2636) [night][]

[night]: https://github.com/night


  var languages = Object.create(null);
  var aliases = Object.create(null);

  it('should not succeed for constructor', () => {
    const result = hljs.getLanguage('constructor');

    should.strictEqual(result, undefined);
  });

  it('should not succeed for __proto__', () => {
    const result = hljs.getLanguage('__proto__');

    should.strictEqual(result, undefined);
  });