Summary
Laravel Excel contains a path handling vulnerability in its disk copy operation. When application-controlled export paths identify existing writable files, an attacker may overwrite those files with generated export content, potentially enabling remote code execution if an executable file is replaced.
Affected context
The issue may occur in Laravel Excel deployments where application input influences the destination passed to Excel export storage operations such as Excel::store(), $export->store(), or storeExcel(). Risk exists when the destination is resolved against the process working directory and an attacker-controlled path identifies an existing file writable by the application process, allowing the operation to bypass the configured filesystem disk's path confinement.
Exploit preconditions
- Attack surface: Application functionality that accepts or derives an export destination from untrusted input
- Required access: Ability to influence the export path, typically through an exposed application parameter or workflow
- Trigger point: The
Maatwebsite\Excel\Files\Disk::copy()operation while storing generated export content - Target condition: The resolved path must refer to an existing file that the application process can write
- Why exploitation is possible: The destination is resolved using the process working directory rather than the configured filesystem disk, bypassing expected path confinement
Why this happens
The underlying bug is a mismatch between application-level path resolution and filesystem abstraction boundaries. The Disk::copy() method resolves a caller-controlled destination with realpath() and then opens the resulting file for read/write access, instead of consistently routing the destination through the configured disk's confinement and validation rules.
This behavior maps primarily to CWE-22: Improper Limitation of a Pathname to a Restricted Directory, because an external path can escape the intended storage location. It also relates to CWE-73: External Control of File Name or Path, because untrusted input influences the file selected for writing.
Potential impact
- An attacker may overwrite existing writable files with export content.
- Sensitive application files may be corrupted or replaced.
- Non-truncating writes may leave trailing data in files when the replacement content is shorter.
- An executable server-side script may be modified, which could lead to remote code execution.
- Application integrity, availability, or generated-data trust may be affected.
General mitigation guidance
Mitigation generally focuses on treating export destinations as trusted server-side resources rather than accepting arbitrary paths from application input.
Common defensive patterns include:
- Restricting export destinations to approved logical names or fixed directories.
- Resolving and validating paths against an explicitly permitted storage root before writing.
- Preserving filesystem-disk confinement and avoiding direct host-path resolution for user-influenced destinations.
- Rejecting absolute paths, traversal segments, symbolic-link escapes, and unexpected path components.
- Separating export output from executable and configuration directories.
- Applying least-privilege filesystem permissions so the application cannot modify executable code or sensitive files.
- Using dedicated temporary storage and controlled promotion workflows for generated exports.
- Validating output names and enforcing secure-by-default storage policies at application boundaries.
How teams detect issues like this
Detection approaches may include:
- Static analysis rules that flag
realpath(), direct filesystem writes, or file-open operations receiving request-derived paths. - Code review checks for export APIs whose destination arguments originate from users, jobs, or externally controlled configuration.
- Tests verifying that absolute paths, traversal sequences, symbolic links, and paths outside the configured disk are rejected.
- Runtime monitoring for unexpected writes by the application process to source, configuration, upload, or executable directories.
- Policy enforcement requiring export destinations to use allowlisted identifiers rather than raw filesystem paths.
- Automated security review tools can help identify data-flow paths from external input to file-writing operations.

