@@ -1270,6 +1270,15 @@ protected function exitWith404($type) {
1270
1270
}
1271
1271
}
1272
1272
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
+
1273
1282
protected function exitWith400 ($ type ) {
1274
1283
if (isset ($ _SERVER ['REQUEST_METHOD ' ])) {
1275
1284
header ('Content-Type: ' ,true ,400 );
@@ -2649,13 +2658,19 @@ protected function swagger($settings) {
2649
2658
protected function allowOrigin ($ origin ,$ allowOrigins ) {
2650
2659
if (isset ($ _SERVER ['REQUEST_METHOD ' ])) {
2651
2660
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 ' ])) {
2654
2666
header ('Access-Control-Allow-Origin: ' .$ origin );
2655
- break ;
2656
2667
}
2668
+ break ;
2657
2669
}
2658
2670
}
2671
+ if (!$ found ) {
2672
+ $ this ->exitWith403 ('origin ' );
2673
+ }
2659
2674
}
2660
2675
2661
2676
public function executeCommand () {
0 commit comments