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 8290139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:42:34+00:00 2026-06-08T12:42:34+00:00

In Backbone, it seems to be encouraged that collection resources return bare arrays .

  • 0

In Backbone, it seems to be encouraged that collection resources return bare arrays. This seems to be driven by the Rails model of doing things, which isn’t a good reason at all to do something. I have a few problems with this:

  1. Often, a ‘collection’ resource also needs context around it. At the very least, I like the convention of including the URI of the resource in the response. Other things, like paging, subtotal (in a shopping cart, for example), etc. mean that collections are rarely “bare”.
  2. Bare Arrays supposedly have security issues. I’ve heard this in a few places, but need some references to confirm it.

On the other hand, I can see how “bare” arrays would make an API more natural:

  1. The format of each object in the collection would tend to be the same as the format when creating/updating an object in that collection.
  2. A ‘collection’ semantically maps well to the idea of, well, a collection of items.

Disclaimer: the premise here may be totally flawed. I realize that REST is about much, much more than HTTP Verbs and JSON.

  • 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-08T12:42:36+00:00Added an answer on June 8, 2026 at 12:42 pm

    The security issue you cite is a CSRF vulnerability caused by the fact that JSON arrays requested by script includes can be evaluated by overriding the native javascript Array type. Here’s a good explanation of the vulnerability. AFAIK, this is not possible with plain JSON objects.

    However, Backbone doesn’t stop you from wrapping your collection responses. You can override Backbone.Collection.parse to “unwrap” or otherwise modify the raw response before the collection is populated.

    var MyCollection = Backbone.Collection.extend({
      model:MyModel,
      parse: function(response) {
        //Assume the response looks like { "data": [ ... ] }
        return response.data;
      }
    });
    

    I typically prefer to wrap the collection responses, not only for security reasons, but also because it allows for greater flexibility and change-resilience in the API.

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

Sidebar

Related Questions

We're saving a collection of a model but backbone seems to want to do
In backbone it seems that I have to get model attributes via model.get('att_name') I'd
What is the aim of specifying a model in a Backbone collection? It seems
In backbone.js, I'm noticing that the change and all events on a Model do
A Backbone app which I'm developing has a collection and a model, and associated
I have noticed that when multiple attributes of a Backbone model are set like
I have simple user model: var user = Backbone.Model.extend({ initialize: function(){ this.bind(change:auth, function (){
MongoDB seems appealing because in JavaScript front-end applications, especially those that leverage Backbone and
I have a Backbone collection and when I add a new model to it
This seems pretty much as a standard use of a collection, but it doesnt

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.