22
33use Closure ;
44use Illuminate \Contracts \Routing \Middleware ;
5- use Log ;
65
76// Verify that we aren't serving an unauthorized cross-origin JavaScript response.
87
98class 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