I'm bashing around a few ideas for storing usage data (similar to google analytics) for some Javascript products that we are working on.
Unfortunately as yet we don't quite know 100% what data we want to store and only have a basic idea of the metrics we want to glean from it.
My thinking is that basically we want to store a set of key-value pairs grouped by a unique instance_id (there may well be flaws in this logic:)). With that in mind I knocked up a (very) quick prototype in monkrb, the grand total of which is below:
get "/store" do
key = params[:key]
value = params[:value]
instance_id = params[:instance_id]
Ohm.redis.hset instance_id, key, value
end
While this should work, I'm somewhat worried that an inquiring mind could easily pollute our data with random sets and key-values, doubled by the fact that this is all going to be called in Javascript so anything we do to secure or encrypt it is going to be pretty transparent to anyone who cares to view source.
A lot of it should be easily filtered out, as come reporting time we'll have an idea which keys we are interested in (and know which ones we've created) so we can just junk any sets that contain keys which we know nothing about (though again there's the risk that additional keys have been added to an otherwise valid set..)
Following down this path here are my questions:
- What steps can I take to make it as hard as possible to add completely false data? (handshaking, obfuscation, signing, etc)
- What can I do to try and detect any junk data? (bonus for a rough idea of how to implement too)
- What sort of checks should I have in place to stop an existing instance_id being guessed and messed about with? (so any historical data can't get polluted)
It should be noticed that this is mostly academic at the present stage, as I know 6 lines of ruby does not an application make, I'm just interested in the scenario and would like to hear others approaches and thoughts on where one could go with this.