Missing validation in GivePlayerPatternCommandPacket enables item cheating
Alainx277 opened this issue ยท 1 comments
The GivePlayerPatternCommandPacket
can be abused because it does not validate that patternStack
is a pattern item:
This makes it possible for a cheater to get any items and set arbitrary NBT data.
Example exploit
event.getDispatcher().register(Commands.literal("exploit")
.then(Commands.argument("item", ItemArgument.item(event.getBuildContext())).executes(context -> {
ItemInput item = ItemArgument.getItem(context, "item");
ItemStack stack = item.createItemStack(1, true);
stack.setCount(stack.getMaxStackSize());
ChiselsAndBits.getInstance().getNetworkChannel().sendToServer(new GivePlayerPatternCommandPacket(stack));
return 1;
})));
Running /exploit minecraft:diamond
on client will give the player a stack of diamonds.
Possible fix:
@Override
public void server(final ServerPlayer playerEntity)
{
if (!patternStack.is(ForgeRegistries.ITEMS.getValue(new ResourceLocation("chiselsandbits:pattern_single_use")))) {
return;
}
IPlayerInventoryManager.getInstance().giveToPlayer(playerEntity, patternStack);
}