Skip to content

state-bags skill wrongly says clients cannot override server-set state #43

Closed

Description

@TMHSDigital

Summary

The state-bags skill states that "Server-set state is authoritative -- clients cannot override it" and presents a change handler that returns as a way to reject client changes. Both statements are factually wrong under CFX state bag semantics, and the guidance can lead developers to trust player and entity bags for authority data.

Where

  • skills/state-bags/SKILL.md:30 ("client can read/write own state")
  • skills/state-bags/SKILL.md:155-171 (## Security section and sample)

Details

AddStateBagChangeHandler('customData', nil, function(bagName, key, value, _reserved, replicated)
    if replicated then
        local entity = GetEntityFromStateBagName(bagName)
        if not isEntityOwnedByTrustedPlayer(entity) then
            return  -- reject
        end
    end
end)
  • A client can set replicated values on its own player bag and on entities it owns, including keys the server set earlier. Line 30 of the skill already says the client can write its own state, which contradicts line 157.
  • AddStateBagChangeHandler is a notification. Returning from the handler does not revert or block the value; it has already been applied.
  • The skill's own example (around line 35) stores job and onDuty in Player(source).state, which readers will then treat as trusted on the server.

Impact

Developers using this skill (and agents that load it) may put authority data such as jobs, duty status or permissions into player or entity bags and rely on the "reject" pattern, believing the server value cannot change. The rest of the skill is accurate; this section is the problem.

Suggested fix

Rewrite the Security section to say:

  • Clients can write keys on bags they own (their player bag and entities they own), and those writes replicate.
  • Server-side decisions must read authority data from server-held state (framework player data, server tables, or keys the client cannot own), not from player or entity bags.
  • A change handler cannot reject a change. If a client changes a key it should not, the server must re-set the authoritative value (and optionally flag the player).
  • Mention any server configuration that restricts client state bag writes, after confirming the current option names on docs.fivem.net.

Replace the sample with one that keeps the value server-side and, on a replicated client change to a protected key, re-applies the server value. Adjust line 30 and the job example accordingly.

Acceptance criteria

  • The Security section no longer claims clients cannot override server-set state.
  • The sample does not imply that returning from a change handler rejects a change.
  • The skill tells readers where authority data should live and how to restore a server value.

Getting started

  • Relevant files: skills/state-bags/SKILL.md
  • How to run checks: there is no test suite yet; run the MCP server with cd mcp-server && pip install -r requirements.txt && python server.py, and CI checks live in .github/workflows/validate.yml
  • Related docs: state bags documentation on docs.fivem.net, rules/security-best-practices.mdc

Filed by repo-audit/full-audit at 701824d. Severity: medium. Effort: S. audit-key: documentation|skills/state-bags/SKILL.md|Security

Activity

  1. added
    documentation
    good first issue
    on Nov 21, 2026
  2. TMHSDigital commented on Nov 21, 2026

    @TMHSDigital
    OwnerAuthor

    Fixed in 843373a.

    The Security section now says clients can write bags they own, tells readers to keep authority data in server-held state, explains that a change handler cannot undo a write, and replaces the sample with one that keeps the job in a server table and restores it when the bag differs.

    Verified: Reviewed against the acceptance criteria; no claim that clients cannot override state remains.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationgood first issueseverity: medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions