Baja

Serialize JavaScript: Cross-site scripting (XSS) via unescaped </script at the end of a serialized function body

  • Publicada: 23.10.2026
  • Actualizado: 24.10.2026 05:17

Impact

serialize-javascript escapes its output so it is safe to embed inside a <script> element. Before 7.1.3 that guarantee did not hold for a function value whose source ends in a bare </script.

Each function body is escaped on its own, and a bare </script was only neutralized when followed — within the same body — by a character the HTML tokenizer treats as ending the tag name (TAB, LF, FF, CR, SPACE, / or >). A body ending exactly at </script has no following character, so it was emitted unescaped. The delimiter is then supplied by the surrounding output (for example the newline the space option emits after the value), and a later serialized value can supply the closing > followed by markup:

js
const serialize = require('serialize-javascript');
function f() {} f.toString = () => 'function f(){ return 1 }//</script';
function g() {} g.toString = () => 'function g(x){ return x } > <img src=x onerror=alert(1)>';
serialize({ a: { f }, g }, { space: 2 });
// {
//   "a": {
//     "f": function f(){ return 1 }//</script
//   },
//   "g": function g(x){ return x } > <img src=x onerror=alert(1)>
// }

Embedded in a <script> element, the script ends at the injected tag and the <img> becomes a live element in the page.

Exploitation requires an attacker to control the source text of a serialized function, in practice through a spoofed toString(). Real functions always end in }, so ordinary function values are not affected, and non-function values (including strings containing </script) are escaped correctly.

Patches

Fixed in 7.1.3 (#235). The bare </script form is now also matched at the end of the function body, so it is escaped regardless of what follows it in the output.

Workarounds

Upgrade to 7.1.3. If you cannot upgrade, do not serialize function values whose source text (or toString()) can be influenced by an attacker.

Credits

Reported by ha_kr25 via the Yahoo bug bounty program.

Software afectado

Haz clic en una tecnología para ver todas sus vulnerabilidades.

PlataformaPaqueteVersiones vulnerablesCorregida en
Paquete de npm serialize-javascript < 7.1.3 7.1.3

Referencias

Puntuación CVSS -
Vector CVSS
CVSS:4.0/AV:N/AC:H/AT:P/PR:L/UI:P/VC:L/VI:L/VA:N/SC:L/SI:L/SA:N
Debilidad (CWE)
CWE-79
Plataforma
npm
Paquete
serialize-javascript
Publicada
23.10.2026
Actualizado
24.10.2026 05:17

Fuentes y licencias

OSV / GitHub Advisory Database - GHSA-m5mm-p8h7-m29v - CC BY 4.0

Historial de vulnerabilidades: serialize-javascript

Todas las vulnerabilidades publicadas de este paquete (Paquete de npm), de la más reciente a la más antigua. Muestra si es un fallo aislado o un paquete que hay que vigilar.

Entradas en total
7
Primera → última
12.2019 10.2026
Sin corrección
0
Explotada en ataques
0

Distribución por gravedad

  • Alta 2
  • Media 3
  • Baja 2

Divulgaciones por año

  1. 2019: 1
  2. 2020: 1
  3. 2021: 0
  4. 2022: 0
  5. 2023: 0
  6. 2024: 0
  7. 2025: 1
  8. 2026: 4
  1. Serialize JavaScript: Cross-site scripting (XSS) via unescaped </script at the end of a serialized function body esta entrada
    Baja CVE-2026-115897 < 7.1.3 7.1.3
  2. Media · 5.4 CVE-2024-11831 >= 6.0.0, < 6.0.2 6.0.2
  3. Alta · 8.1 CVE-2020-7660 < 3.1.0 3.1.0
  4. Media · 4.2 CVE-2019-16769 < 2.1.1 2.1.1

Identifica las vulnerabilidades de tu aplicación

Con la integración de DockRay y el inventario de software activado, DockRay compara las versiones notificadas de los componentes con las vulnerabilidades conocidas y avisa de las coincidencias confirmadas. La cobertura depende de la tecnología compatible y de los avisos disponibles.

Conectar tu aplicación
Newsletter DockRay

La seguridad de tus aplicaciones en tu correo

Vulnerabilidades importantes, recomendaciones concretas y consejos prácticos para tus aplicaciones. Elige tus tecnologías y sigue lo que importa para tu proyecto.

  • Un resumen diario de nuevas vulnerabilidades, también las críticas.
  • Avisos sobre actualizaciones importantes.
  • Consejos prácticos sobre seguridad y monitorización de aplicaciones.

Déjalo vacío para recibir avisos de todas las tecnologías.

Suscripción gratuita. Date de baja con un clic en cualquier correo.