Add client-side Lua event sequence management and anti-replay checks#4990
Open
QueryOfficial wants to merge 2 commits into
Open
Add client-side Lua event sequence management and anti-replay checks#4990QueryOfficial wants to merge 2 commits into
QueryOfficial wants to merge 2 commits into
Conversation
- Introduced a monotonic sequence for Lua events to prevent replay attacks. - Added methods to manage the client Lua event sequence in CClientGame and CPlayer. - Implemented checks in CGame and CLuaEventPacket to validate the sequence. - Enhanced event handling in CEvents to support remote server event pulses. - Updated relevant classes and methods to accommodate the new sequence logic.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Hardens Lua event sync against verbatim replay and protects server→client event delivery from Lua-level cancellation.
eBitStreamVersion::ClientLuaEventSequence)CClientGameandCPlayerCGameandCLuaEventPacketto validate the sequence before dispatchCEventsto support remote server event pulses (scopedcancelEvent+ debug-hook guard)Client → server (anti-replay)
uint32sequence on eachtriggerServerEvent/triggerLatentServerEventServer → client (event blocking mitigation)
CPacketHandler::Packet_LuaEventdispatchcancelEventaccepted only from the handler's own Lua VM (injected scripts cannot cancel foreign handlers)addDebugHookpreEvent"skip"ignored during the pulseDocs:
Server/mods/deathmatch/README.event-sync-guard.mdRequires matching client + server build (new bitstream feature). No crypto/secrets — open-source-safe design.
Out of scope: client-side outbound event blocking before the packet is sent (not fixable server-side).
Motivation
Cheats can resend captured
PACKET_ID_LUA_EVENTpackets verbatim (ResendPacket/ packet filter) and block server→client events via injected scripts (cancelEvent, debug-hook"skip").The server previously had no replay gate for Lua events, and any injected resource could cancel handlers for server-triggered
triggerClientEvent.Because MTA's client is open source, this fix uses only:
No session keys or client-side signatures — those would be trivially bypassed in a recompiled cheat.
Test plan
Build client + server from this branch (matching bitstream). Private test server, 2 clients if testing server→client blocking.
Client → server
triggerServerEventtwice with identical args → both reach the serverPACKET_ID_LUA_EVENTpacket verbatim (cheatResendPacket) → server drops the replayServer → client
triggerClientEventto a registered handlercancelEvent()during dispatch → intended handler still runs"skip"during server remote event → event still dispatchesExpected results
triggerServerEventcalls → both acceptedcancelEvent/ debug-hook skip on server events → ignoredChecklist