Summary
The @cgauge/yaml npm package can execute attacker-controlled JavaScript when parsing YAML containing its custom !js tag. Applications that parse untrusted YAML may expose the Node.js process to arbitrary code execution, including filesystem, network, environment, and subprocess operations.
Affected context
The vulnerability occurs in applications that use @cgauge/yaml to parse YAML from untrusted or insufficiently trusted sources. Risk is present when the parser recognizes the custom !js tag and invokes its construct callback during document processing, particularly when the parsing process runs with meaningful application or operating-system privileges.
Exploit preconditions
- Attack surface: YAML parsing performed by an application using @cgauge/yaml
- Required access: Ability to supply or modify YAML content that the application will parse
- Trigger point: Processing of a document containing the custom
!jstag - Why exploitation is possible: The tag's construct callback unconditionally evaluates attacker-controlled string values, without a safe-mode alternative or opt-out mechanism
Why this happens
The underlying bug is direct evaluation of untrusted YAML-derived data. The custom !js tag maps attacker-controlled strings to a construct callback that invokes eval(), treating serialized input as executable JavaScript rather than inert data. This behavior maps to CWE-95: Improper Neutralization of Directives in Dynamically Evaluated Code, because untrusted input reaches a dynamic code-evaluation operation without effective restriction.
Potential impact
- Attackers may execute arbitrary JavaScript in the Node.js process
- Attackers could read environment variables and application secrets
- Attackers may read, modify, or delete accessible files
- The process could initiate network connections or execute subprocesses
- Applications could experience data theft, tampering, or service disruption
General mitigation guidance
Mitigation generally centers on ensuring that untrusted YAML is not processed by a parser that evaluates embedded code.
Common defensive patterns include:
- Replacing code-evaluating YAML features with data-only parsing behavior
- Using a parser with safe-by-default semantics and no executable custom tags
- Treating YAML from external users, integrations, or repositories as untrusted
- Validating parsed data against a strict schema and rejecting unexpected tags
- Isolating parsing workloads with least-privilege identities, restricted filesystem access, and limited network permissions
- Avoiding reliance on application-level validation as a substitute for disabling dynamic evaluation
How teams detect issues like this
Detection can include static analysis and dependency review for uses of eval(), dynamic JavaScript evaluation, and YAML custom-tag constructors that process input values. Code review should flag parser callbacks that convert serialized data into executable code, especially when no explicit trust boundary or safe parsing mode exists. Runtime policy can monitor unexpected child-process creation, filesystem access, or outbound network activity from YAML-processing components. Automated security review tools may help identify dynamic evaluation and risky parser integrations.

