Packages / highlight.js / Security
Prototype Pollution in highlight.js
Affected releases · highlight.js
- 10.x10.0.0 – 10.1.1Fixed in 10.1.2
- 9.x9.0.0 – 9.18.1Fixed in 9.18.2
- 8.x and older1.0.0 – 8.9.1No fix, no longer updated
On 10.x, the newest line:
npm install highlight.js@10.1.2Every release on a timeline
Not affected
11.0.0 – 11.12.0
18 releases, latest
Affected
10.0.0 – 10.1.1
6 releases
Fixed
10.1.2 – 10.7.3
14 releases
Affected
9.0.0 – 9.18.1
31 releases
Fixed
9.18.2 – 9.18.5
4 releases
Affected
8.0.0 – 8.9.1
11 releases
Affected
7.0.1 – 7.5.0
6 releases
Affected
1.0.0 – 1.2.0
8 releases
What happens
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
A whole project to check? Paste its package.json in the dependency check: every deprecated, outdated or vulnerable dependency, with what to upgrade to. Free, no account.