# GHSA-q2c6-c6pm-g3gh: Arbitrary Code Execution in handlebars

> Attackers can execute arbitrary JavaScript by submitting malicious templates to the handlebars library, affecting both server-side and client-side applications.

- **Severity:** Not scored
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 4 Sep 2020

## What is GHSA-q2c6-c6pm-g3gh?

GHSA-q2c6-c6pm-g3gh is a code injection vulnerability in handlebars, published on 4 Sep 2020. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

Versions of `handlebars` prior to 3.0.8 or 4.5.3 are vulnerable to Arbitrary Code Execution. The package's lookup helper fails to properly validate templates, allowing attackers to submit templates that execute arbitrary JavaScript in the system. It is due to an incomplete fix for a [previous issue](https://www.npmjs.com/advisories/1316). This vulnerability can be used to run arbitrary code in a server processing Handlebars templates or on a victim's browser (effectively serving as Cross-Site Scripting).

## Recommendation

Upgrade to version 3.0.8, 4.5.3 or later.

## Which versions are affected by GHSA-q2c6-c6pm-g3gh?

4 open source packages ship an affected version, including handlebars.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `handlebars` | npm | All versions | 3.0.8 |
| `handlebars` | npm | All versions | 3.0.8 |
| `handlebars` | npm | From 4.0.0 | 4.5.3 |
| `handlebars` | npm | From 4.0.0 | 4.5.3 |

## How do I fix GHSA-q2c6-c6pm-g3gh?

Upgrade handlebars to a fixed version for your release line: 3.0.8 or 4.5.3.

## Is GHSA-q2c6-c6pm-g3gh being exploited?

There is no known exploitation of GHSA-q2c6-c6pm-g3gh in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-q2c6-c6pm-g3gh and fix it if it is affected.

What it is: GHSA-q2c6-c6pm-g3gh is a code injection vulnerability in handlebars, published on 4 Sep 2020. An attacker can exploit it over the internet without logging in, with no action from the victim.
Exploitation: There is no known exploitation of GHSA-q2c6-c6pm-g3gh in the wild and no public exploit code.

Affected packages and fixed versions:
- handlebars (npm): affected all versions; fixed in 3.0.8
- handlebars (npm): affected all versions; fixed in 3.0.8
- handlebars (npm): affected from 4.0.0; fixed in 4.5.3
- handlebars (npm): affected from 4.0.0; fixed in 4.5.3

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/GHSA-q2c6-c6pm-g3gh/ (Markdown: https://insights.sbomify.com/GHSA-q2c6-c6pm-g3gh/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-q2c6-c6pm-g3gh

---
From sbomify Insights: https://insights.sbomify.com/GHSA-q2c6-c6pm-g3gh/
Summaries are generated and may contain mistakes; the official description above is the record.
