Skip to content

Fix location property for taint operations (fixes #321)#343

Merged
leeN merged 9 commits into
SAP:mainfrom
eleumasc:fix-321
Jan 23, 2026
Merged

Fix location property for taint operations (fixes #321)#343
leeN merged 9 commits into
SAP:mainfrom
eleumasc:fix-321

Conversation

@eleumasc

Copy link
Copy Markdown
Contributor

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 for fetch.text() and fetch.json() taint operations, including those in JSON.parse taint 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 ParseStringTaint and SerializeStringTaint to 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 ParseTaint with ParseStringTaintForE2E and serializeStringtaint with SerializeStringTaintForE2E for 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() and fetch.json() taint operations, we add an additional attribute to the JSContext struct, that we call fallbackTaintLocation. 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

Differences from #338

  • Reverted format String.cpp.
  • Changed naming of DumpStringTaintAsJSON, LoadStringTaintFromJSON, etc. to avoid ambiguities.
  • Fixed empty taint locations for fetch.text() and fetch.json() taint operations.

@leeN

leeN commented Jan 19, 2026

Copy link
Copy Markdown
Collaborator

Hi, sorry for the long delay.

There seem to be some merge conflicts. Do you have any capacity to look into those? Based on the mochitests, the PR looks good to me, and we'd prefer to merge it before we have to do the great switchover to the original Mozilla upstream.

@eleumasc

Copy link
Copy Markdown
Contributor Author

Probably that's just a matter of rebasing and solving conflicts, I can do it within the day. Also, I would like to spend a bit of time to understand how to use the built-in JSON library in place of the third-party one.

@leeN

leeN commented Jan 19, 2026

Copy link
Copy Markdown
Collaborator

Hi, I just had a call with @tmbrbr, and our conclusion was that if you can resolve the merge issues by Friday, we're happy to merge this PR

Afterwards, we will do a big rebase, as Firefox switched from Mercurial to Git and every Git commit hash changed, i.e., existing PRs require work on every end, we'd ask you to split out the native JSON stuff until we do the big rebase, or get it done by Friday, if it's easy.

We're okay with including the external JSON library until it's clear whether we need it, but every open PR is work on our (or your) end after the rebase, so just fixing the merge issues and we can merge it before Friday sounds best to us. This gives you time to mess around with native JSON and does not put much time pressure on you.

@eleumasc

eleumasc commented Jan 22, 2026

Copy link
Copy Markdown
Contributor Author

In the end I've managed to rebase with the latest main, now this PR should merge and Foxhound build. Instead, I haven't managed to replace the external JSON library with the built-in one, I can retry it after the big rebase. Remarkably, I've noticed that nlohmann/json was already included somewhere in the Firefox source (see https://github.com/SAP/project-foxhound/blob/main/intl/icu/source/tools/toolutil/json-json.hpp). My only concern is about the JS Rooting Hazards Analysis failing due to a missing model.

@leeN leeN left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@leeN leeN merged commit fbfa4cf into SAP:main Jan 23, 2026
6 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Empty location property for network taint operations

2 participants