I’m reading about this ajax response that describes ways to prevent Javascript based exploits.
-
Does it make sense to apply this technique to WCF-based services that return JSON?
-
How would this be implemented server side?
-
How would the client consume it?
There’s one way WebScriptEnablingBehavior — the behavior of choice if you want a WCF service that works with ASP .NET AJAX — deals with this. By default, its response mode is “WrappedResponse”. If you watch this in action using Fiddler, it means that every response from the service — even a simple number — will wrapped in {d:} wrapper as follows:
On the other hand, WebHttpBehavior is XML out-of-the-box, but if you switch it to JSON, you can choose between WrappedResponse and BareResponse. WrappedResponse is similar to WebScriptEnablingBehavior (if I remember correctly), but BareResponse would be unsecure JSON transmitted back as a direct return value.