Skip to content

Commit 8aece27

Browse files
author
Tortue Torche
committed
Add an $except property for the VerifyJavascriptResponse middleware, similar to the Laravel 5.1 VerifyCsrfToken middleware.
Useful for some development packages. See: http://laravel.com/docs/5.1/routing#csrf-protection
1 parent b6e1513 commit 8aece27

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

src/Efficiently/JqueryLaravel/VerifyJavascriptResponse.php

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,20 @@
22

33
use Closure;
44
use Illuminate\Contracts\Routing\Middleware;
5-
use Log;
65

76
// Verify that we aren't serving an unauthorized cross-origin JavaScript response.
87

98
class VerifyJavascriptResponse implements Middleware
109
{
1110

11+
/**
12+
* The URIs that should be excluded from cross origin verification.
13+
*
14+
* @var array
15+
*/
16+
protected $except = [];
17+
18+
1219
/**
1320
* Create a new middleware instance.
1421
*
@@ -30,8 +37,8 @@ public function __construct()
3037
public function handle($request, Closure $next)
3138
{
3239
$response = $next($request);
33-
if ($this->isReading($request) &&
34-
$this->nonXhrJavascriptResponse($request, $response)
40+
if (! $this->shouldPassThrough($request) ||
41+
($this->isReading($request) && $this->nonXhrJavascriptResponse($request, $response))
3542
) {
3643
$crossOriginJavascriptWarning = "Security warning: an embedded " .
3744
"<script> tag on another site requested protected JavaScript. " .
@@ -43,6 +50,23 @@ public function handle($request, Closure $next)
4350

4451
return $response;
4552
}
53+
54+
/**
55+
* Determine if the request has a URI that should pass through cross origin verification.
56+
*
57+
* @param \Illuminate\Http\Request $request
58+
* @return bool
59+
*/
60+
protected function shouldPassThrough($request)
61+
{
62+
foreach ($this->except as $except) {
63+
if ($request->is($except)) {
64+
return true;
65+
}
66+
}
67+
return false;
68+
}
69+
4670
/**
4771
* Determine if the the response isn't a XHR(AJAX) Javascript one
4872
*

0 commit comments

Comments
 (0)