diff --git a/CHANGELOG.md b/CHANGELOG.md index e9b54d02..68b00884 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -74,6 +74,7 @@ Many thanks to the following for contributing to this release: - Previously silent errors for controller.sendEvent now throw exceptions [#625](https://github.com/clusterio/clusterio/pull/625). - @clusterio/controller export InstanceInfo has added factorioVersion parameter. - Argument order for `Config.canAccess` changed to require an access mode passed as the second argument. +- Instances can now have `factorio.enable_script_commands` disabled which will throw an error when any script command is used over rcon. [#681](https://github.com/clusterio/clusterio/pull/681). Many thanks to the following for contributing to this release: [@CCpersonguy](https://github.com/CCpersonguy) diff --git a/packages/host/src/Instance.ts b/packages/host/src/Instance.ts index 4101a7c1..d5aa8ae9 100644 --- a/packages/host/src/Instance.ts +++ b/packages/host/src/Instance.ts @@ -18,7 +18,7 @@ const scriptCommands = [ "/cheat", "/editor", "/command", "/c", "/measured-command", "/mc", - "/silent-command", "/sc" + "/silent-command", "/sc", ]; const instanceRconCommandDuration = new lib.Histogram( @@ -876,7 +876,7 @@ rcon.print(game.table_to_json(players))`.replace(/\r?\n/g, " "); this._loadedSave = saveName; await this.server.start(saveName); - if (this.config.get("factorio.enable_save_patching")) { + if (this.config.get("factorio.enable_save_patching") && this.config.get("factorio.enable_script_commands")) { await this.server.disableAchievements(); await this.updateInstanceData(); } else { diff --git a/packages/lib/src/config/definitions.ts b/packages/lib/src/config/definitions.ts index db0b6da8..c26ddf56 100644 --- a/packages/lib/src/config/definitions.ts +++ b/packages/lib/src/config/definitions.ts @@ -433,7 +433,6 @@ export class InstanceConfig extends classes.Config { "Allows achievement breaking commands to be executed over rcon. " + "Required for Clusterio integrations and most plugins. " + "This does not prevent players using script commands.", - restartRequired: true, type: "boolean", initialValue: true, }, diff --git a/test/integration/clusterio.js b/test/integration/clusterio.js index 13b5669f..9b35c4f4 100644 --- a/test/integration/clusterio.js +++ b/test/integration/clusterio.js @@ -442,6 +442,10 @@ describe("Integration of Clusterio", function() { }); describe("instance send-rcon", function() { + this.afterAll(async function() { + // Prevents cascading failure where enable_script_commands is expected to be true + await execCtl("instance config set test factorio.enable_script_commands true"); + }); it("sends the command", async function() { slowTest(this); await execCtl("instance send-rcon test technobabble"); @@ -465,6 +469,24 @@ describe("Integration of Clusterio", function() { } assert(received, "InstanceSaveDetailsUpdatesEvent not sent"); }); + it("should prevent execution of script commands when disabled", async function() { + slowTest(this); + await execCtl("instance send-rcon test /c"); + const r1 = await getControl().send( + new lib.LogQueryRequest(false, false, [], [44], undefined, 10, "desc") + ); + assert(r1.log.some(info => /\[COMMAND\]/.test(info.message)), "Command was not sent"); + await execCtl("instance config set test factorio.enable_script_commands false"); + + assert.rejects( + execCtl("instance send-rcon test /c"), + new Error( + "Attempted to use script command while disabled. " + + "See config factorio.enable_script_commands.\nCommand: /c" + ) + ); + await execCtl("instance config set test factorio.enable_script_commands true"); + }); }); describe("instance config set-prop", function() { diff --git a/test/mock.js b/test/mock.js index d1c6b30d..47bba6aa 100644 --- a/test/mock.js +++ b/test/mock.js @@ -129,6 +129,7 @@ class MockInstance extends lib.Link { this.mockConfigEntries = new Map([ ["instance.id", 7357], ["factorio.enable_save_patching", true], + ["factorio.enable_script_commands", true], ]); this.config = { get: (name) => {