Fix location property for taint operations (fixes #321) #343
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.
In this pull request, we propose a solution for the empty taint location issue involving
XMLHttpRequest.response, or better, string literals in dynamically evaluated tainted scripts. Moreover, we fix empty taint locations forfetch.text()andfetch.json()taint operations, including those inJSON.parsetaint operations. Hence, this pull request fixes #321.First, we add nlohmann/json (taint/json.hpp), a popular and maintained library for JSON parsing and serialization. We decided to add it because Firefox internals only provide JSONWriter, not JSONReader, and the JSON features provided by the JS engine require a JSContext*. Update: we discovered that it is possible to instantiate an ad-hoc JSContext* for JSON parsing and serialization, however we maintained the implementation from #338.
Then, in Taint.h we declare the functions
ParseStringTaintandSerializeStringTaintto parse and serialize, respectively, the whole StringTaint data structure as a simplified JSON string. Their implementation in Taint.cpp is based on nlohmann/json.Finally, in Taint.h we replace the functions
ParseTaintwithParseStringTaintForE2EandserializeStringtaintwithSerializeStringTaintForE2Efor the end-to-end tainting. We rewrite the functions using nlohmann/json and thus discarding the custom JSON parser, while preserving the expected behavior of these functions.To fix empty taint locations for
fetch.text()andfetch.json()taint operations, we add an additional attribute to the JSContext struct, that we callfallbackTaintLocation. On TaintLocationFromContext, if it is not possible to create the TaintLocation from the given context, we get it from the fallbackTaintLocation. In this pull request, fallbackTaintLocation is set in the main thread, before BodyConsumer created by fetch logic is executed in another thread.Other
TaintOperation::sourceandTaintOperation::native.Differences from #338
fetch.text()andfetch.json()taint operations.