-
-
Notifications
You must be signed in to change notification settings - Fork 145
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
Inventory Packet Validation #292
Comments
This was referenced Mar 17, 2023
Seems like something we should be handling at some point. |
We found in #293 that sometimes, the client will automatically add nbt data if it thinks it needs it, like a "Damage" property on a pickaxe. This messed with our checks for nbt data so we removed them for now |
rj00a
added a commit
that referenced
this issue
Mar 24, 2023
## Description This adds some validation for incoming inventory packets that makes it so that you can't just spawn items by sending malicious packets. It adds type 1 and type 2 validations as outlined in #292. This also adds some new helpers, `InventoryWindow` and `InventoryWindowMut`. fixes #292 <details> <summary>Playground</summary> ```rust use valence::client::{default_event_handler, despawn_disconnected_clients}; use valence::prelude::event::PlayerInteractBlock; use valence::prelude::*; #[allow(unused_imports)] use crate::extras::*; const SPAWN_Y: i32 = 64; const CHEST_POS: [i32; 3] = [0, SPAWN_Y + 1, 3]; pub fn build_app(app: &mut App) { app.add_plugin(ServerPlugin::new(()).with_connection_mode(ConnectionMode::Offline)) .add_startup_system(setup) .add_system(default_event_handler.in_schedule(EventLoopSchedule)) .add_system(init_clients) .add_system(despawn_disconnected_clients) .add_systems((toggle_gamemode_on_sneak, open_chest).in_schedule(EventLoopSchedule)); } fn setup(mut commands: Commands, server: Res<Server>) { let mut instance = server.new_instance(DimensionId::default()); for z in -5..5 { for x in -5..5 { instance.insert_chunk([x, z], Chunk::default()); } } for z in -25..25 { for x in -25..25 { instance.set_block([x, SPAWN_Y, z], BlockState::GRASS_BLOCK); } } instance.set_block(CHEST_POS, BlockState::CHEST); commands.spawn(instance); let mut inventory = Inventory::new(InventoryKind::Generic9x3); inventory.set_slot(0, ItemStack::new(ItemKind::Apple, 100, None)); inventory.set_slot(1, ItemStack::new(ItemKind::Diamond, 40, None)); inventory.set_slot(2, ItemStack::new(ItemKind::Diamond, 30, None)); commands.spawn(inventory); } fn init_clients( mut clients: Query<(&mut Position, &mut Location, &mut Inventory), Added<Client>>, instances: Query<Entity, With<Instance>>, ) { for (mut pos, mut loc, mut inv) in &mut clients { pos.0 = [0.5, SPAWN_Y as f64 + 1.0, 0.5].into(); loc.0 = instances.single(); inv.set_slot(24, ItemStack::new(ItemKind::Apple, 100, None)); inv.set_slot(25, ItemStack::new(ItemKind::Apple, 10, None)); } } // Add new systems here! fn open_chest( mut commands: Commands, inventories: Query<Entity, (With<Inventory>, Without<Client>)>, mut events: EventReader<PlayerInteractBlock>, ) { let Ok(inventory) = inventories.get_single() else { return; }; for event in events.iter() { if event.position != CHEST_POS.into() { continue; } let open_inventory = OpenInventory::new(inventory); commands.entity(event.client).insert(open_inventory); } } ``` </details> ## Test Plan Steps: 1. `cargo test` --------- Co-authored-by: Ryan Johnson <[email protected]>
dyc3
added a commit
that referenced
this issue
Sep 21, 2023
…nventories (#529) Hi, # Objective I was playing around with the chest example. After adding an item with NBT data, I noticed I was unable to remove it from the chest. Sourced the error down to this check. All I have done is not check the NBT data for now. Same as in last comment of #292 . # Solution Only item kind and count checked, nbt ignored. Kind Regards, Mac --------- Co-authored-by: Carson McManus <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the problem related to your feature request.
At the moment, we trust the client a little too much when it comes to modifying inventories. For example, a client can send a click slot packet that just adds any item to any slot out of thin air.
What solution would you like?
There are 2 types of assertions we need to make on incoming modifications:
Type 1 validations:
some slots are "outbound only" eg. crafting result slotsdecided not to do this because it's not that useful and pretty hard to assert forType 2 validations:
The type 2 validations may be expensive, so ideally we should allow the user to disable it.
There's probably some more that I missed, but that should be enough to catch most cases.
What alternative(s) have you considered?
We could also not do this, and defer this to end users, but I think that could end up being pretty error prone.
Additional context
For #288
https://wiki.vg/Protocol#Click_Container
The text was updated successfully, but these errors were encountered: