# GHSA-3227-r97m-8j95: Relative Path Traversal in afire serve_static

> An attacker can read arbitrary files outside the web root via path traversal in the afire serve_static extension.

- **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:** 22 Apr 2022

## What is GHSA-3227-r97m-8j95?

GHSA-3227-r97m-8j95 is a path traversal vulnerability in afire, published on 22 Apr 2022. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

### Impact
This vulnerability effects the built-in afire serve_static extension allowing paths containing `//....` to bypass the previous path sanitation and request files in higher directories that should not be accessible.

### Patches
The issue has been fixed in [afire 1.1.0](https://crates.io/crates/afire/1.1.0).
If you can, just update to the newest version of afire.

### Workarounds
If you can't update afire you can simply disallow paths containing `/..` with the following middleware.
Make sure this is the last middleware added to the server so it runs first, stopping the bad requests.
```rust
use afire::prelude::*;

struct PathTraversalFix;

impl Middleware for PathTraversalFix {
    fn pre(&self, req: Request) -> MiddleRequest {
        if req.path.replace("\\", "/").contains("/..") {
            return MiddleRequest::Send(
                Response::new()
                    .status(400)
                    .text("Paths containing `..` are not allowed"),
            );
        }

        MiddleRequest::Continue
    }
}
```
```rust
let mut server = Server::new(host, port);
PathTraversalFix.attach(&mut server);
```

### References
You can read about the new changes to afire in 1.1.0 [here](https://connorcode.com/writing/afire/update-3)

### For more information
If you have any questions or comments about this advisory you can email me or message me on discord.
[[https://connorcode.com/contact](https://connorcode.com/contact)]

## Which versions are affected by GHSA-3227-r97m-8j95?

2 open source packages ship an affected version, including afire.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `afire` | crates.io | From 0.2.1 | 1.1.0 |
| `afire` | crates.io | From 0.2.1 | 1.1.0 |

## How do I fix GHSA-3227-r97m-8j95?

Upgrade afire to 1.1.0 or later.

## Is GHSA-3227-r97m-8j95 being exploited?

There is no known exploitation of GHSA-3227-r97m-8j95 in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-3227-r97m-8j95 and fix it if it is affected.

What it is: GHSA-3227-r97m-8j95 is a path traversal vulnerability in afire, published on 22 Apr 2022. 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-3227-r97m-8j95 in the wild and no public exploit code.

Affected packages and fixed versions:
- afire (crates.io): affected from 0.2.1; fixed in 1.1.0
- afire (crates.io): affected from 0.2.1; fixed in 1.1.0

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-3227-r97m-8j95/ (Markdown: https://insights.sbomify.com/GHSA-3227-r97m-8j95/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-3227-r97m-8j95

---
From sbomify Insights: https://insights.sbomify.com/GHSA-3227-r97m-8j95/
Summaries are generated and may contain mistakes; the official description above is the record.
