@@ -1270,6 +1270,15 @@ protected function exitWith404($type) {
12701270 }
12711271 }
12721272
1273+ protected function exitWith403 ($ type ) {
1274+ if (isset ($ _SERVER ['REQUEST_METHOD ' ])) {
1275+ header ('Content-Type: ' ,true ,403 );
1276+ die ("Forbidden ( $ type) " );
1277+ } else {
1278+ throw new \Exception ("Forbidden ( $ type) " );
1279+ }
1280+ }
1281+
12731282 protected function exitWith400 ($ type ) {
12741283 if (isset ($ _SERVER ['REQUEST_METHOD ' ])) {
12751284 header ('Content-Type: ' ,true ,400 );
@@ -2649,13 +2658,19 @@ protected function swagger($settings) {
26492658 protected function allowOrigin ($ origin ,$ allowOrigins ) {
26502659 if (isset ($ _SERVER ['REQUEST_METHOD ' ])) {
26512660 header ('Access-Control-Allow-Credentials: true ' );
2652- foreach (explode (', ' ,$ allowOrigins ) as $ o ) {
2653- if (preg_match ('/^ ' .str_replace ('\* ' ,'.* ' ,preg_quote (strtolower (trim ($ o )))).'$/ ' ,$ origin )) {
2661+ }
2662+ $ found = false ;
2663+ foreach (explode (', ' ,$ allowOrigins ) as $ o ) {
2664+ if (preg_match ('/^ ' .str_replace ('\* ' ,'.* ' ,preg_quote (strtolower (trim ($ o )))).'$/ ' ,$ origin )) {
2665+ if (isset ($ _SERVER ['REQUEST_METHOD ' ])) {
26542666 header ('Access-Control-Allow-Origin: ' .$ origin );
2655- break ;
26562667 }
2668+ break ;
26572669 }
26582670 }
2671+ if (!$ found ) {
2672+ $ this ->exitWith403 ('origin ' );
2673+ }
26592674 }
26602675
26612676 public function executeCommand () {
0 commit comments