Dan posted on December 7, 2009 22:33

If you've been trying out Asp.Net MVC 2 you might come across this error:

This request has been blocked because sensitive information could be disclosed to third party web sites when this is used in a GET request.

But it worked in MVC 1.0!  There is a security vulnerability using JQuery AJAX GET requests (JSON Hijacking) and in MVC 2 get requests  are blocked by default.  You can get around the problem and leave the security problem by adding JsonRequestBehavior.AllowGet when you return the JSON result:

   1: public JsonResult FindByCoordinates(string latitude, string longitude)
   2: {
   3:     IList<Object> records = new List<Object>
   4:         {
   5:             new 
   6:                 {
   7:                     Lat = "0.1122",
   8:                     Long = "51.12212"
   9:                 }
  10:         };
  11:  
  12:     return new JsonResult { Data = (records), JsonRequestBehavior = JsonRequestBehavior.AllowGet };
  13: }

The better approach is to avoid the possibility of JSON hijacking and use JQuery post instead:

   1: $.ajax({
   2:     type: "POST",
   3:     contentType: "application/json; charset=utf-8",
   4:     url: "/Home/FindEscortsByCoordinates",
   5: ....
   6: ....

Hope this helps anyone that comes across this.


Posted in: ASP.NET MVC  Tags: , ,

Comments


December 8. 2009 09:02
trackback
Asp.Net MVC 2 JsonRequestBehavior.AllowGet

You've been kicked (a good thing) - Trackback from DotNetKicks.com

http://www.dotnetkicks.com/aspnet/Asp_Net_MVC_2_JsonRequestBehavior_AllowGethttp://www.dotnetkicks.com/aspnet/Asp_Net_MVC_2_JsonRequestBehavior_AllowGet


December 8. 2009 12:00
trackback
Asp.Net MVC 2 JsonRequestBehavior.AllowGet - Dan Gibbons

Thank you for submitting this cool story - Trackback from DotNetShoutout

http://dotnetshoutout.com/AspNet-MVC-2-JsonRequestBehaviorAllowGet-Dan-Gibbonshttp://dotnetshoutout.com/AspNet-MVC-2-JsonRequestBehaviorAllowGet-Dan-Gibbons


December 8. 2009 16:00
pingback
Pingback from topsy.com

Twitter Trackbacks for
        
        Asp.Net MVC 2 JsonRequestBehavior.AllowGet
        [ifunky.net]
        on Topsy.com

http://topsy.com/tb/tinyurl.com/y9fqv88http://topsy.com/tb/tinyurl.com/y9fqv88

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading



Calendar

«  March 2010  »
MoTuWeThFrSaSu
22232425262728
1234567
891011121314
15161718192021
22232425262728
2930311234
View posts in large calendar

Authors

Recent Comments

Banners

Theme Grabber
Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010 Dan Gibbons .Net Developer