The vulnerability, GHSA-458j-xx4x-4375, in Hono's JSX module is an HTML injection vulnerability caused by improper handling of attribute names during server-side rendering (SSR). The root cause is the lack of validation on attribute keys when rendering JSX elements to an HTML string. An attacker who can control the keys of attributes in a JSX element can inject malicious HTML, leading to potential Cross-Site Scripting (XSS).
The patch addresses this by introducing a new validation function, isValidAttributeName, in src/jsx/utils.ts. This function checks for invalid characters in attribute names that could be used for injection, such as quotes, angle brackets, and spaces.
This validation is then applied in two key vulnerable functions:
JSXNode.toString() in src/jsx/base.ts: This is the core of the SSR rendering logic. The patch ensures that any attribute with an invalid key is skipped during the serialization process.
jsxAttr() in src/jsx/jsx-runtime.ts: This helper function for creating attributes is also patched to validate the attribute key.
Additionally, the client-side DOM renderer is made more robust. The applyProps function in src/jsx/dom/render.ts is updated to catch exceptions that can occur when using invalid attribute names with setAttribute and removeAttribute, preventing potential rendering failures on the client side.