# GHSA-322x-v876-g883: @asymmetric-effort/nogginlessdom's Path Traversal in matchFileSnapshot allows arbitrary file write

> Attackers can write arbitrary files via path traversal in snapshot updates, potentially compromising CI/CD pipelines and executing code.

- **Severity:** Not scored
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Local or same network only
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 2 Jul 2026

## What is GHSA-322x-v876-g883?

GHSA-322x-v876-g883 is a path traversal vulnerability in @asymmetric-effort/nogginlessdom, published on 2 Jul 2026. It can only be exploited from the same machine or local network, with no action from the victim.

### Official description

## Summary

The `matchFileSnapshot` function in `src/assertions/snapshots.ts` accepted a `filePath` parameter with zero validation. When snapshot update mode was active (`UPDATE_SNAPSHOTS=1` or `setUpdateMode('all')`), an attacker who controls test input could write arbitrary content to any filesystem path the process has write access to, including creating intermediate directories.

## Affected Code

**File:** `src/assertions/snapshots.ts`, lines 732-769

```typescript
export function matchFileSnapshot(actual: unknown, filePath: string): void {
  const serialized = serialize(actual);
  const mode = resolveUpdateMode();
  const fileExists = fs.existsSync(filePath);

  if (!fileExists) {
    if (mode === 'all' || mode === 'new') {
      const dir = path.dirname(filePath);
      if (!fs.existsSync(dir)) {
        fs.mkdirSync(dir, { recursive: true });
      }
      fs.writeFileSync(filePath, serialized, 'utf-8');
```

The `filePath` flows from `expect(value).toMatchFileSnapshot(filePath)` at `index.ts:1033-1035` with no sanitization, no check that the path is within an expected directory, and no symlink resolution.

## Proof of Concept

```typescript
import { expect, setUpdateMode } from '@asymmetric-effort/nogginlessdom';

setUpdateMode('all');

// Writes arbitrary content to any writable path
expect('malicious content').toMatchFileSnapshot('/tmp/exploit/payload.txt');

// Path traversal via relative components
expect('data').toMatchFileSnapshot('../../../tmp/evil.txt');

// In CI environments, could overwrite CI config
expect('injected step').toMatchFileSnapshot('/home/runner/.github/workflows/backdoor.yml');
```

## Impact

In CI/CD environments where test files may come from untrusted pull requests, this allows writing to any writable filesystem location with directory creation. An attacker could overwrite configuration files, inject code into build artifacts, or modify CI pipeline definitions.

## Fix

Fixed in commit https://github.com/asymmetric-effort/NogginLessDom/commit/785e6ac6e124d1a89b3ccf40bbd75fc8e4cb215d on `main`. The `matchFileSnapshot` function now validates that the resolved file path is within the project root directory (defaults to `process.cwd()`, configurable via optional `projectRoot` parameter). Paths that resolve outside the project directory are rejected with a descriptive error.

```typescript
export function matchFileSnapshot(
  actual: unknown,
  filePath: string,
  projectRoot?: string,
): void {
  const root = projectRoot ?? process.cwd();
  const resolved = path.resolve(root, filePath);
  if (!resolved.startsWith(root + path.sep) && resolved !== root) {
    throw new Error(
      `File snapshot path must be within the project directory: ${filePath}`,
    );
  }
  // ... all subsequent file I/O uses `resolved` instead of `filePath`
}
```

## Which versions are affected by GHSA-322x-v876-g883?

2 open source packages ship an affected version, including @asymmetric-effort/nogginlessdom.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `@asymmetric-effort/nogginlessdom` | npm | All versions | 0.0.22 |
| `@asymmetric-effort/nogginlessdom` | npm | All versions | 0.0.22 |

## How do I fix GHSA-322x-v876-g883?

Upgrade @asymmetric-effort/nogginlessdom to 0.0.22 or later.

## Is GHSA-322x-v876-g883 being exploited?

There is no known exploitation of GHSA-322x-v876-g883 in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-322x-v876-g883 and fix it if it is affected.

What it is: GHSA-322x-v876-g883 is a path traversal vulnerability in @asymmetric-effort/nogginlessdom, published on 2 Jul 2026. It can only be exploited from the same machine or local network, with no action from the victim.
Exploitation: There is no known exploitation of GHSA-322x-v876-g883 in the wild and no public exploit code.

Affected packages and fixed versions:
- @asymmetric-effort/nogginlessdom (npm): affected all versions; fixed in 0.0.22
- @asymmetric-effort/nogginlessdom (npm): affected all versions; fixed in 0.0.22

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-322x-v876-g883/ (Markdown: https://insights.sbomify.com/GHSA-322x-v876-g883/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-322x-v876-g883

---
From sbomify Insights: https://insights.sbomify.com/GHSA-322x-v876-g883/
Summaries are generated and may contain mistakes; the official description above is the record.
