Ask HN: Tips for safely parsing user provided JSON in browser?
Client-side, browser, react app. A small form that accepts user provided JSON. Would like to make this a safe as possible to parse that JSON. User will most like upload a file, or paste the JSON directly in an input.
A user accessing the form would most likely be logged in to the app, so there might be cookies and/or keys in localStorage etc. Want to protect things like this when possible.
Was thinking of several defenses, including.
1. Hosting the form within an iframe in a different context/domain.
2. Not parsing the JSON in the browser, but sending off to a serverless/cloud function api that has no env/secrets/db connections etc to potentially access.
3. Checking string input with regex and other typical tools before parsing/using.
The JSON, once parsed and passes validation would be used to generate some other objects/data that would be later stored in a database.
Thanks in advance.