Skip to content

Validation in OnPlayerGiveTakeDamage #600

Closed

Description

@NexiusTailer

if (!from->areWeaponsAllowed() && 0 < onPlayerGiveTakeDamageRPC.WeaponID && onPlayerGiveTakeDamageRPC.WeaponID <= 47)

if (!peer.areWeaponsAllowed() && 0 < onPlayerGiveTakeDamageRPC.WeaponID && onPlayerGiveTakeDamageRPC.WeaponID <= 47)

These lines should have validate weapon IDs under TakeDamage and GiveDamage parts of the callback, but SA-MP client can send OnPlayerTakeDamage with a wider range of weapon IDs than in OnPlayerGiveDamage: damage can be taken by reason, while can be given by weapon.

The valid reasons for OnPlayerTakeDamage are:
0..18, 22..46, 49..54 (including 52, it's half-valid despite the samp docs says)

The valid weapon IDs for OnPlayerGiveDamage are:
0..18, 22..46

Activity

  1. NexiusTailer commented on Jan 10, 2023

    @NexiusTailer
    ContributorAuthor

    including 52, it's half-valid despite the samp docs says

    Reason 52 called when player shoots another player from this vehicle built-in gun, if anyone interested:
    image
    In SA-MP server, OnPlayerDeath will still be called with reason 255 if player get killed from this (and idk if it's possible to fix on the server side in omp), but at least we let it still work for TakeDamage if properly validate all possible values.

  2. NexiusTailer commented on Jan 10, 2023

    @NexiusTailer
    ContributorAuthor

    UPD:
    The same logic as in OnPlayerTakeDamage (validate all possible damage reasons) should be in OnPlayerGiveDamageActor as well

    bool onReceive(IPlayer& peer, NetworkBitStream& bs) override
    {
    NetCode::RPC::OnPlayerDamageActor onPlayerDamageActorRPC;
    if (!onPlayerDamageActorRPC.read(bs))
    {
    return false;
    }
    if (onPlayerDamageActorRPC.Damage <= 0.0f)
    {
    return false;
    }
    if (onPlayerDamageActorRPC.Bodypart < BodyPart_Torso || onPlayerDamageActorRPC.Bodypart > BodyPart_Head)
    {
    return false;
    }
    Actor* actorPtr = self.storage.get(onPlayerDamageActorRPC.ActorID);
    if (actorPtr)
    {
    Actor& actor = *actorPtr;
    if (actor.isStreamedInForPlayer(peer) && !actor.isInvulnerable())
    {
    ScopedPoolReleaseLock<IActor> lock(self, actor);
    self.eventDispatcher.dispatch(
    &ActorEventHandler::onPlayerGiveDamageActor,
    peer,
    *lock.entry,
    onPlayerDamageActorRPC.Damage,
    onPlayerDamageActorRPC.WeaponID,
    BodyPart(onPlayerDamageActorRPC.Bodypart));
    }
    }
    return true;
    }

    At the moment, weaponid don't checked at all.

  3. self-assigned this
    on Jun 11, 2023
  4. added
    enhancement
    on Jun 11, 2023
  5. NexiusTailer commented on Dec 2, 2023

    @NexiusTailer
    ContributorAuthor

    I think it's kinda important too, so just bump it with hope it can be fixed with higher priority.

  6. assigned and unassigned on Dec 3, 2023
  7. added
    security
    on Dec 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementsecurity

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions