Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: obfuscation of an array element can lead to undefined error #312

Merged
merged 2 commits into from
Aug 2, 2024

Conversation

phanshiyu
Copy link
Contributor

@phanshiyu phanshiyu commented Aug 2, 2024

why

In normal circumstances, we should expect that there will be no leaf node in a document that will be undefined, since in JSON land, which is the type that we will always serialise, does not have such a primitive. This is the reason why we only handle known JSON primitive types in traverseAndFlatten, and throw otherwise.

The problem comes during obfuscation, when traverseAndFlatten is used to flatten leaf nodes that are to be removed. We do so by using lodash's pick on our document, that in cases where there are arrays involved, array items that are not picked, will be left as an undefined/<empty item>.

pick([1,2,3,4], 3) will result in [undefined, undefined, undefined, 4] which is passed to traverseAndFlatten which then throws because now it encounters an unexpected type.

what

  1. Added a flag on traverseAndFlatten to remove undefined values instead of throwing, it defaults to false
  2. Switch flag to true in obfuscation

@phanshiyu phanshiyu merged commit 51d910e into beta Aug 2, 2024
6 checks passed
@phanshiyu phanshiyu deleted the fix/v4-obfuscation-in-array-throws-undefined branch August 2, 2024 09:38
Copy link

github-actions bot commented Aug 2, 2024

🎉 This PR is included in version 6.10.0-beta.7 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants