Next.js: Remote Code Execution in next/og ImageResponse
Affected releases · next
- 16.x16.2.0 – 16.3.5Fixed in 16.3.6
On 16.x, the newest line:
npm install next@16.3.6Not affected
0.1.0 – 16.1.7
398 releases
Affected
16.2.0 – 16.3.5
19 releases
Fixed
16.3.6 – 16.4.2
6 releases, latest
Is your project affected?
Paste your package.json, or type the range you declare for next. It is read in your browser and sent nowhere.
What happens
Impact
The Node.js ImageResponse implementation from next/og is affected by an upstream vulnerability. This can lead to remote code execution.
Affected applications pass attacker-controlled values into SVG content, attributes, or styles during image generation:
import { ImageResponse } from 'next/og'
export async function GET(request: Request) {
const value = new URL(request.url).searchParams.get('value') ?? ''
return new ImageResponse(
<svg width="1200" height="630">
<title>{value}</title>
</svg>
)
}Applications using the Edge ImageResponse implementation, or applications that do not pass attacker-controlled values into SVG content, attributes, or styles, are not affected.
Workaround
If upgrading is not immediately possible, do not pass attacker-controlled values into SVG content, attributes, or styles rendered by the Node.js ImageResponse implementation from next/og.