Summary
Oh My Posh can interpret attacker-controlled directory names as Go template expressions when rendering its path segment. If a user enters a directory whose name contains such an expression, arbitrary operating system commands may execute with the privileges of the current user when the prompt renders in that directory or a descendant.
Affected context
The vulnerability occurs in Oh My Posh prompt rendering when the path segment passes raw directory names to a template renderer whose function map exposes command execution functionality. It becomes risky when an attacker can create or influence a directory name that the affected user's shell prompt later displays, including through shared workspaces, extracted archives, repositories, or other untrusted filesystem content.
Exploit preconditions
- Attack surface: Local filesystem content processed by the shell prompt
- Required access: Ability to create, rename, or otherwise influence a directory visible to the affected user
- Trigger point: Prompt rendering while the user is inside the crafted directory or one of its descendants
- Why exploitation is possible: Raw path data is evaluated as a template rather than treated solely as display text, and the template environment exposes command-execution functionality
Why this happens
The underlying bug is a failure to preserve the distinction between data and executable template syntax. The path segment supplies attacker-controlled folder names directly to a template renderer, allowing embedded expressions to be evaluated with access to functions that can invoke operating system commands. This behavior maps to CWE-94: Improper Control of Generation of Code, with CWE-1336: Improper Neutralization of Special Elements Used in a Template Engine describing the template-specific injection mechanism.
Potential impact
- Arbitrary operating system commands may execute as the current user
- User credentials, tokens, or local files could be exposed
- Shell configuration or development environments could be modified
- Malicious commands could affect repositories, build artifacts, or other accessible data
- The impact could extend to connected services when the user has elevated permissions
General mitigation guidance
Mitigation centers on treating directory names and other path-derived values strictly as untrusted display data.
Common defensive patterns include:
- Escaping or quoting dynamic values before placing them into templates
- Rendering untrusted path components as data rather than re-parsing them as template source
- Restricting template function maps so display templates cannot invoke operating system commands
- Separating command-capable functionality from user-controlled rendering contexts
- Running prompt tools with normal user privileges and limiting access to sensitive resources
- Applying safer defaults for prompt configurations and reviewing filesystem trust boundaries
How teams detect issues like this
Organizations can look for this vulnerability class through:
- Static analysis that identifies raw filesystem values passed into template rendering APIs
- Code review checks for dynamic strings being treated as template source
- Review of template function maps for command execution, process spawning, or shell access
- Policy enforcement that prohibits command-capable functions in display-only templates
- Tests using metacharacters and template syntax in directory names to verify they remain inert
- Automated security review tools that flag template injection and data-to-code boundary violations

