# GHSA-hj8m-9fhf-v7jp: fief-server Server-Side Template Injection vulnerability

> An authenticated user can execute arbitrary code on the server via Server-Side Template Injection in email templates.

- **Severity:** Not scored
- **Exploited in the wild:** Not known
- **Login needed:** Any signed-in user
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 23 Jun 2023

## What is GHSA-hj8m-9fhf-v7jp?

GHSA-hj8m-9fhf-v7jp is a code injection vulnerability in fief-server, published on 23 Jun 2023. Any signed-in user can exploit it over the network, with no action from the victim.

### Official description

# Server-Side Template Injection

## Overview of the Vulnerability

Server-Side Template Injection (SSTI) is a vulnerability within application templating engines where user input is improperly handled and is embedded into the template, possibly leading code being executed.

An attacker can use SSTI to execute code on the underlying system by manipulating values within the embedded template. When code is executed within the underlying system, it can allow an attacker to run permissioned commands under the exploited process, or exploit Cross-Site Scripting (XSS) to run code within the user's browser.

## Business Impact

SSTI can lead to reputational damage for the business due to a loss in confidence and trust by users. If an attacker successfully executes code within the underlying system, it can result in data theft and indirect financial losses.

## Steps to Reproduce

1. [Sign up](https://fief.fief.dev/register) and login to your account
1. Use a browser to navigate to: email-templates {{[URL](https://test.fief.dev/admin/customization/email-templates/)}}
1. put your payload in Edit Base template `{{ cycler.__init__.__globals__.os.popen('id').read() }}` and you will se it will execute.

Payload:
`{{ cycler.__init__.__globals__.os.popen('id').read() }}`

## Proof of Concept (PoC)

The screenshot(s) below demonstrates the SSTI:

![SSTI](https://user-images.githubusercontent.com/42150485/248214990-854c2272-4f34-4c49-9759-d49ce8ce3d12.png)

## Which versions are affected by GHSA-hj8m-9fhf-v7jp?

2 open source packages ship an affected version, including fief-server.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `fief-server` | PyPI | From 0.19.0 | 0.25.3 |
| `fief-server` | PyPI | From 0.19.0 | 0.25.3 |

## How do I fix GHSA-hj8m-9fhf-v7jp?

Upgrade fief-server to 0.25.3 or later.

## Is GHSA-hj8m-9fhf-v7jp being exploited?

There is no known exploitation of GHSA-hj8m-9fhf-v7jp in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-hj8m-9fhf-v7jp and fix it if it is affected.

What it is: GHSA-hj8m-9fhf-v7jp is a code injection vulnerability in fief-server, published on 23 Jun 2023. Any signed-in user can exploit it over the network, with no action from the victim.
Exploitation: There is no known exploitation of GHSA-hj8m-9fhf-v7jp in the wild and no public exploit code.

Affected packages and fixed versions:
- fief-server (PyPI): affected from 0.19.0; fixed in 0.25.3
- fief-server (PyPI): affected from 0.19.0; fixed in 0.25.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-hj8m-9fhf-v7jp/ (Markdown: https://insights.sbomify.com/GHSA-hj8m-9fhf-v7jp/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-hj8m-9fhf-v7jp

---
From sbomify Insights: https://insights.sbomify.com/GHSA-hj8m-9fhf-v7jp/
Summaries are generated and may contain mistakes; the official description above is the record.
