-
Notifications
You must be signed in to change notification settings - Fork 534
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
Do not rely on the global JSON objects on a page #290
Comments
We have met this problem here: hypothesis/h#608 |
Oh this is horrible. Thanks for the report, @scharf. |
Prototype has since changed so that they do not export a broken Array.prototype.toJSON anymore. I'm not sure we should really do anything here. It seems we'd have to include our own, private json2.js patched to ignore toJSON methods. That's a lot of nonsense. Thoughts? |
This is a difficult one. We can't possibly predict all the ways in which people could monkeypatch (and break) native APIs on websites, but we could easily detect and fix this one. Options:
4 strikes me as the "right" option, given how rare this problem is, but it obviously has a significantly higher implementation cost than any other option. 3 fixes the problem for everyone, but adds N KiB for everyone. 2 seems like the worst of all worlds... |
@nickstenning but as far as I can see there is nothing wrong with the JSON object on this page. The problem lies with the fact that the delete Array.prototype.toJSON;
JSON.stringify([1,2]);
//=> "[1,2]" This is a lot harder to detect unless you want to try to validate every object type, and update their |
Ugh, javascript -- (╯°□°)╯︵ ┻━┻ You're right, of course, and that does make this basically impossible to fix for the bookmarklet form of Annotator, short of doing |
So we can definitely just warn and I think that's all we should do. |
Sorry for entering so late to this discussion, but I think we have already (sort of) solved this earlier. Our workaround was temporarily remove @edsu has fixed https://github.com/mozilla/jschannel this way, see here and here for the two steps (remove and patch), or here for the combined effect. |
The solution mentioned above fixes the behavior of |
@tilgovi, @nickstenning, should we apply the solution outlined above? |
After talking about it on IRC, I think @csillag is going to implement a configuration hook for serialization and then add the workaround to the bookmarklet code. |
Or possibly as a plugin (which the bookmarklet would use). |
In the interest of simplicity, and given the gnarliness of addressing any issue like this, I'm going to just close this for now. If a page author has sabotaged the |
If you go to a cnn video, open the console and type in
the result is
And not as you expect
"[1,2]"
. In fact it puts any array into strings even if they are nested:This changes the data sent to the server in unexpected ways....
==> do not rely on the global JSON object
The text was updated successfully, but these errors were encountered: