First of all, this great article explains all sorts of tricks and weirdness in YAML:
Insecure Deserialization
In YAML the ! character can mean a tag, which allows you to execute a function in the host language with a parameter that comes right after (because why not). Many parsers implement this as it is required by the spec, but if attackers have control over the YAML file, even partially, they can use these tags to run arbitrary functions with arbitrary arguments.
A common target for this is a function that executes shell commands, where you can gain Remote Code Execution. The following examples all execute the id command and allow you to execute any arbitrary commands:
from yaml import Loader, loaddeserialized =load(open('data.yml'), Loader=Loader)
Payload
data.yml
!!python/object/apply:os.system- "id"
JavaScript - js-yaml (<4.0)
This popular JavaScript library allows the creation of arbitrary functions like .toString() which can be called accidentally, when using load() instead of safeLoad() in versions below 4:
Vulnerable Code
constyaml=require('js-yaml');constfs=require('fs');constres=yaml.load(fs.readFileSync('data.yml'));console.log(res +"") // Calls .toString() as trigger