mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-11-17 08:50:42 +09:00
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:
1 parent
55bdf72fff
commit
8e7ac3c872
5 files changed
+51
-9
No files matched your search
@@ -74,10 +74,13 @@ async function startPlugin(t2, { reports = [report(1, "bob", "alice"), report(2,
|
||||
};
|
||||
}
|
||||
|
||||
/** 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_reports\.(\w+)\(helpers\.json_to_table\[=\[(.*)\]=\]\)$/s);
|
||||
return { receiver: match[1], payload: JSON.parse(match[2]) };
|
||||
const match = command.match(/^\/sc exp_reports\.(\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("instance plugin", t2 => {
|
||||
@@ -106,6 +109,16 @@ t.test("instance plugin", t2 => {
|
||||
t3.strictSame(payload, { caller: "dave", message: "dave has already reported bob" });
|
||||
});
|
||||
|
||||
t2.test("text that closes a long bracket stays inside the json", async t3 => {
|
||||
const { state, createIPC } = await startPlugin(t3);
|
||||
const message = "]=]) game.print(1) --[==[ ]==] ]===]";
|
||||
state.failNext = new lib.RequestError(message);
|
||||
await createIPC({ player_name: "bob", by_player_name: "dave", reason: message });
|
||||
|
||||
const { payload } = decodeRcon(state.rcons[0]);
|
||||
t3.strictSame(payload.message, message);
|
||||
});
|
||||
|
||||
t2.test("exp_reports:list lists the reports for the caller", async t3 => {
|
||||
const { state, listIPC } = await startPlugin(t3);
|
||||
await listIPC({ caller: "admin", player_name: "bob" });
|
||||
|
||||
Reference in new issue
Block a user