Fix Deserialization of user-controlled data on renderLocalView #2888
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.
graphite-web/webapp/graphite/render/views.py
Line 27 in c92e8c0
graphite-web/webapp/graphite/render/views.py
Line 502 in c92e8c0
graphite-web/webapp/graphite/render/views.py
Line 555 in c92e8c0
Deserializing untrusted data using any deserialization framework that allows the construction of arbitrary serializable objects is easily exploitable and in many cases allows an attacker to execute arbitrary code. Even before a deserialized object is returned to the caller of a deserialization method a lot of code may have been executed, including static initializers, constructors, and finalizers. Automatic deserialization of fields means that an attacker may craft a nested combination of objects on which the executed initialization code may have unforeseen effects, such as the execution of arbitrary code.
The safest way to fix this vulnerability is to avoid using Pickle for this endpoint and instead use a safe data serialization format, such as JSON, which does not allow arbitrary code execution on deserialization. Specifically:
request.body
inrenderLocalView
), parsing must be done usingjson.loads
.delegateRendering
) should switch to using JSON serialization (json.dumps
in place ofpickle.dumps
).renderLocalView
should be replaced with JSON deserialization.delegateRendering
(request construction) andrenderLocalView
(request parsing).Only the code snippets provided can be modified. Since the problematic use is in both
webapp/graphite/render/views.py
(logic for reading/parsing, and logic for sending), changes will be applied there only.References
Deserialization of untrusted data
objects Deserialization Cheat Sheet
Talks by Chris Frohoff & Gabriel Lawrence: AppSecCali 2015: Marshalling Pickles - how deserializing objects will ruin your day