mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 08:17:34 +00:00
InGamePacketHandler: limit depth of form responses to 2
form responses should only contain string|int|float|bool|null. Arrays or objects appearing in here are likely malicious.
This commit is contained in:
parent
ed312863a7
commit
c10eda5eae
@ -125,6 +125,7 @@ use const JSON_THROW_ON_ERROR;
|
||||
* This handler handles packets related to general gameplay.
|
||||
*/
|
||||
class InGamePacketHandler extends PacketHandler{
|
||||
private const MAX_FORM_RESPONSE_DEPTH = 2; //modal/simple will be 1, custom forms 2 - they will never contain anything other than string|int|float|bool|null
|
||||
|
||||
/** @var Player */
|
||||
private $player;
|
||||
@ -880,14 +881,14 @@ class InGamePacketHandler extends PacketHandler{
|
||||
|
||||
$fixed = "[" . implode(",", $newParts) . "]";
|
||||
try{
|
||||
return json_decode($fixed, $assoc, flags: JSON_THROW_ON_ERROR);
|
||||
return json_decode($fixed, $assoc, self::MAX_FORM_RESPONSE_DEPTH, JSON_THROW_ON_ERROR);
|
||||
}catch(\JsonException $e){
|
||||
throw PacketHandlingException::wrap($e, "Failed to fix JSON (original: $json, modified: $fixed)");
|
||||
}
|
||||
}
|
||||
|
||||
try{
|
||||
return json_decode($json, $assoc, flags: JSON_THROW_ON_ERROR);
|
||||
return json_decode($json, $assoc, self::MAX_FORM_RESPONSE_DEPTH, JSON_THROW_ON_ERROR);
|
||||
}catch(\JsonException $e){
|
||||
throw PacketHandlingException::wrap($e);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user