Skip to content

Conversation

@p0wn4j
Copy link
Contributor

@p0wn4j p0wn4j commented Jan 23, 2021

In case of creating ScriptEngine by this way:
NashornScriptEngine engine = (NashornScriptEngine) factory.getScriptEngine(...);
engine.eval(input);
ScriptEngine.ql cannot detect this sink.

@p0wn4j p0wn4j requested a review from a team as a code owner January 23, 2021 14:55
@p0wn4j p0wn4j changed the title Java: Add NashornScriptEngine detection in ScriptEngine query Jan 24, 2021
@smowton
Copy link
Contributor

smowton commented Jan 25, 2021

Can you add this example as a test under the query's corresponding ql/test/experimental directory? I note the original query didn't include tests; it would be good to add a basic non-Nashorn test at the same time.

@p0wn4j
Copy link
Contributor Author

p0wn4j commented Jan 28, 2021

There is a problem with writing unit test because of Java 15.

@smowton
Copy link
Contributor

smowton commented Jan 28, 2021

What in particular? Nashorn is quite old, isn't it?

@p0wn4j
Copy link
Contributor Author

p0wn4j commented Jan 28, 2021

Yes it's removed from JDK15. Also calls with ScriptEngine are not compiling

@smowton
Copy link
Contributor

smowton commented Jan 28, 2021

So you may have noticed we use stubs when dealing with third-party libraries so that the tests can be built without shipping the lib's entire jar (e.g. https://github.com/github/codeql/tree/main/java/ql/test/stubs/apache-commons-io-2.6)

Even though this is a first-party package, does it suffice to provide some stubs and ensure those are on the classpath as we do for third-party libs?

@p0wn4j
Copy link
Contributor Author

p0wn4j commented Jan 28, 2021

Yeah, stubs helped, thanks.

@aschackmull
Copy link
Contributor

Error:     ql/java/ql/test/experimental/query-tests/security/CWE-094/ScriptEngine.qlref: Test failure (Expected output does not match)
@p0wn4j
Copy link
Contributor Author

p0wn4j commented Mar 4, 2021

Where can I see test output?

@aschackmull
Copy link
Contributor

CI logs are not currently public, but you can run it yourself with codeql test run java/ql/test/experimental/query-tests/security/CWE-094/ScriptEngine.qlref. The test output diff is rather long - it looks like most of the line numbers are off-by-one or something like that.

@p0wn4j
Copy link
Contributor Author

p0wn4j commented Mar 6, 2021

I have created a new pull request #5349

@p0wn4j p0wn4j closed this Mar 6, 2021
@p0wn4j p0wn4j deleted the fix-nashorn-engine branch March 6, 2021 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

3 participants