CVE-2020-26237 (published 2020-11-24T23:15Z)

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.

Severity: MEDIUM
CVSS v2 base score: 4.9 (AV:N/AC:M/Au:S/C:N/I:P/A:P)
CVSS v3 base score: 8.7, HIGH (CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:C/C:N/I:H/A:H)

Weakness information:
cwe_id: CWE-471
cwe_name: Modification of Assumed-Immutable Data (MAID)
description: The product does not properly protect an assumed-immutable element from being modified by an attacker.
extended_description: This occurs when a particular input is critical enough to the functioning of the application that it should not be modifiable at all, but it is. Certain resources are often assumed to be immutable when they are not, such as hidden form fields in web applications, cookies, and reverse DNS lookups.
         

Fix information:
repo_url: https://github.com/highlightjs/highlight.js
commit_details: repo_url: https://github.com/highlightjs/highlight.js
author: Zack
author_date: 2020-07-20 17:22:42-07:00
msg: (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`.
repository: repo_url: https://github.com/highlightjs/highlight.js
repo_name: highlightjs/highlight.js
description: JavaScript syntax highlighter with language auto-detection and zero dependencies.
repo_language: JavaScript
owner: highlightjs
file_changes: filename: CHANGES.md
change_type: ModificationType.MODIFY
diff: @@ -1,3 +1,12 @@
+## 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:

programming_language: Markdown
filename: highlight.js
change_type: ModificationType.MODIFY
diff: @@ -29,9 +29,9 @@ const HLJS = function(hljs) {
 
   // 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 = [];
 

programming_language: JavaScript
filename: getLanguage.js
change_type: ModificationType.MODIFY
diff: @@ -41,4 +41,16 @@ describe('.getLanguage()', () => {
     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);
+  });
 });

programming_language: JavaScript