Summary
A path traversal issue in PostCSS can cause attacker-controlled source map references in untrusted CSS to resolve to unintended local or absolute .map files. When source maps are enabled and the processed result is exposed, an attacker may disclose embedded sourcesContent from reachable files.
Affected context
The issue occurs in PostCSS deployments that process CSS containing attacker-controlled sourceMappingURL annotations and allow source map loading. Risk increases when map generation or loading is enabled, the referenced paths can reach files outside the intended source directory, and result.map or equivalent output is returned to an untrusted party.
Exploit preconditions
- Attack surface: CSS processing through the PostCSS API
- Required access: Ability to submit or influence CSS content and receive the resulting source map output
- Trigger point: Source map resolution during CSS parsing or transformation
- Required environment: Source map loading must be enabled, rather than disabled with an appropriate configuration
- Why exploitation is possible: Attacker-controlled source map references can influence path construction, including traversal or absolute path resolution, allowing reachable
.mapfiles to be read
Why this happens
The vulnerable behavior passes an attacker-controlled sourceMappingURL annotation into path-joining logic and permits resolved paths that are traversed or absolute. This fails to enforce that source map references remain within an intended trusted directory.
The behavior maps to CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal'). The insecure pattern is treating a path derived from untrusted document content as a trusted local file reference without canonicalization, containment checks, or an equivalent restricted resolver.
Potential impact
- Source map contents may be disclosed to an attacker
- Embedded
sourcesContentmay reveal application source code or sensitive configuration - Internal filesystem structure may be exposed through file resolution behavior
- Downstream systems may unintentionally publish sensitive source data in generated artifacts
General mitigation guidance
Mitigation generally focuses on reducing trust in source map references and restricting filesystem access during CSS processing.
Common defensive patterns include:
- Disable source map loading when it is not required for the processing workflow
- Resolve source map paths only within an explicitly permitted directory
- Canonicalize candidate paths and enforce directory containment before reading files
- Reject absolute paths, traversal segments, and unexpected path forms from document annotations
- Avoid exposing generated source maps or embedded
sourcesContentto untrusted consumers - Run processing with least-privilege filesystem permissions and minimal readable data
- Use isolated temporary workspaces for files that must be processed
How teams detect issues like this
Organizations can detect this class of issue through:
- Static analysis for tainted
sourceMappingURLvalues flowing into filesystem path APIs - Code review checks for path joins that lack canonicalization and containment validation
- Tests covering traversal segments, absolute paths, symlinked locations, and unexpected URL-like values
- Runtime monitoring for CSS processing components reading
.mapfiles outside approved directories - Policy enforcement requiring source map loading to be explicitly enabled and restricted
- Automated code review or dependency analysis tools that flag path traversal and unsafe file access patterns

