Skip to content

Commit 3219768

Browse files
authored
[jrubyscripting] Disallow exec (openhab#18394)
If a script (or a library it calls) accidentally calls Process.exec Signed-off-by: Cody Cutrer <[email protected]>
1 parent c61686f commit 3219768

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

bundles/org.openhab.automation.jrubyscripting/src/main/java/org/openhab/automation/jrubyscripting/internal/JRubyScriptEngineConfiguration.java

+19
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ public void configureRubyEnvironment(ScriptEngine scriptEngine) {
300300
});
301301

302302
configureRubyLib(scriptEngine);
303+
disallowExec(scriptEngine);
303304
}
304305

305306
/**
@@ -322,6 +323,24 @@ private void configureRubyLib(ScriptEngine engine) {
322323
}
323324
}
324325

326+
private void disallowExec(ScriptEngine engine) {
327+
try {
328+
engine.eval("""
329+
def Process.exec(*)
330+
raise NotImplementedError, "You cannot call `exec` from within openHAB"
331+
end
332+
333+
module Kernel
334+
module_function def exec(*)
335+
raise NotImplementedError, "You cannot call `exec` from within openHAB"
336+
end
337+
end
338+
""");
339+
} catch (ScriptException exception) {
340+
logger.warn("Error preventing exec", unwrap(exception));
341+
}
342+
}
343+
325344
public List<String> getRubyLibPaths() {
326345
String rubyLib = get(RUBYLIB_CONFIG_KEY);
327346
if (rubyLib.isEmpty()) {

0 commit comments

Comments
 (0)