Olaf Gottschalk
11/04/2024, 10:56 AMScriptCompilationConfiguration
?
Does anybody know how to do it? Thanks!Piotr Krzemiński
11/04/2024, 11:14 AMimport java.io.File
fun main() {
println(File(".").absolutePath)
}
gives me
Exception in thread "main" java.security.AccessControlException: Access control exception due to security reasons in web playground:
access denied ("java.util.PropertyPermission" "user.dir" "read")
at java.lang.SecurityManager.checkPermission (:-1)
so I think JB uses Java's SecurityManager. I don't have experience with this, so just throwing it here as a likely hintPiotr Krzemiński
11/04/2024, 11:15 AMPiotr Krzemiński
11/04/2024, 11:17 AMOlaf Gottschalk
11/04/2024, 11:19 AMPiotr Krzemiński
11/04/2024, 11:21 AMPiotr Krzemiński
11/04/2024, 11:23 AMmikehearn
11/04/2024, 11:24 AMmikehearn
11/04/2024, 11:25 AMmikehearn
11/04/2024, 11:25 AMEl Anthony
11/04/2024, 12:02 PMOlaf Gottschalk
11/04/2024, 12:13 PMOlaf Gottschalk
11/04/2024, 12:14 PMPiotr Krzemiński
11/04/2024, 12:18 PMPiotr Krzemiński
11/04/2024, 12:21 PMOlaf Gottschalk
11/04/2024, 12:33 PMjsonTransformation {
set mandatory "name" type string map { it.lowercase() } from "NAME"
}
Given this transformation an incoming JSON {"NAME":"Olaf"}
would be transformed to {"name":"olaf"}
. Easy.
When my DSL code runs, the result of executing the function jsonTransformation(block: JsonTransformationDsl.()->Unit)
results in a callable of type (Map<String, Any?>) -> Map<String, Any?>
(my transformation) that then will be applied (called) on many, many sets of JSON data.
So, the business user has to define a transformation using the DSL above (which also supports a web interface). Because the DSL is plain Kotlin, it now also allows this hack:
jsonTransformation {
set mandatory "name" type string map { it.lowercase() } from "NAME"
set mandatory "env" to java.lang.System.getenv()
}
To expose the complete environment which might contain secrets into every transformed JSON...
Basically, within my DSL code that gets used, I need to restrict access to anything like java.lang.System
or java.io.File
. But I do not see how the ScriptCompilationConfiguration
would allow this.
A very very rudimentary approach I took was a hook on beforeCompilation
that scans for forbidden keywords and then fails the compilation. But disallowing plain "System" in my code would be too oversimplified. It would not allow
jsonTransformation {
set mandatory "System" from "sys"
}
when it finds the word "System"... :-)Piotr Krzemiński
11/04/2024, 12:53 PM@file:DependsOn(...)
that can do whatever they want, so this would need to be disabled as wellOlaf Gottschalk
11/04/2024, 1:09 PMPiotr Krzemiński
11/04/2024, 1:10 PMmikehearn
11/04/2024, 1:11 PMmikehearn
11/04/2024, 1:11 PMPiotr Krzemiński
11/04/2024, 1:12 PMOlaf Gottschalk
11/04/2024, 1:16 PMOlaf Gottschalk
11/04/2024, 1:17 PMmikehearn
11/04/2024, 1:21 PMmikehearn
11/04/2024, 1:21 PMmikehearn
11/04/2024, 1:21 PMOlaf Gottschalk
11/04/2024, 1:30 PMScriptCompilationConfiguration
...Piotr Krzemiński
11/04/2024, 1:33 PMcompileBinding
function accepts a list of source files and produces a path where .class files are put (it's ZIPped to create a JAR in a different place). I guess what you'd have to do is to just use the JS target to produce a JS file, and pass it to GraalJS this way: https://www.graalvm.org/javascript/#getting-started (haven't played with this yet, so just linking to their docs)Piotr Krzemiński
11/04/2024, 1:36 PMmikehearn
11/04/2024, 1:36 PMPiotr Krzemiński
11/04/2024, 1:38 PMK2JSCompiler
class and an associated K2JSCompilerArguments
Olaf Gottschalk
11/04/2024, 3:27 PMPiotr Krzemiński
11/04/2024, 5:22 PMOlaf Gottschalk
11/05/2024, 8:22 AMPiotr Krzemiński
11/05/2024, 8:25 AMhfhbd
11/10/2024, 3:55 PMPiotr Krzemiński
11/18/2024, 1:01 PM