Repository navigation
Closed
Labels
Description
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(vehicledeclared twice)snippets/csharp/register-command.cs:17(args[0]without a length check)snippets/lua/export-function.lua:9(undefined globaldoSomeCalculation)snippets/lua/verified-payment-callback.lua:98,:104(non-integer timestamp)
Details
- state-bag-entity.js declares
const vehicleat line 5 (server part) and again at line 9 (client part) in the same scope.node --checkfails withSyntaxError: Identifier 'vehicle' has already been declared. - register-command.cs formats
args[0]unconditionally, so/mycommandwith no arguments throwsArgumentOutOfRangeExceptioninside 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 as1763600000.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
node --check snippets/javascript/state-bag-entity.js- In a C# resource using
register-command.cs, type/mycommandwith no arguments. - Send the payment callback a request whose timestamp header is
1763600000.5with 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 readingargs[0]. - Define a stub
doSomeCalculationor 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 isnil(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
TMHSDigital commentedon Nov 21, 2026
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.