-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#45: Add origin hosts check to server + readme
- Loading branch information
1 parent
cb269f2
commit 0b32dd9
Showing
16 changed files
with
153 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace WSSC\Components; | ||
|
||
use PHPUnit\Framework\OutputError; | ||
use WSSC\Exceptions\ConnectionException; | ||
|
||
class OriginComponent | ||
{ | ||
private $client; | ||
private $config; | ||
|
||
/** | ||
* OriginComponent constructor. | ||
* @param ServerConfig $config | ||
* @param $client | ||
*/ | ||
public function __construct(ServerConfig $config, $client) | ||
{ | ||
$this->config = $config; | ||
$this->client = $client; | ||
} | ||
|
||
/** | ||
* Checks if there is a compatible origin header came from client | ||
* @param string $headers | ||
* @return bool | ||
*/ | ||
public function checkOrigin(string $headers): bool | ||
{ | ||
preg_match('/Origin\:\s(.*?)\s/', $headers, $matches); | ||
if (empty($matches[1])) { | ||
$this->sendAndClose('No Origin header found.'); | ||
return false; | ||
} else { | ||
$originHost = $matches[1]; | ||
$allowedOrigins = $this->config->getOrigins(); | ||
if (in_array($originHost, $allowedOrigins, true) === false) { | ||
$this->sendAndClose('Host ' . $originHost . ' is not allowed to pass access control as origin.'); | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
/** | ||
* @param string $msg | ||
* @throws \Exception | ||
*/ | ||
private function sendAndClose(string $msg) | ||
{ | ||
$conn = new Connection($this->client); | ||
$conn->send($msg); | ||
$conn->close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,6 @@ | |
|
||
trait WSClientTrait | ||
{ | ||
|
||
/** | ||
* Validates whether server sent valid upgrade response | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,6 @@ | |
*/ | ||
class WssMain implements CommonsContract | ||
{ | ||
|
||
private $isPcntlLoaded = false; | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.