Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7833913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:58:05+00:00 2026-06-02T12:58:05+00:00

I am learning JQuery with a MVC3 book. I find that Json data is

  • 0

I am learning JQuery with a MVC3 book. I find that Json data is really easy to use, but it may not be safe.

Consider the scenario, say, I got a CRM with senstive customer infomation. Ajax returns Json array as search results. The search textbox ajax autocomplete also return Json array of senstive keywords from database. etc…They all use GET method.

However, it is said that GET method has vulnerabilities when passing around Json array data:

http://haacked.com/archive/2009/06/25/json-hijacking.aspx

http://haacked.com/archive/2008/11/20/anatomy-of-a-subtle-json-vulnerability.aspx

How do you JQuery experts out there go about fixing this issue? Please help.

— EDIT: —

@Gren. Awesome. Thank you. Based on your tips, here is what I figured out.

  1. The normal autocomplete returning json array
  2. and a mod one with a json object wrapping the array

Here is the code, assuming we got a global List named txtlst in the controller.cs…

    // normal one
    public JsonResult AutoCompleteHelper1(string term) {
        //if (!Request.IsAjaxRequest()) return null;
        var lst = txtlst.Where(s => s.StartsWith(term)).ToList();
        var res = lst.Select(x => new { value = x }).ToList();
        return Json(res, JsonRequestBehavior.AllowGet);
    }
    //mod one
    public JsonResult AutoCompleteHelper2(string term) {
        //if (!Request.IsAjaxRequest()) return null;
        var lst = txtlst.Where(s => s.StartsWith(term)).ToList();
        var res = lst.Select(x => new { value = x }).ToList();
        return Json(new { wrapper= res, name="wrapper" }, JsonRequestBehavior.AllowGet);
    }
}

and then in the .cshtml file…

<p>Auto Complete Example</p>
<input type="text" name="q" id="MyInput1" data-autocomplete-source="@Url.Action("AutoCompleteHelper1", "Home")"/>
<input type="text" name="q" id="MyInput2" data-autocomplete-source="@Url.Action("AutoCompleteHelper2", "Home")" />

and then in the .js file…

$(document).ready(function () {

    // normal autocomplete
    $("#MyInput1").autocomplete({ source: $("#MyInput1").attr("data-autocomplete-source") });

    // mod autocomplete with a wrap
    $("#MyInput2").autocomplete({
        source: function (req, add) {
            $.getJSON($("#MyInput2").attr("data-autocomplete-source"), req, function (data) {
                var suggestions = [];
                $.each(data.wrapper, function (i, o) {
                    suggestions.push(o.value);
                });
                add(suggestions);
            });
        }
    });
});

— EDIT 2: —

Please ignore those comments that are telling me to use POST. They
are not reading the blog links or do not understand the issue.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T12:58:07+00:00Added an answer on June 2, 2026 at 12:58 pm

    The other option is to wrap your JSON Arrays within JSON objects. The article and comments in it answered this question.

    Edit:
    From the article:

    The fact that this is a JSON array is important. It turns out that a script that contains a JSON array is a valid JavaScript script and can thus be executed. A script that just contains a JSON object is not a valid JavaScript file.

    If you wrap your json array in an object {“myJsonArray”:[{“name”:”sensitive”},{“name”:”data”}]} the HTML script tag would not be able to execute.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm still learning jQuery, but the more I use jQuery, the more it appears
I am learning jQuery from book Learning jQuery, and found part of code that
I've just started learning Jquery but the examples aren't helping me much... Now whats
I'm learning jQuery and am about to write some pages using intensively that library.
Inspired by chapter 7 of Learning jQuery 1.3 (not found in the third edition),
I am learning JQuery, and I have checked out that JQUery has got a
I am learning JQuery and writing a simple data validation for the two fields
Still learning jquery here and I've tried to setup a set of divs that
I'm learning jQuery but I still don't fully undestand how it works. Suppose I
I am still learning jQuery so this may be a simple one. When a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.