Bug Tracker

Modify

Ticket #2567 (closed feature: fixed)

Opened 5 years ago

Last modified 5 years ago

$.ajax should allow filtering JS and JSON responses to remove security measures

Reported by: eventualbuddha Owned by: flesler
Priority: major Milestone: 1.2.4
Component: ajax Version: 1.2.3
Keywords: security Cc:
Blocking: Blocked by:

Description

Responses that contain executable JS or even bare JSON may pose a security risk when a malicious site requests such things via a <script> tag (see  http://www.fortify.com/servlet/downloads/public/JavaScript_Hijacking.pdf).

To compliment a server-side JS/JSON mechanism, I propose that jQuery allow users to specify a filter that will remove whatever is added to the payload to render it safe for <script> tags. Popular methods are prepending while(1); and wrapping the response in a comment. In this patch I've gone with the latter, using a filter identical to the one Prototype uses. Users are free to choose their own, as it is simply a regular expression. Here is an example of the wrapped JSON:

/*-secure- { "data": {"lang": "en", "length": 25} } */

I'm not super-familiar with jQuery, so there may be problems with this patch, particularly with regard to the tests, so please modify to suit whatever guidelines I missed.

Attachments

json_with_security.diff Download (3.0 KB) - added by eventualbuddha 5 years ago.
ajax-filter.diff Download (1.1 KB) - added by flesler 5 years ago.

Change History

Changed 5 years ago by eventualbuddha

comment:1 Changed 5 years ago by flesler

  • Type changed from enhancement to feature

I'd prefer a function, that receives a string, and returns a string. That gives more flexibility than a regex. One could simply sanitize the response from possible injection

comment:2 Changed 5 years ago by flesler

  • Owner set to flesler
  • Status changed from new to assigned

Changed 5 years ago by flesler

comment:3 Changed 5 years ago by brandon

I like the idea of using a function but wonder if we should provide an optional, default function for developers to utilize... hopefully making it that much easier to make their JSON feeds more secure.

comment:4 Changed 5 years ago by flesler

  • need changed from Review to Commit

So.. commit ?

comment:5 Changed 5 years ago by flesler

  • Status changed from assigned to closed
  • Resolution set to fixed

Added the possibility to use a parsing function by the name of 'dataFilter' at [5620].

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.