Harden JsonMapper on login JSON handling

This commit is contained in:
Dylan K. Taylor 2024-02-23 14:10:02 +00:00
parent e06b042cd0
commit 6872661fd0
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
4 changed files with 19 additions and 16 deletions

View File

@ -32,7 +32,7 @@
"ext-zlib": ">=1.2.11", "ext-zlib": ">=1.2.11",
"composer-runtime-api": "^2.0", "composer-runtime-api": "^2.0",
"adhocore/json-comment": "~1.2.0", "adhocore/json-comment": "~1.2.0",
"pocketmine/netresearch-jsonmapper": "~v4.2.1000", "pocketmine/netresearch-jsonmapper": "~v4.4.999",
"pocketmine/bedrock-block-upgrade-schema": "~3.5.0+bedrock-1.20.60", "pocketmine/bedrock-block-upgrade-schema": "~3.5.0+bedrock-1.20.60",
"pocketmine/bedrock-data": "~2.8.0+bedrock-1.20.60", "pocketmine/bedrock-data": "~2.8.0+bedrock-1.20.60",
"pocketmine/bedrock-item-upgrade-schema": "~1.7.0+bedrock-1.20.60", "pocketmine/bedrock-item-upgrade-schema": "~1.7.0+bedrock-1.20.60",

29
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "9e781d0fef7796616b0580e7b06cc6d1", "content-hash": "14848cb7b70d0fa63ed46b30128c2320",
"packages": [ "packages": [
{ {
"name": "adhocore/json-comment", "name": "adhocore/json-comment",
@ -200,21 +200,20 @@
}, },
{ {
"name": "pocketmine/bedrock-protocol", "name": "pocketmine/bedrock-protocol",
"version": "27.0.1+bedrock-1.20.60", "version": "27.0.2+bedrock-1.20.60",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/pmmp/BedrockProtocol.git", "url": "https://github.com/pmmp/BedrockProtocol.git",
"reference": "0cebb55f6e904f722b14d420f6b2c84c7fa69f10" "reference": "6905865133b69da8c95a13c563d349e1993c06b8"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/pmmp/BedrockProtocol/zipball/0cebb55f6e904f722b14d420f6b2c84c7fa69f10", "url": "https://api.github.com/repos/pmmp/BedrockProtocol/zipball/6905865133b69da8c95a13c563d349e1993c06b8",
"reference": "0cebb55f6e904f722b14d420f6b2c84c7fa69f10", "reference": "6905865133b69da8c95a13c563d349e1993c06b8",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"ext-json": "*", "ext-json": "*",
"netresearch/jsonmapper": "^4.0",
"php": "^8.1", "php": "^8.1",
"pocketmine/binaryutils": "^0.2.0", "pocketmine/binaryutils": "^0.2.0",
"pocketmine/color": "^0.2.0 || ^0.3.0", "pocketmine/color": "^0.2.0 || ^0.3.0",
@ -241,9 +240,9 @@
"description": "An implementation of the Minecraft: Bedrock Edition protocol in PHP", "description": "An implementation of the Minecraft: Bedrock Edition protocol in PHP",
"support": { "support": {
"issues": "https://github.com/pmmp/BedrockProtocol/issues", "issues": "https://github.com/pmmp/BedrockProtocol/issues",
"source": "https://github.com/pmmp/BedrockProtocol/tree/27.0.1+bedrock-1.20.60" "source": "https://github.com/pmmp/BedrockProtocol/tree/27.0.2+bedrock-1.20.60"
}, },
"time": "2024-02-07T11:53:50+00:00" "time": "2024-02-23T13:43:39+00:00"
}, },
{ {
"name": "pocketmine/binaryutils", "name": "pocketmine/binaryutils",
@ -563,16 +562,16 @@
}, },
{ {
"name": "pocketmine/netresearch-jsonmapper", "name": "pocketmine/netresearch-jsonmapper",
"version": "v4.2.1000", "version": "v4.4.999",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/pmmp/netresearch-jsonmapper.git", "url": "https://github.com/pmmp/netresearch-jsonmapper.git",
"reference": "078764e869e9b732f97206ec9363480a77c35532" "reference": "9a6610033d56e358e86a3e4fd5f87063c7318833"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/pmmp/netresearch-jsonmapper/zipball/078764e869e9b732f97206ec9363480a77c35532", "url": "https://api.github.com/repos/pmmp/netresearch-jsonmapper/zipball/9a6610033d56e358e86a3e4fd5f87063c7318833",
"reference": "078764e869e9b732f97206ec9363480a77c35532", "reference": "9a6610033d56e358e86a3e4fd5f87063c7318833",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -586,7 +585,7 @@
"netresearch/jsonmapper": "~4.2.0" "netresearch/jsonmapper": "~4.2.0"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "~7.5 || ~8.0 || ~9.0", "phpunit/phpunit": "~7.5 || ~8.0 || ~9.0 || ~10.0",
"squizlabs/php_codesniffer": "~3.5" "squizlabs/php_codesniffer": "~3.5"
}, },
"type": "library", "type": "library",
@ -611,9 +610,9 @@
"support": { "support": {
"email": "cweiske@cweiske.de", "email": "cweiske@cweiske.de",
"issues": "https://github.com/cweiske/jsonmapper/issues", "issues": "https://github.com/cweiske/jsonmapper/issues",
"source": "https://github.com/pmmp/netresearch-jsonmapper/tree/v4.2.1000" "source": "https://github.com/pmmp/netresearch-jsonmapper/tree/v4.4.999"
}, },
"time": "2023-07-14T10:44:14+00:00" "time": "2024-02-23T13:17:01+00:00"
}, },
{ {
"name": "pocketmine/raklib", "name": "pocketmine/raklib",

View File

@ -135,6 +135,7 @@ class ProcessLoginTask extends AsyncTask{
$mapper = new \JsonMapper(); $mapper = new \JsonMapper();
$mapper->bExceptionOnMissingData = true; $mapper->bExceptionOnMissingData = true;
$mapper->bExceptionOnUndefinedProperty = true; $mapper->bExceptionOnUndefinedProperty = true;
$mapper->bStrictObjectTypeChecking = true;
$mapper->bEnforceMapType = false; $mapper->bEnforceMapType = false;
try{ try{
@ -181,6 +182,7 @@ class ProcessLoginTask extends AsyncTask{
$mapper = new \JsonMapper(); $mapper = new \JsonMapper();
$mapper->bExceptionOnUndefinedProperty = false; //we only care about the properties we're using in this case $mapper->bExceptionOnUndefinedProperty = false; //we only care about the properties we're using in this case
$mapper->bExceptionOnMissingData = true; $mapper->bExceptionOnMissingData = true;
$mapper->bStrictObjectTypeChecking = true;
$mapper->bEnforceMapType = false; $mapper->bEnforceMapType = false;
$mapper->bRemoveUndefinedAttributes = true; $mapper->bRemoveUndefinedAttributes = true;
try{ try{

View File

@ -169,6 +169,7 @@ class LoginPacketHandler extends PacketHandler{
$mapper->bEnforceMapType = false; //TODO: we don't really need this as an array, but right now we don't have enough models $mapper->bEnforceMapType = false; //TODO: we don't really need this as an array, but right now we don't have enough models
$mapper->bExceptionOnMissingData = true; $mapper->bExceptionOnMissingData = true;
$mapper->bExceptionOnUndefinedProperty = true; $mapper->bExceptionOnUndefinedProperty = true;
$mapper->bStrictObjectTypeChecking = true;
try{ try{
/** @var AuthenticationData $extraData */ /** @var AuthenticationData $extraData */
$extraData = $mapper->map($claims["extraData"], new AuthenticationData()); $extraData = $mapper->map($claims["extraData"], new AuthenticationData());
@ -197,6 +198,7 @@ class LoginPacketHandler extends PacketHandler{
$mapper->bEnforceMapType = false; //TODO: we don't really need this as an array, but right now we don't have enough models $mapper->bEnforceMapType = false; //TODO: we don't really need this as an array, but right now we don't have enough models
$mapper->bExceptionOnMissingData = true; $mapper->bExceptionOnMissingData = true;
$mapper->bExceptionOnUndefinedProperty = true; $mapper->bExceptionOnUndefinedProperty = true;
$mapper->bStrictObjectTypeChecking = true;
try{ try{
$clientData = $mapper->map($clientDataClaims, new ClientData()); $clientData = $mapper->map($clientDataClaims, new ClientData());
}catch(\JsonMapper_Exception $e){ }catch(\JsonMapper_Exception $e){