Safely embed serialized JSON in a page as temporary global data. HTML tags are sanitized.
var JSONGlobals = require("safe-json-globals")
function (req, res) {
getUser(req, res, function (userRecord) {
var globalsMarkup = JSONGlobals({
user: userRecord,
potentialMaliciousContent: "</script><script>alert('hack')"
})
var html = "" // whatever html
html += globalsMarkup
res.end(html)
})
}
var JSONGlobals = require("safe-json-globals/get")
var user = JSONGlobals("user")
npm install safe-json-globals
- Raynos
- lxe