CVE-2021-39157

CVE-2021-39157 is a high-severity security vulnerability in detect-character-encoding (npm), affecting versions < 0.7.0. It is fixed in 0.7.0.

Does this CVE actually affect you?

Kodem shows which CVEs are reachable and running in your applications, so you fix what's exploitable, not just what's listed.

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

Runtime intelligence, not another scanner.

Summary

Improper Handling of Exceptional Conditions in detect-character-encoding

CVSS score

CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H/RL:O/RC:C

Base Score: 7.5 (High)
Temporal Score: 7.2 (High)

Since detect-character-encoding is a library, the scoring is based on the “reasonable worst-case implementation scenario”, namely, accepting data from untrusted sources over a network and passing it directly to detect-character-encoding. Depending on your specific implementation, the vulnerability’s severity in your program may be different.

Proof of concept

const express = require("express");
const bodyParser = require("body-parser");
const detectCharacterEncoding = require("detect-character-encoding");

const app = express();

app.use(bodyParser.raw());

app.post("/", (req, res) => {
  const charsetMatch = detectCharacterEncoding(req.body);

  res.end(charsetMatch.encoding);
});

app.listen(3000);

printf "\xAA" | curl --request POST --header "Content-Type: application/octet-stream" --data-binary @- http://localhost:3000 crashes the server.

Impact

In detect-character-encoding v0.6.0 and earlier, data matching no charset causes the Node.js process to crash.

CVE-2021-39157 has a CVSS score of 7.5 (High). The vector is network-reachable, no privileges required, and no user interaction. A CVSS score reflects the worst-case severity of the vulnerability, not your specific exposure. Whether this affects your application depends on whether the vulnerable code is present and reachable in your environment. A fixed version is available (0.7.0); upgrading removes the vulnerable code path.

Affected versions

detect-character-encoding (< 0.7.0)

Security releases

detect-character-encoding → 0.7.0 (npm)

Kodem intelligence

Severity tells you how bad this could be in the worst case. It does not tell you whether you are exposed. Exploitability and impact are functions of runtime truth: whether the vulnerable code is present, reachable, and actually executes in your application. A vulnerable package can sit in your dependency tree and never run.

Kodem, an Intelligent Application Security platform, uses runtime intelligence to reveal which vulnerabilities actually execute in production, so teams prioritize the ones that genuinely matter. Kodem's runtime-powered SCA identifies whether this CVE is reachable in your applications.

Already deployed Kodem?

See it in your environmentNew to Kodem? Get a demo →

Remediation advice

The problem has been patched in detect-character-encoding v0.7.0.

Frequently Asked Questions

  1. What is CVE-2021-39157? CVE-2021-39157 is a high-severity security vulnerability in detect-character-encoding (npm), affecting versions < 0.7.0. It is fixed in 0.7.0.
  2. How severe is CVE-2021-39157? CVE-2021-39157 has a CVSS score of 7.5 (High). This score reflects the worst-case severity of the vulnerability, not your specific exposure. Whether it represents real risk in your environment depends on whether the vulnerable code is present and reachable.
  3. Which versions of detect-character-encoding are affected by CVE-2021-39157? detect-character-encoding (npm) versions < 0.7.0 is affected.
  4. Is there a fix for CVE-2021-39157? Yes. CVE-2021-39157 is fixed in 0.7.0. Upgrade to this version or later.
  5. Is CVE-2021-39157 exploitable, and should I be worried? Whether CVE-2021-39157 is exploitable in your environment depends on whether the vulnerable code is present and reachable. A CVSS score is a worst-case rating; it does not account for your specific deployment, configuration, or usage patterns. Kodem, an Intelligent Application Security platform, uses runtime intelligence to show which vulnerabilities actually execute in production, so you can focus on the ones that represent real risk. Get a demo
  6. What actually determines whether CVE-2021-39157 is exploitable, and how bad it is? Exploitability and impact are not fixed properties of a CVE. They depend on runtime truth: whether the vulnerable code is present, reachable, and actually executes in your application. A high CVSS score on a dependency that never runs is not the same as real risk. Kodem, an Intelligent Application Security platform, uses runtime intelligence to reveal which vulnerabilities actually execute in production, so teams prioritize the ones that genuinely matter.
  7. How do I fix CVE-2021-39157? Upgrade detect-character-encoding to 0.7.0 or later.

Other vulnerabilities in detect-character-encoding

Stop the waste.
Protect your environment with Kodem.