Summary
Vikunja's backup restore functionality trusts file paths embedded in ZIP archives and uses them directly when writing files to disk.
A malicious archive can escape the intended restore directory to overwrite arbitrary files on the host, and specially crafted "minimalist" archives can trigger an unhandled panic after the database has already been wiped, causing a crash and permanent data loss.
Affected context
This vulnerability occurs in Vikunja instances where administrators use the built-in backup restoration feature that accepts ZIP archives.
The restoreConfig function assumes ZIP entries are well-formed and confined to the expected directory structure, and it directly uses the zip.File.Name value when opening files on the host filesystem.
The code also assumes that certain slices derived from archive contents always have a minimum length, without validating these assumptions before indexing.
In environments where restore operations are performed on production systems, this behavior can expose the host filesystem and jeopardize data integrity if a crafted backup is restored.
Exploit preconditions
- Attack surface: Vikunja backup/restore interface or any API/CLI path that accepts ZIP archives for configuration or data restoration.
- Required access: Ability to supply a ZIP archive to the restoreConfig logic (e.g., authenticated admin, compromised admin account, or untrusted backup source).
- Trigger point (path traversal): Restoration of a ZIP file containing entries with crafted path components (such as parent directory segments) that escape the intended restore directory.
- Trigger point (panic/crash): Restoration of a "minimal" or malformed ZIP that breaks the assumed directory structure, leading to out-of-bounds slice access.
- Why exploitation is possible: The application:
- Trusts the
Namefield inzip.Fileand passes it directly toos.OpenFilewithout normalization, path cleaning, or confinement checks. - Does not enforce that extracted paths remain under a designated base directory.
- Indexes into slices derived from archive paths (e.g., using
len(ms)-2) without first confirming the slice length, allowing runtime panics when assumptions do not hold.
Why this happens
The primary issue is a path traversal flaw (CWE-22) in the archive extraction logic: the restoreConfig function interprets path strings from ZIP metadata as trusted, and uses them verbatim when creating or opening files on the filesystem.
Without canonicalization and validation of these paths against a known base directory, an attacker can embed directory traversal sequences or absolute paths in ZIP entry names to write outside the intended extraction root.
The secondary issue is an unhandled runtime panic (CWE-248) caused by unchecked assumptions about archive structure.
The restoration logic splits or processes archive-derived data into slices and then accesses indices relative to len(ms) (such as len(ms)-2) without verifying that the slice is long enough.
When a "minimalist" or malformed archive is provided, these assumptions fail, leading to an out-of-bounds index and a panic, which is not recovered from and therefore crashes the process.
Both problems stem from overly trusting external input (archive metadata and structure) and encoding those assumptions directly into filesystem operations and indexing logic without defensive validation or error handling.
Potential impact
- Arbitrary file overwrite on the host system within the permissions of the Vikunja process.
- Modification of application configuration files, potentially leading to further compromise or misconfiguration.
- Overwriting of critical system or service files, which may cause denial of service or facilitate privilege escalation in some environments.
- Permanent loss of application data if a restore operation wipes the database and then crashes before completing recovery.
- Application downtime due to runtime panics during restore, requiring manual intervention to recover.
General mitigation guidance
Effective mitigation focuses on restricting filesystem writes during archive extraction and hardening assumptions about archive structure:
- Constrain extraction paths:
- Normalize and clean all paths from ZIP entries before use (e.g., via canonicalization functions).
- Ensure the final extraction path is always joined with and confined to a predefined base directory, rejecting any entry that resolves outside it.
- Ignore or fail the restore if a path is absolute, contains parent directory segments that escape the base, or attempts to target special filesystem locations.
- Validate archive structure defensively:
- Treat all metadata from the archive (file names, directory hierarchies) as untrusted and verify that required components are present before proceeding.
- Perform length and bounds checks on slices derived from path splits or metadata before indexing into them.
- Fail restore operations gracefully (with clear errors) when the archive does not conform to the expected structure rather than assuming it does.
- Harden error handling and recovery:
- Replace crash-prone patterns with explicit error checks and controlled error returns; avoid panics in routine restore paths.
- Consider transactional or staged restore designs where destructive operations (e.g., wiping databases) are performed last, after the input archive has been fully validated.
- Run the restore process with the least privileges necessary and consider isolating it from the rest of the system (e.g., dedicated user, restricted directories).
- Trust boundaries and operational practices:
- Treat backup archives as untrusted input unless their origin and integrity are strongly validated.
- Encourage operators to store and handle backup files securely, limiting opportunities for tampering.
How teams detect issues like this
To detect and prevent similar vulnerabilities, organizations can combine static checks, code review practices, and runtime monitoring:
- Static analysis and linting:
- Configure static analysis rules to flag:
- Direct usage of archive entry names (
zip.File.Name, or equivalents) passed to filesystem APIs without prior normalization and validation. - Calls to
os.OpenFile,os.Create, or similar functions using user-controlled or external-input-derived paths. - Slice indexing patterns that use
len(s)-Nwithout preceding length checks or early returns. - Integrate these rules into CI to fail builds when unsafe patterns are found.
- Code review signals:
- During review, pay close attention to:
- Archive extraction loops that use user-supplied names or paths.
- Logic that assumes a fixed directory structure or a minimum number of path segments.
- Any use of panic or unrecovered runtime errors in non-critical, user-triggerable paths such as backup/restore.
- Require reviewers to explicitly verify that path confinement and bounds checks are present in file-handling code.
- Runtime and operational monitoring:
- Monitor logs for failed restore attempts, unexpected panics, or error messages related to path handling or index out of range.
- Implement structured logging around backup and restore operations, including information on rejected paths or validation failures.
- Use host-based monitoring to detect unusual file write patterns from the Vikunja process, such as writes outside expected application directories.
- Automated review tools:
- Employ SAST tools and security-focused linters that understand Go idioms and can detect path traversal and unchecked indexing.
- Periodically scan the codebase and dependencies for similar patterns in other components that handle archives or migration data.

