-
Notifications
You must be signed in to change notification settings - Fork 196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[JENKINS-70108] CastBlock must contextualize invoker to avoid issues in mixed-trust scenarios #640
Conversation
…in mixed-trust scenarios
"Script1.super(Script1).setBinding(Binding)", | ||
"Script1.trusted", | ||
"Script1.foo()"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously, we would also intercept new File(String)
, which was wrong because the cast is in trusted code and so it should not be intercepted by the sandbox.
@@ -527,7 +527,7 @@ public void regexpOperator() throws Throwable { | |||
@Test | |||
public void arrayPassedToMethod() throws Throwable { | |||
assertEvaluate(4, "def m(x) {x.size()}; def a = [1, 2]; a.size() + m(a)"); // control case | |||
assertEvaluate(4, "def m(x) {x.size()}; def a = [1, 2].toArray(); a.length + m(List.of(a))"); // workaround #1 | |||
assertEvaluate(4, "def m(x) {x.size()}; def a = [1, 2].toArray(); a.length + m(Arrays.asList(a))"); // workaround #1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #635 (comment).
import java.util.List; | ||
import org.codehaus.groovy.runtime.InvokerInvocationException; | ||
import org.codehaus.groovy.runtime.ScriptBytecodeAdapter; | ||
|
||
public class CastBlock implements Block { | ||
public class CastBlock extends CallSiteBlockSupport { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I verified that this does not cause problems deserializing CastBlock
s serialized before this change.
* 1. Add a CallSiteBlock parameter to ContinuationGroup.castToBoolean, and use it to contextualize the invoker | ||
* used in that method. All Blocks that use the method would need to be updated to implement CallSiteBlock. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like the simplest option. Let me know if you think it's worth fixing. There are eight Block
s that would need to implement CallSiteBlock
if we make this change. The second option might be better in terms of reducing overall complexity, but it would be more complex to implement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fine to the extent I understand it.
See JENKINS-70108.
819cc9b introduced a new
Block
for casts,CastBlock
, which did not implementCallSiteBlock
and did not contextualize itsInvoker
. In cases where untrusted code calls trusted code that performs a cast, this could result in trusted code callingSandboxInvoker.cast
instead ofDefaultInvoker.cast
. In practical terms, this means that casts inside of global Pipeline libraries were sometimes incorrectly blocked by the sandbox.This PR makes
CastBlock
implementCallSiteBlock
so that it can contextualizeInvoker
correctly before performing the cast.TODO:
ContinuationGroup.castToBoolean
also need changes?asBoolean
method that is not allowed by the sandbox, so IDK if it matters in practice.