Pick a long bracket the json does not close in rcon commands (#506)

exp_reports, exp_roles and exp_groups wrapped the json they send to Lua in
a fixed [=[ ]=] long bracket. A report reason, role name or group name
containing ]=] closed it early and the rest ran as Lua through /sc. Any
player can make a report, so any player could run code on the server.

Use the next level the json does not contain, like the other plugins do.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
BastiaanandClaude Opus 5.5 authored and GitHub committed 2026-10-15 17:07:47 +01:00
1 parent 55bdf72fff
commit 8e7ac3c872
5 files changed
+51 -9

No files matched your search

+14 -3
View File
@@ -83,10 +83,13 @@ async function startPlugin(t2, { syncMode = "bidirectional", roles = sampleRoles
};
}
/** The lua receiver and payload of a recorded rcon command. */
/** The lua receiver and payload of a recorded rcon command, throws if the json closes its long bracket. */
function decodeRcon(command) {
const match = command.match(/^\/sc exp_roles\.(\w+)\(helpers\.json_to_table\[=\[(.*)\]=\]\)$/s);
return { receiver: match[1], payload: JSON.parse(match[2]) };
const match = command.match(/^\/sc exp_roles\.(\w+)\(helpers\.json_to_table\[(=+)\[(.*)\]\2\]\)$/s);
if (match[3].includes(`]${match[2]}]`)) {
throw new Error(`json closes the long bracket: ${command}`);
}
return { receiver: match[1], payload: JSON.parse(match[3]) };
}
t.test("entrypoint", async t2 => {
@@ -161,6 +164,14 @@ t.test("instance plugin", t2 => {
t3.strictSame(assignments.receiver, "receive_assignment_updates", "assignment updates are forwarded");
});
t2.test("role names that close a long bracket stay inside the json", async t3 => {
const { state, roleUpdated } = await startPlugin(t3);
const records = sampleRoles();
records[0].name = "]=]) game.print(1) --[==[ ]==]";
await roleUpdated(new messages.RoleUpdatedEvent(records));
t3.strictSame(decodeRcon(state.rcons[0]).payload[0].name, records[0].name);
});
t2.test("role and assignment updates are gated while disabled", async t3 => {
const { state, roleUpdated, assignmentUpdated } = await startPlugin(t3, { syncMode: "disabled" });
await roleUpdated(new messages.RoleUpdatedEvent(sampleRoles()));