fix: devalue will return private data to the client even if toJSON is implemented.#14
Open
CleverLili wants to merge 4 commits intonuxt-contrib:mainfrom
Open
fix: devalue will return private data to the client even if toJSON is implemented.#14CleverLili wants to merge 4 commits intonuxt-contrib:mainfrom
CleverLili wants to merge 4 commits intonuxt-contrib:mainfrom
Conversation
toJSON is not called in all the appropriate places. This fix will call toJSON and fix the original data structure correctly.
Member
|
cc @pi0 |
…l call toJSON and fix the original data structure correctly.
Author
Member
|
Hi @CleverLili. Sorry for late reply. Sure it seems better idea also aligning with latest main refactors. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
nuxt-contrib/devalue does not handle toJSON properly. There was a fix made earlier and there is an open pull request for another fix. However, that pull request is not correct either.
Here is an example that demonstrates the problems. There are 2 problems:
Here is example: There is a class User that implements toJSON where it excludes certain fields. In this case, it's "internal" that should be excluded. In the example below, you will see that "old code output" shows internal returned to the client.
I tried very hard to not touch the existing code to make sure that nothing breaks. So you'll see that I let the existing code add a property to a map and then I remove it. I also introduced additional walk parameters to handle the update of the parent with the JSONified data. I would like to rewrite the code at some point but I have to deal with duplicates which this code doesn't handle perfectly when dealing with JSONified objects. There is a performance concern with that so I have a hack that I'm happy to discuss with the team once we get past this.
I ran the mocha test and all 61 are passing.
My motivation
Other than this is a security issue as it may return data that isn't meant for the browser. I'm returning my object data and hydrating it on the client with the proper class instance. Without toJSON working properly I cannot return the class name that needs to be instantiated. This fix will solve both the security problem and give programmers a way to hydrate their own data.
In my 30 years of programming, this is the first time I make edits to a Typescript file so let me know if I could do things better.