Framework: JSON Hijacking

Created on 9 Jul 2017  路  7Comments  路  Source: laravel/framework

  • Laravel Version: 5.4
  • PHP Version: 7.1.4

Description:

JSON responses using the json(array) method are susceptible to hijack via cross-site script inclusion due to charset definition. The root cause: Laravel responds with header 'Content-Type: application/json' without charset value. Supose an application that returns json responses with sensitive information in it. This behaviour must be connsidered a security vulnerability, also, is a good practice to include charset definitions by default in the content-type header.

Note

Recent versions of some browsers fixed this behaviour. But it still works when a part of the json response is user controlled.

Further reading about JSON hijacking by using charset definition:

Steps To Reproduce:

//include this code snippet in a controller method and register it in the web routes:
$res = \App\MyModel::all();
return response()->json(['data' => $res]); #

Most helpful comment

I am not sure if it is a good idea to disclose this in public (normal protocol for security bugs).

All 7 comments

Sorry, I forgot the 'further reading', so here you can find more info about JSON hijacking in modern browsers: http://blog.portswigger.net/2016/11/json-hijacking-for-modern-web.html

I am not sure if it is a good idea to disclose this in public (normal protocol for security bugs).

@JoaquinRMtz what do you suggest here? have a fix?

@themsaid: it looks like he suggests adding a charset definition in the content-type header.

Example without charset (vulnerable): header('Content-Type: application/json')
Example with charset (fixes vulnerabiity): header('Content-Type: application/json; charset=utf-8')

Yeah.. by adding charset definition (header('Content-Type: application/json; charset=utf-8')) fix the issue.

Feel free to open a PR then, I think this issue is fixed already in all modern browsers and there's no need for any changes but I could be wrong.

According to the linked article, from November 2016, Edge is still vulnerable.

This looks like an easy fix... imho, it would be better to close the issue only when it is really fixed.

Was this page helpful?
0 / 5 - 0 ratings