Remove Loader alias to UnsafeLoader and enhance security #851
+60
−52
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background
The Lazarus Group, a North Korean state-sponsored hacking group, has been actively exploiting PyYAML's unsafe loader functionality to conduct advanced persistent threat (APT) attacks. Most recently, they were responsible for the $1.5 billion Bybit cryptocurrency exchange hack in February 2025 - the largest heist in history.
The attackers specifically used PyYAML's
yaml.Loader
vulnerability to execute remote code execution (RCE) attacks by tricking exchange employees into running seemingly legitimate Python code that contained:Changes in this PR
This PR significantly enhances PyYAML's security posture through several critical changes:
Loader
alias toUnsafeLoader
: This prevents accidental use of the unsafe loaderUnsafeLoader
,CUnsafeLoader
, orunsafe_load()
functions are usedUnsafeLoader
toSafeLoader
in various core functionsSecurity Impact
These changes provide multiple layers of protection:
Loader
alias prevents the specific attack pattern used in the Bybit hackBackward Compatibility
While this PR makes security-focused breaking changes, the actual impact should be minimal:
yaml.SafeLoader
oryaml.safe_load()
will continue to work without changesyaml.FullLoader
oryaml.full_load()
will continue to work without changesyaml.UnsafeLoader
oryaml.unsafe_load()
will continue to work but will now generate runtime warningsyaml.Loader
alias will need to be updated to either useyaml.UnsafeLoader
(not recommended) or preferably migrate toyaml.SafeLoader
oryaml.FullLoader
References
This PR helps eliminate a serious security vulnerability that has been exploited by nation-state actors to steal billions in cryptocurrency assets. By removing the unsafe loader alias and promoting safer defaults, we can help prevent future attacks.