Skip to content

Added an Origin Check... #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions class.PHPWebSocket.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ class PHPWebSocket
// the maximum length, in bytes, of a message's payload data, this is also internally limited to 2,147,483,647
const WS_MAX_MESSAGE_PAYLOAD_RECV = 500000;


// check the Origin header matches a designated URL
const WS_ORIGIN_CHECK = true;
const WS_ORIGIN_URL = 'http://localhost/';


// internal
Expand Down Expand Up @@ -608,8 +610,16 @@ function wsProcessClientHandshake($clientID, &$buffer) {
for ($i=1; $i<$headersCount; $i++) {
$parts = explode(':', $headers[$i]);
if (!isset($parts[1])) return false;

$headersKeyed[trim($parts[0])] = trim($parts[1]);
if ($parts[0] == 'Origin') {
$headersKeyed[trim($parts[0])] = str_replace('Origin: ', '', trim($headers[$i]));
} else {
$headersKeyed[trim($parts[0])] = trim($parts[1]);
}
}

// check Origin matches, if requested to do so
if (self::WS_ORIGIN_CHECK) {
if ($headersKeyed['Origin'] != self::WS_ORIGIN_URL) return false;
}

// check Host header was received
Expand Down Expand Up @@ -755,4 +765,4 @@ function unbind( $type='' )
else $this->wsOnEvents = array();
}
}
?>
?>