Skip to content

Shipped snippets that do not load or throw on common input #65

Closed

Description

@TMHSDigital

Summary

Some shipped snippets do not load as written or throw on common input, which breaks the project convention that "Snippets: must compile or load cleanly inside a CFX resource".

Where

  • snippets/javascript/state-bag-entity.js:5-10 (vehicle declared twice)
  • snippets/csharp/register-command.cs:17 (args[0] without a length check)
  • snippets/lua/export-function.lua:9 (undefined global doSomeCalculation)
  • snippets/lua/verified-payment-callback.lua:98, :104 (non-integer timestamp)

Details

  • state-bag-entity.js declares const vehicle at line 5 (server part) and again at line 9 (client part) in the same scope. node --check fails with SyntaxError: Identifier 'vehicle' has already been declared.
  • register-command.cs formats args[0] unconditionally, so /mycommand with no arguments throws ArgumentOutOfRangeException inside the handler.
  • export-function.lua calls doSomeCalculation(param), which is not defined anywhere in the snippet, so the export errors when called.
  • verified-payment-callback.lua parses the timestamp header with tonumber, which accepts non-integer values such as 1763600000.5. That value passes the freshness check, and then ('%d.%s'):format(timestamp, body) raises "number has no integer representation", so the request is left unanswered instead of getting a 400. The rest of the verification flow is unaffected; this is an input robustness issue.

Impact

Users pasting these snippets get load errors or runtime exceptions in the server console.

Steps to reproduce

  1. node --check snippets/javascript/state-bag-entity.js
  2. In a C# resource using register-command.cs, type /mycommand with no arguments.
  3. Send the payment callback a request whose timestamp header is 1763600000.5 with a fresh value: the handler errors instead of replying.

Suggested fix

  • Split the JS snippet into clearly separate server and client blocks (separate files or comments plus distinct variable names) so it parses.
  • Guard with args.Count > 0 (or equivalent) before reading args[0].
  • Define a stub doSomeCalculation or mark the placeholder clearly in a way that still loads.
  • In the payment callback, parse the header with math.tointeger(tonumber(...)) and reply 400 when the result is nil (non-integer or missing).

Acceptance criteria

  • Every JS snippet passes node --check.
  • The C# command snippet handles zero arguments without throwing.
  • The Lua snippets load and run without undefined globals.
  • A non-integer timestamp gets a 400 response.

Getting started

  • Relevant files: snippets/javascript/state-bag-entity.js, snippets/csharp/register-command.cs, snippets/lua/export-function.lua, snippets/lua/verified-payment-callback.lua
  • 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: CLAUDE.md (Key Conventions, Snippets)

Filed by repo-audit/full-audit at 701824d. Severity: low. Effort: S. audit-key: bug|snippets/javascript/state-bag-entity.js|snippet-load

Activity

  1. added
    bug
    on Nov 21, 2026
  2. TMHSDigital commented on Nov 21, 2026

    @TMHSDigital
    OwnerAuthor

    Fixed in 99c490c.

    Split the JS state-bag snippet into labelled server/client parts with distinct names, guarded the C# command for zero arguments (List), defined the Lua export placeholder, and converted the payment-callback timestamp with math.tointeger so non-integer values get a 400.

    Verified: node --check passes for every JS snippet; the C# snippet compiles against CitizenFX.Core.Server. The Lua edits are syntax-checked by the new CI luac step.

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

    bugseverity: low

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions