You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
chris of the clan edited this page Jun 2, 2015
·
1 revision
How to secure the KV store for users
Say we want to make sure the client application can't write to a KV, which should only be writable from batches.
mod.isSafe() will help us know if the hook was called because the client wants to write to the key, or because amother batch or
hook wants to write to it.
server side code
function before-gamervfs-write(params, customData, mod) {
"use strict;"
// don't edit above this line // must be on line 3
var key = params.key; // the key we're trying to write to
if (!mod.isSafe() && key == "myPrivateKey") {
// mod.isSafe() == false means 'called from client'
throw new Error('myPrivateKey cannot we written from client');
// thowing the error will stop the write before it happens, because we chose the before-gamervfs-write hook
}
}