Skip to main content
CriticalCodeOWASP A08:2021CWE-502

How to fix: yaml.load without safe loader

yaml.load(input) uses the unsafe Loader by default and instantiates arbitrary Python objects via !!python/object tags. yaml.safe_load rejects those tags.

Why it matters

Crafted YAML can execute arbitrary Python during parsing, leading to full RCE on the host.

The `code-deser-yaml-load` check verifies that the server does not expose the `deser-yaml-load` weakness in the code category. The detection runs against the response headers, body, or auxiliary probes (DNS, TLS, async fetch) as appropriate.

How to fix it

  1. 1Use yaml.safe_load(input) for any untrusted YAML.
  2. 2Or pin a safe Loader: yaml.load(input, Loader=yaml.SafeLoader).
  3. 3Validate the YAML schema with a strict parser (e.g. pydantic) before deserialization.

Code examples

Use YAML safeLoad / yaml.parse instead of load

TypeScript
import yaml from "js-yaml";

// BAD: yaml.load can execute arbitrary JS (!!js/function tag)
const data = yaml.load(userYaml);

// GOOD: safeLoad rejects dangerous YAML types
const data = yaml.safeLoad(userYaml);
// Or with the newer js-yaml API:
const data = yaml.load(userYaml, { schema: yaml.JSON_SCHEMA }); // JSON-only types

References

Detected automatically by VulnRadar. The check id is code-deser-yaml-load, stable across every scan so you can filter or diff on it.

See every code check

Questions

How severe is yaml.load without safe loader?
VulnRadar rates this critical severity in the code category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
Does VulnRadar check for this automatically?
Yes. It runs as part of every scan under the check id code-deser-yaml-load, which stays the same between runs so you can filter, diff, or gate CI on it.
Which standards does yaml.load without safe loader map to?
It maps to CWE-502. In the OWASP Top 10 it falls under A08:2021.

Missing a check?

The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.

Propose a checkHow a check is built

Scan your own site for yaml.load without safe loader

VulnRadar runs this check and hundreds more against a URL in seconds. No agent to install, just paste a URL.

Or scan this site as a demoRead the docs

How to fix: yaml.load without safe loader | VulnRadar