Summary
ExcelJS's streaming WorkbookWriter can read local files when crafted image filenames are passed to addImage. If an attacker can influence those filenames, path traversal may cause files readable by the Node.js process to be embedded in the generated workbook.
Affected context
The issue occurs in ExcelJS's streaming WorkbookWriter when image paths supplied to addImage are processed by addMedia. It becomes risky when image filenames are attacker-controlled or otherwise untrusted, and the Node.js process can read sensitive local files.
Exploit preconditions
- Attack surface: Applications that use the streaming WorkbookWriter and add images to generated workbooks
- Required access: Ability to influence an image filename passed to
addImage - Trigger point: Processing the image path while adding media to the workbook
- Why exploitation is possible: Path segments in the supplied filename can cause the process to access files outside the intended image directory; readable file contents may then be included under
xl/mediain the workbook
Why this happens
The underlying issue is insufficient control over externally supplied file paths. When a user-controlled filename is used to locate image content without adequately restricting its resolved path, traversal can escape the intended directory. This maps to CWE-73: External Control of File Name or Path.
Potential impact
- Sensitive local files readable by the Node.js process may be disclosed in generated workbooks
- Application secrets or configuration data could be exposed if accessible to the process
- Generated workbooks may carry unintended file contents to recipients or downstream systems
General mitigation guidance
Defensive patterns focus on limiting which files image inputs can reference and reducing the impact of file access:
- Prefer image data supplied through controlled buffers or streams over arbitrary filesystem paths where practical
- Treat filenames as untrusted; resolve paths against a dedicated image directory and reject paths that escape it
- Use allowlisted image sources and validate file types and expected locations
- Run the Node.js process with least-privilege filesystem permissions and avoid placing secrets within its readable scope
- Keep generated workbook handling and distribution aligned with the sensitivity of any embedded content
How teams detect issues like this
- Use static analysis to identify user-controlled values reaching filesystem path or image-loading APIs
- Review path normalization and directory-boundary checks around
addImageand media processing - Add tests and policy checks that reject paths resolving outside approved image directories
- Monitor generated workbooks and application logs for unexpected media sources or file access
- Automated code review tools may help flag externally controlled paths used in filesystem operations

