Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion server accepting JSON in POST - how to secure/validate?
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Bradley Meck  
View profile  
 More options Jan 19 2012, 3:13 pm
From: Bradley Meck <bradley.m...@gmail.com>
Date: Thu, 19 Jan 2012 12:13:45 -0800 (PST)
Local: Thurs, Jan 19 2012 3:13 pm
Subject: Re: [nodejs] Re: server accepting JSON in POST - how to secure/validate?

JSON.parse will remove functions, but not save you from things such as :
"{hasOwnProperty:null,toString:0,valueOf:"_"}"

JSON.parse(str).hasOwnProperty(...) toString(...) etc. will throw an error

Also a real nightmare starts to show up when you have "{"key":1}" and
"{"key":"1"}" and you naively use an object as a hash.

var cache = {}
function update(str) {
  var updatedObj = JSON.parse(str)
  var objs = [{key:...}] // gotten from some API call
  var isNewObject = objs.every(function(existingObj) {
    existingObj.key !== updatedObj.key
  })
  if (isNewObject) {
    cache[key] = updatedObj
  }
  else {
     cache[key] = mergeAndUpdate(cache[key], updatedObject)
  }

}

In this case "1" !== 1 and so the updated object when attached to the cache
will completely replace instead of updating and merging with the existing
object.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.