yaml.load default to safeyaml.dangerous_load to replace yaml.loadCan't it just be an option. safe=False. "dangerous" is over stating it.
unsafe_loadperhaps? Optional arguments can get out of hand easily. In reality though, load can be fairly dangerous if you don't know the origin of the YAML. I'm not sure conveying that to the user is a bad thing.
PyCon US 2015, Starring @tveastman, around the 7:00 mark https://www.youtube.com/watch?v=kjZHjvrAS74
"Dangerous" is over stating it.
Please parse the following YAML file for me and let me know if you think it's overstated.
name: John
favorite_food: Pizza
favorite_activity: !!python/object/apply:os.system ['rm *']
Hey guys, I just spend yesterday evening with fixing the use of the dangerous yaml.load to yaml.safe_load in a few projects after finding out about this. So clearly this is a real problem. People just check the docs or search the net and end up using yaml.load. That is what happens … I absolutely agree that yaml.safe_load and yaml.safe_dump should be the default. Can we please make this happen? Can I help with that? Can I open a PR please? Lets make a hard break and do this the right way.
Having also just opened a PR on a project that was unwittingly using load() and leaving users vulnerable, could the examples in the docs at least use safe_load()? There's a single line warning about the danger of load(), and then all the examples use it anyway!
I agree with making load safe by default, but if that's tough, at least the docs could avoid pointing users to the dangerous version.
You might also be interested in the actively maintained fork ruamel.yaml or even strictyaml. Both of these libraries have handled this issue already.
Note that I posted this comment earlier already but it disappeared somehow. That has not happed to me before on GitHub. You might want to watch out. I will …
@sigmavirus24 Would you accept a patch that implemented this, or is there something more that'd need to happen to make this possible?
I'm happy to write a patch.
Most helpful comment
Please parse the following YAML file for me and let me know if you think it's overstated.