The vulnerability described is a reflected Cross-Site Scripting (XSS) attack in the nuxt-og-image package, where query parameters are injected as HTML attributes. The analysis began by identifying the commits between the last vulnerable version (v6.2.4) and the first patched version (v6.2.5). The key commit 3dcf8c1566e30a83fedd1ab2706dc6e8429f513d introduces a fix by sanitizing component props.
The commit analysis reveals two main changes:
- A new function,
sanitizeProps, is added to src/runtime/shared.ts. This function is designed to strip potentially dangerous attributes and event handlers (like on*) from an object of properties.
- The
resolveContext function in src/runtime/server/og-image/context.ts is modified to use this new sanitizeProps function on the options.props object, which is derived from the request's query parameters.
Prior to this change, resolveContext would process the request and pass the raw, unsanitized query parameters as props to the Vue component responsible for rendering the OG image. This is the root cause of the vulnerability. During exploitation, the resolveContext function would be on the call stack as it's the entry point for handling the malicious request and its parameters. Therefore, resolveContext is identified as the vulnerable function.