NodeJS/highlight.js/9.18.1
Syntax highlighting with language autodetection.
https://www.npmjs.com/package/highlight.js
BSD-3-Clause
2 Security Vulnerabilities
ReDOS vulnerabities: multiple grammars
- https://github.com/highlightjs/highlight.js/security/advisories/GHSA-7wwv-vh3v-89cq
- https://github.com/advisories/GHSA-7wwv-vh3v-89cq
- https://github.com/highlightjs/highlight.js/commit/373b9d862401162e832ce77305e49b859e110f9c
- https://www.npmjs.com/package/@highlightjs/cdn-assets
- https://www.npmjs.com/package/highlight.js
Impact: Potential ReDOS vulnerabilities (exponential and polynomial RegEx backtracking)
The Regular expression Denial of Service (ReDoS) is a Denial of Service attack, that exploits the fact that most Regular Expression implementations may reach extreme situations that cause them to work very slowly (exponentially related to input size). An attacker can then cause a program using a Regular Expression to enter these extreme situations and then hang for a very long time.
If are you are using Highlight.js to highlight user-provided data you are possibly vulnerable. On the client-side (in a browser or Electron environment) risks could include lengthy freezes or crashes... On the server-side infinite freezes could occur... effectively preventing users from accessing your app or service (ie, Denial of Service).
This is an issue with grammars shipped with the parser (and potentially 3rd party grammars also), not the parser itself. If you are using Highlight.js with any of the following grammars you are vulnerable. If you are using highlightAuto
to detect the language (and have any of these grammars registered) you are vulnerable. Exponential grammars (C, Perl, JavaScript) are auto-registered when using the common grammar subset/library require('highlight.js/lib/common')
as of 10.4.0 - see https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@10.4.0/build/highlight.js
All versions prior to 10.4.1 are vulnerable, including version 9.18.5.
Grammars with exponential backtracking issues:
- c-like (c, cpp, arduino)
- handlebars (htmlbars)
- gams
- perl
- jboss-cli
- r
- erlang-repl
- powershell
- routeros
- livescript (10.4.0 and 9.18.5 included this fix)
- javascript & typescript (10.4.0 included partial fixes)
And of course any aliases of those languages have the same issue. ie: hpp
is no safer than cpp
.
Grammars with polynomial backtracking issues:
- kotlin
- gcode
- d
- aspectj
- moonscript
- coffeescript/livescript
- csharp
- scilab
- crystal
- elixir
- basic
- ebnf
- ruby
- fortran/irpf90
- livecodeserver
- yaml
- x86asm
- dsconfig
- markdown
- ruleslanguage
- xquery
- sqf
And again: any aliases of those languages have the same issue. ie: ruby
and rb
share the same ruby issues.
Patches
- Version 10.4.1 resolves these vulnerabilities. Please upgrade.
Workarounds / Mitigations
- Discontinue use the affected grammars. (or perhaps use only those with poly vs exponential issues)
- Attempt cherry-picking the grammar fixes into older versions...
- Attempt using newer CDN versions of any affected languages. (ie using an older CDN version of the library with newer CDN grammars). Your mileage may vary.
References
For more information
If you have any questions or comments about this advisory: * Open an issue: https://github.com/highlightjs/highlight.js/issues * Email us at security@highlightjs.com
Prototype Pollution in highlight.js
- https://github.com/highlightjs/highlight.js/security/advisories/GHSA-vfrc-7r7c-w9mx
- https://nvd.nist.gov/vuln/detail/CVE-2020-26237
- https://github.com/advisories/GHSA-vfrc-7r7c-w9mx
- https://github.com/highlightjs/highlight.js/pull/2636
- https://github.com/highlightjs/highlight.js/commit/7241013ae011a585983e176ddc0489a7a52f6bb0
- https://www.npmjs.com/package/highlight.js
- https://lists.debian.org/debian-lts-announce/2020/12/msg00041.html
- https://www.oracle.com/security-alerts/cpujul2022.html
Impact
Affected versions of this package 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.
Patches
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.
Workarounds
Patch your library
Manually patch your library to create null objects for both languages
and aliases
:
const HLJS = function(hljs) {
// ...
var languages = Object.create(null);
var aliases = Object.create(null);
Filter out bad data from end users:
Filter the language names that users are allowed to inject into your HTML to guarantee they are valid.
References
For more information
If you have any questions or comments about this advisory:
- Please file an issue against highlight.js
100 Other Versions
Version | License | Security | Released | |
---|---|---|---|---|
11.9.0 | BSD-3-Clause | 2023-10-09 - 03:53 | 6 months | |
11.8.0 | BSD-3-Clause | 2023-04-29 - 13:37 | 12 months | |
11.7.0 | BSD-3-Clause | 2022-11-23 - 22:09 | over 1 year | |
11.6.0 | BSD-3-Clause | 2022-07-13 - 15:11 | almost 2 years | |
11.5.1 | BSD-3-Clause | 2022-04-11 - 01:16 | about 2 years | |
11.5.0 | BSD-3-Clause | 2022-03-12 - 00:35 | about 2 years | |
11.4.0 | BSD-3-Clause | 2022-01-06 - 14:57 | over 2 years | |
11.3.1 | BSD-3-Clause | 2021-10-17 - 20:19 | over 2 years | |
11.3.0 | BSD-3-Clause | 2021-10-17 - 13:32 | over 2 years | |
11.2.0 | BSD-3-Clause | 2021-08-02 - 01:43 | over 2 years | |
11.1.0 | BSD-3-Clause | 2021-07-08 - 14:58 | almost 3 years | |
11.0.1 | BSD-3-Clause | 2021-06-04 - 01:47 | almost 3 years | |
11.0.0 | BSD-3-Clause | 2021-05-30 - 08:06 | almost 3 years | |
11.0.0-beta1 | BSD-3-Clause | 2021-05-16 - 16:36 | almost 3 years | |
11.0.0-beta0 | BSD-3-Clause | 2021-05-04 - 12:35 | almost 3 years | |
11.0.0-alpha1 | BSD-3-Clause | 2021-04-22 - 16:58 | almost 3 years | |
11.0.0-alpha0 | BSD-3-Clause | 2021-04-13 - 11:46 | about 3 years | |
10.7.3 | BSD-3-Clause | 2021-06-04 - 01:40 | almost 3 years | |
10.7.2 | BSD-3-Clause | 2021-04-04 - 19:32 | about 3 years | |
10.7.1 | BSD-3-Clause | 2021-03-21 - 08:22 | about 3 years | |
10.7.0 | BSD-3-Clause | 2021-03-20 - 13:16 | about 3 years | |
10.6.0 | BSD-3-Clause | 2021-02-08 - 13:25 | about 3 years | |
10.5.0 | BSD-3-Clause | 2020-12-23 - 20:40 | over 3 years | |
10.4.1 | BSD-3-Clause | 2020-12-03 - 17:22 | over 3 years | |
10.4.0 | BSD-3-Clause | 1 | 2020-11-18 - 19:11 | over 3 years |
10.4.0-beta1 | BSD-3-Clause | 1 | 2020-11-15 - 04:18 | over 3 years |
10.4.0-beta0 | BSD-3-Clause | 1 | 2020-11-13 - 20:31 | over 3 years |
10.3.2 | BSD-3-Clause | 1 | 2020-10-29 - 13:08 | over 3 years |
10.3.1 | BSD-3-Clause | 1 | 2020-10-17 - 23:37 | over 3 years |
10.3.0 | BSD-3-Clause | 1 | 2020-10-17 - 17:32 | over 3 years |
10.2.1 | BSD-3-Clause | 1 | 2020-10-01 - 14:37 | over 3 years |
10.2.0 | BSD-3-Clause | 1 | 2020-09-07 - 20:21 | over 3 years |
10.1.2 | BSD-3-Clause | 1 | 2020-07-23 - 21:06 | over 3 years |
10.1.1 | BSD-3-Clause | 2 | 2020-06-16 - 16:23 | almost 4 years |
10.1.0 | BSD-3-Clause | 2 | 2020-06-11 - 23:28 | almost 4 years |
10.0.3 | BSD-3-Clause | 2 | 2020-05-12 - 01:02 | almost 4 years |
10.0.2 | BSD-3-Clause | 2 | 2020-05-03 - 18:14 | almost 4 years |
10.0.1 | BSD-3-Clause | 2 | 2020-04-26 - 22:39 | almost 4 years |
10.0.0 | BSD-3-Clause | 2 | 2020-04-21 - 22:54 | almost 4 years |
10.0.0-beta.0 | BSD-3-Clause | 1 | 2020-03-10 - 02:02 | about 4 years |
9.18.5 | BSD-3-Clause | 1 | 2020-11-19 - 17:45 | over 3 years |
9.18.4 | BSD-3-Clause | 1 | 2020-11-18 - 20:13 | over 3 years |
9.18.3 | BSD-3-Clause | 1 | 2020-07-29 - 00:31 | over 3 years |
9.18.2 | BSD-3-Clause | 1 | 2020-07-28 - 14:47 | over 3 years |
9.18.1 | BSD-3-Clause | 2 | 2020-02-01 - 17:45 | about 4 years |
9.18.0 | BSD-3-Clause | 2 | 2020-01-20 - 14:01 | about 4 years |
9.17.1 | BSD-3-Clause | 2 | 2019-12-12 - 14:11 | over 4 years |
9.17.0 | BSD-3-Clause | 2 | 2019-12-11 - 01:58 | over 4 years |
9.16.2 | BSD-3-Clause | 2 | 2019-11-01 - 14:37 | over 4 years |
9.16.1 | BSD-3-Clause | 2 | 2019-10-31 - 15:35 | over 4 years |
9.15.10 | BSD-3-Clause | 2 | 2019-08-20 - 03:21 | over 4 years |
9.15.9 | BSD-3-Clause | 2 | 2019-07-31 - 02:51 | over 4 years |
9.15.8 | BSD-3-Clause | 2 | 2019-05-29 - 07:33 | almost 5 years |
9.15.7 | BSD-3-Clause | 2 | 2019-05-29 - 03:37 | almost 5 years |
9.15.6 | BSD-3-Clause | 2 | 2019-02-26 - 21:56 | about 5 years |
9.15.5 | BSD-3-Clause | 2 | 2019-02-25 - 23:22 | about 5 years |
9.15.2 | BSD-3-Clause | 2 | 2019-02-25 - 09:20 | about 5 years |
9.15.1 | BSD-3-Clause | 2 | 2019-02-25 - 05:35 | about 5 years |
9.14.2 | BSD-3-Clause | 2 | 2019-02-01 - 04:27 | about 5 years |
9.14.1 | BSD-3-Clause | 2 | 2019-01-30 - 07:43 | about 5 years |
9.13.1 | BSD-3-Clause | 2 | 2018-10-17 - 02:30 | over 5 years |
9.13.0 | BSD-3-Clause | 2 | 2018-10-13 - 03:08 | over 5 years |
9.12.0 | BSD-3-Clause | 2 | 2017-05-31 - 02:47 | almost 7 years |
9.11.0 | BSD-3-Clause | 2 | 2017-04-19 - 07:20 | almost 7 years |
9.10.0 | BSD-3-Clause | 2 | 2017-03-08 - 07:36 | about 7 years |
9.9.0 | BSD-3-Clause | 2 | 2016-12-14 - 07:12 | over 7 years |
9.8.0 | BSD-3-Clause | 2 | 2016-11-02 - 05:54 | over 7 years |
9.7.0 | BSD-3-Clause | 2 | 2016-09-21 - 05:44 | over 7 years |
9.6.0 | BSD-3-Clause | 2 | 2016-08-10 - 05:14 | over 7 years |
9.5.0 | BSD-3-Clause | 2 | 2016-06-28 - 21:46 | almost 8 years |
9.4.0 | BSD-3-Clause | 2 | 2016-05-17 - 19:16 | almost 8 years |
9.3.0 | BSD-3-Clause | 2 | 2016-04-05 - 19:11 | about 8 years |
9.2.0 | BSD-3-Clause | 2 | 2016-02-23 - 22:36 | about 8 years |
9.1.0 | BSD-3-Clause | 2 | 2016-01-06 - 15:00 | over 8 years |
9.0.0 | BSD-3-Clause | 2 | 2015-12-02 - 03:13 | over 8 years |
8.9.1 | BSD-3-Clause | 1 | 2015-10-19 - 22:55 | over 8 years |
8.9.0 | BSD-3-Clause | 1 | 2015-10-19 - 22:21 | over 8 years |
8.8.0 | BSD-3-Clause | 1 | 2015-09-06 - 15:25 | over 8 years |
8.7.0 | BSD-3-Clause | 1 | 2015-07-28 - 21:29 | over 8 years |
8.6.0 | BSD-3-Clause | 1 | 2015-05-20 - 07:25 | almost 9 years |
8.5.0 | BSD | 1 | 2015-04-03 - 05:50 | about 9 years |
8.4.0 | BSD | 1 | 2014-11-18 - 19:38 | over 9 years |
8.3.0 | BSD | 1 | 2014-10-09 - 20:21 | over 9 years |
8.2.0 | BSD | 1 | 2014-08-20 - 21:56 | over 9 years |
8.1.0 | BSD | 1 | 2014-07-08 - 21:21 | almost 10 years |
8.0.0 | BSD | 1 | 2014-01-09 - 00:30 | over 10 years |
7.5.0 | BSD | 1 | 2013-11-20 - 07:54 | over 10 years |
7.4.0 | BSD | 1 | 2013-10-30 - 22:14 | over 10 years |
7.3.0 | BSD | 1 | 2012-10-13 - 04:11 | over 11 years |
7.2.0 | BSD | 1 | 2012-08-28 - 01:19 | over 11 years |
7.1.0 | BSD | 1 | 2012-08-11 - 22:01 | over 11 years |
7.0.1 | BSD | 1 | 2012-06-04 - 20:16 | almost 12 years |
1.2.0 | BSD-3-Clause | 1 | 2012-04-24 - 15:41 | almost 12 years |
1.1.1 | BSD-3-Clause | 1 | 2012-02-26 - 00:39 | about 12 years |
1.1.0 | BSD-3-Clause | 1 | 2012-01-30 - 20:23 | about 12 years |
1.0.4 | BSD-3-Clause | 1 | 2012-01-26 - 19:38 | about 12 years |
1.0.3 | BSD-3-Clause | 1 | 2012-01-26 - 15:55 | about 12 years |
1.0.2 | BSD-3-Clause | 1 | 2011-09-24 - 20:22 | over 12 years |
1.0.1 | BSD-3-Clause | 1 | 2011-09-18 - 20:33 | over 12 years |
1.0.0 | BSD-3-Clause | 1 | 2011-07-15 - 00:49 | almost 13 years |