During my exploration of the topic of JSON vs XML, I stumbled upon this particular question. One of the arguments in favor of JSON was its ease of conversion in Javascript, specifically using the eval()
function. However, this raised some security concerns in my mind.
This prompted me to delve into the security implications of JSON and I found a blog post discussing the fact that JSON may not be as secure as commonly believed. A key point highlighted was:
Update: A crucial aspect of security is to only have objects at the top level in JSON data. Wrapping arrays, strings, and numbers within an object prevents the JavaScript interpreter from identifying it as a block instead of an object during evaluation. While this is a good security measure, additional steps such as protecting sensitive data with unpredictable URLs are recommended.
Following the suggestion to keep only objects at the top level in JSON is a good starting point for security. Are there any other best practices to follow or pitfalls to avoid in JSON and AJAX security?
The mention of unpredictable URLs in the quoted text raises questions about its implementation, especially in PHP. Coming from a Java background, the concept is clearer, as multiple URLs can be mapped to a single servlet. However, my experience with PHP involves mapping a single URL to a PHP script. How exactly can unpredictable URLs be used to enhance security?