Summary
Kakoune's enabled-by-default autorestore script can process malicious backup files in an unsafe way, allowing arbitrary Kakoune and shell commands to run when a user opens a file. The issue becomes risky when untrusted or attacker-controlled backup files are present in locations examined by the autorestore feature.
Affected context
The vulnerability occurs in Kakoune installations that use the bundled autorestore feature and process backup files during file opening. It requires a malicious backup file to reach a location and naming pattern recognized by the autorestore script; users opening the associated file may then trigger command execution before they have explicitly trusted the file contents.
Exploit preconditions
- Attack surface: Kakoune's bundled autorestore script
- Required access: Ability to place or influence a malicious backup file in a location accessible to the victim
- Trigger point: Opening a file that causes the autorestore feature to inspect the crafted backup
- Why exploitation is possible: Backup-file content is interpreted in a way that can invoke Kakoune commands and shell operations rather than being treated strictly as inert data
Why this happens
The underlying issue is insufficient separation between backup-file data and executable editor or shell commands. The autorestore script processes attacker-controlled content through command-capable Kakoune or shell evaluation paths, allowing embedded control sequences to influence execution. This maps to CWE-74: Improper Neutralization of Special Elements in Output Used by a Downstream Component, because data is not adequately constrained before being interpreted by a command-processing component.
Potential impact
- Arbitrary Kakoune commands may be executed in the victim's editor session
- Shell commands may run with the user's operating-system privileges
- Local files could be read, modified, or deleted
- Credentials or other sensitive data may be exposed
- Malicious commands could modify projects or introduce supply-chain changes
General mitigation guidance
Mitigation generally focuses on preventing backup-file content from reaching command-evaluation paths and reducing trust in files opened by the editor.
Common defensive patterns include:
- Treating backup and recovery files as data-only inputs
- Avoiding shell or editor command evaluation for untrusted file content
- Disabling autorestore behavior when working with untrusted files or repositories
- Restricting file permissions and directory ownership for backup locations
- Running the editor with least privilege and limiting access to sensitive resources
- Applying sandboxing or process isolation where practical
How teams detect issues like this
Organizations can identify similar risks through:
- Static analysis for command evaluation, shell invocation, and interpolation of file-derived values
- Code review checks for scripts that transform backup or configuration content into executable commands
- Tests using adversarial backup files to verify that parsing remains data-only
- Policy enforcement that restricts shell execution from editor plugins and startup scripts
- Monitoring unexpected child processes or shell activity spawned by Kakoune
Automated code review and security scanning tools may help surface unsafe command-construction patterns.

