Phoenix.HTML vulnerable to attribute injection via unvalidated attribute names in attributes_escape/1
Affected packages
| Package | Affected → Fixed | |
|---|---|---|
| phoenixframeworkphoenix_html |
≥ 6ad3a1d7960891a468d54636054a98e11dfb5111 (no fix yet)→ a47dc8944a773b7e9273d9691dc6744ec793f1de, d9e4e6b2d9be49e25fb6d6b4fdbb2008174f01a6 |
a47dc8944a773b7e9273d9691dc6744ec793f1de, d9e4e6b2d9be49e25fb6d6b4fdbb2008174f01a6 |
| Hexphoenix_html |
≥ 1.0.0, < 3.3.5→ 3.3.5 ≥ 4.0.0, < 4.4.0→ 4.4.0 |
3.3.5 4.4.0 |
Original description The description as published by the source.
Summary
Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') vulnerability in phoenixframework phoenix_html allows an attacker who controls attribute names to inject attributes and script into rendered HTML via Phoenix.HTML.attributes_escape/1.
attributes_escape/1 in lib/phoenix_html.ex escapes attribute values but not attribute names. key_escape/1 passes a binary key through html_escape, which neutralizes quotes and angle brackets but not whitespace, so a key such as x onmouseover ends the attribute and starts a new one. An atom key is only dasherized, so any character passes, including quotes and >. Nested data, aria and phx keys take the same paths. An application is affected when it builds attribute keys from untrusted input and renders them through HEEx ``, content_tag/3, or a direct call. Before 3.0.0 the same code lived in Phoenix.HTML.Tag.
This issue affects phoenix_html: from 1.0.0 before 3.3.5 and from 4.0.0 before 4.4.0.
Details
1. Attribute rendering. Phoenix.HTML.attributes_escape/1 walks the key-value pairs through build_attrs/1 and nested_attrs/3 and emits each as key_escape(k)="attr_escape(v)". Values are escaped. Names are not checked against the HTML attribute-name grammar.
2. Binary names. key_escape/1 sends a binary through Phoenix.HTML.Engine.html_escape/1, which replaces &, <, >, " and '. Whitespace passes. HTML uses whitespace to separate attributes, so `%{…
Source: CVE.org (CVE Program・cvelistV5) NVD GitHub Advisory
References
- advisory nvd.nist.gov
- advisory github.com
- package hex.pm
- package github.com
- patch github.com
- patch github.com
- web cna.erlef.org
- web osv.dev
- web github.com
- web github.com
- web github.com
- web repo.hex.pm