Skip to content
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

Vulnerability resolutions #261

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions src/EmotePacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
namespace pocketmine\network\mcpe\protocol;

use pocketmine\network\mcpe\protocol\serializer\PacketSerializer;
use Ramsey\Uuid\Uuid;

class EmotePacket extends DataPacket implements ClientboundPacket, ServerboundPacket{
public const NETWORK_ID = ProtocolInfo::EMOTE_PACKET;
Expand Down Expand Up @@ -60,6 +61,10 @@ public function getFlags() : int{
protected function decodePayload(PacketSerializer $in) : void{
$this->actorRuntimeId = $in->getActorRuntimeId();
$this->emoteId = $in->getString();
if(!Uuid::isValid($this->emoteId)) {
throw new PacketDecodeException("Invalid EmoteId");
}

$this->xboxUserId = $in->getString();
$this->platformChatId = $in->getString();
$this->flags = $in->getByte();
Expand Down
4 changes: 4 additions & 0 deletions src/LoginPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ protected function decodeConnectionRequest(string $binary) : void{
if(!is_array($chainDataJson["chain"])){
throw new PacketDecodeException("Chain data 'chain' element must be a list of strings");
}
if(count($chainDataJson["chain"]) !== 3) {
throw new PacketDecodeException("Chain data 'chain' must contain three jwt");
}

$jwts = [];
foreach($chainDataJson["chain"] as $jwt){
if(!is_string($jwt)){
Expand Down
30 changes: 28 additions & 2 deletions src/PurchaseReceiptPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

namespace pocketmine\network\mcpe\protocol;

use pocketmine\network\mcpe\JwtUtils;
use pocketmine\network\mcpe\protocol\serializer\PacketSerializer;
use pocketmine\network\mcpe\protocol\types\login\JwtChain;
use function count;

class PurchaseReceiptPacket extends DataPacket implements ServerboundPacket{
Expand All @@ -35,8 +37,32 @@

protected function decodePayload(PacketSerializer $in) : void{
$count = $in->getUnsignedVarInt();
for($i = 0; $i < $count; ++$i){
$this->entries[] = $in->getString();
if($count > 1) {
throw new PacketDecodeException("There should be a maximum of one jwt");
}

for($i = 0; $i < $count; ++$i) {
[, $data, ] = JwtUtils::parse($in->getString());

Check failure on line 45 in src/PurchaseReceiptPacket.php

View workflow job for this annotation

GitHub Actions / Tests (PHP 8.1)

Call to static method parse() on an unknown class pocketmine\network\mcpe\JwtUtils.

Check failure on line 45 in src/PurchaseReceiptPacket.php

View workflow job for this annotation

GitHub Actions / Tests (PHP 8.2)

Call to static method parse() on an unknown class pocketmine\network\mcpe\JwtUtils.

Check failure on line 45 in src/PurchaseReceiptPacket.php

View workflow job for this annotation

GitHub Actions / Tests (PHP 8.3)

Call to static method parse() on an unknown class pocketmine\network\mcpe\JwtUtils.
if(!isset($data["sub"])) {
throw new PacketDecodeException("JWT payload must contain 'sub'");
}
if(!isset($data["tid"])) {
throw new PacketDecodeException("JWT payload must contain 'tid'");
}
if(!isset($data["xuid"])) {
throw new PacketDecodeException("JWT payload must contain 'xuid'");
}
if(!isset($data["entitlements"])) {
throw new PacketDecodeException("JWT payload must contain 'entitlements'");
}

try {
json_decode($data["entitlements"], false, flags: JSON_THROW_ON_ERROR);
} catch(\Exception $exception) {
throw new PacketDecodeException($exception->getMessage());
}

$this->entries[] = $data["entitlements"];
}
}

Expand Down
Loading