
RCE (Remote Code Execution) is a vulnerability that allows an attacker to execute arbitrary code remotely within a system or application, and is classified as CWE-94: Improper Control of Generation of Code ('Code Injection').
PyTorch Lightning is a library that helps easily manage deep learning model training based on PyTorch, and DeepDiff is a library that analyzes differences by comparing two Python objects.
CVE-2024-5452 is a vulnerability that causes RCE during deserialization through weak header validation of DeepDiff and delta attribute contamination in the process of utilizing DeepDiff and Lightning in Lightning's AI model weight-related web application features.
Through this, we will examine the code flow that leads to vulnerabilities allowing an attacker to inject arbitrary objects or perform remote code execution (RCE), and explore countermeasures.
In pytorch-lightning, among the DeepDiff endpoints of the web application source, it is possible to attack by contaminating the delta attribute and sending it to /api/v1/delta.
Through examples, we aim to understand how contaminating the delta's dunder attributes induces an object deserialization vulnerability.
The first request consists of: Client attack example, contamination setup -> Weak header validation in Deepdiff's /api/v1/delta -> State storage via contamination setup.
[Figure 1] POC - Endpoint attack
[Figure 2] POC - Vuln Injection / Full contamination setup content
[Figure 3] lightning/api/core/api.py / Weak header validation logic part
[Figure 4] lightning/api/core/app.py / Setup section
[Figure 5] lightning/api/core/app.py / State storage section
In the first request, the header validation of /api/v1/delta in [Figure 3] is bypassed via [Figure 1], then a manipulated contamination setup (delta) [Figure 2] is injected, and the setup is saved through [Figure 4] and [Figure 5]. Now let's look at how these manipulated delta settings work in the second request.
[Figure 6] lightning/api/core/app.py / Initial path flow
[Figure 6] shows the flow of the second request after delta is set: run_once() -> maybe_apply_change() -> _collect_deltas_from_ui_and_work_queues()
[Figure 7] isinstance contamination case
[Figure 7] In _collect_deltas_from_ui_and_work_queues(), the isinstance check is bypassed using contaminated settings (isinstance(delta, _DeltaRequest) == False), causing execution to go to else.
[Figure 8] isinstance contamination case 1
[Figure 8] For better understanding, the results of isinstance(delta, _DeltaRequest), delta, and _DeltaRequest(type) are shown. The first request is a setup request for manipulation, so it is normal; the next request bypasses the condition because _DeltaRequest type is contaminated to str. Next, let's look at an example of the next target, _process_requests.
[Figure 9] isinstance contamination case 2
As seen in [Figure 9], with the same content as above, _process_requests bypasses the isinstance(request, _APIRequest) check using contaminated settings from the client POC code on the right. This contamination is a case where isinstance call on an OrderSet instance for str returns true. We have seen two forms of isinstance contamination so far; afterward, the settings are crafted to allow accessing attributes through contamination.
[Figure 10] isinstance contamination case 3
After bypassing isinstance in [Figure 10] and setting up functions, set "_INTERNAL_STATE_VARS: () to empty" in [Figure 10], making it impossible to verify internal state in [Figure 11].
[Figure 11_1] _INTERNAL_STATE_VARS check function in /lightning/app/core/flow.py
[Figure 11_2] __setattr__ in /lightning/app/core/flow.py
With [Figure 11] as the last step, the overall contamination and setup are complete.
[Figure 12] RCE Command
[Figure 13] RCE Response
Finally, in [Figure 13], exec with root privileges is called to execute the command in [Figure 12], concluding the attack.
So far, we have examined the flow of RCE vulnerability through object deserialization (CVE-2024-5452) in the Lightning environment. Since this is an attack method that compromises the server itself, countermeasures are important. To this end, we propose updating to the latest version.


We have examined the vulnerability that causes RCE by contaminating Dunder attributes through Lightning and Deepdiff. This vulnerability occurred first due to weak header validation, followed by weak delta attribute checking leading to object deserialization.
(poc) https://security.snyk.io/vuln/SNYK-PYTHON-PYTORCHLIGHTNING-7218866
(nist) https://nvd.nist.gov/vuln/detail/CVE-2024-5452