Skip to content
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

Implicit unpermitted operations should be sandboxed #791

Closed
alisevych opened this issue Aug 25, 2022 · 0 comments · Fixed by #838
Closed

Implicit unpermitted operations should be sandboxed #791

alisevych opened this issue Aug 25, 2022 · 0 comments · Fixed by #838
Assignees
Labels
ctg-bug Issue is a bug

Comments

@alisevych
Copy link
Member

alisevych commented Aug 25, 2022

Description

Unpermitted operations can be called implicitly. Need to sandbox them too.

  • in constructors of used classes
  • in static blocks
  • in private methods of other classes
  • in separate threads
  • ? probably, there are other cases to be added ?

To Reproduce

Steps to reproduce the behavior:

  1. Open IntelliJ IDEA with installed UTBot plugin (with Security Manager turned on)
  2. Open/create a project with JDK 8/11
  3. Add the following class:
import java.io.File;
import java.io.IOException;

class A {
    A () throws IOException {
        File a = new File("a.txt");
        a.createNewFile();
    }
}

public class SecurityCheck {

    public int read(A a)  {
        return 10;
    }
}
  1. Generate tests for the SecurityCheck.read method - with Mocking on

Expected behavior

Generated test is supposed to be disabled with sandbox-related comment.
No file must be created by user's code during test generation.

Actual behavior

Successful test is generated.
File "a.txt" is created during test generation.

Visual proofs (screenshots, logs, images)

    @Test
    @DisplayName("read: a = A() -> return 10")
    public void testReadReturns10() throws IOException {
        SecurityCheck securityCheck = new SecurityCheck();
        A a = new A();

        int actual = securityCheck.read(a);

        assertEquals(10, actual);
    }

image

Environment

IntelliJ IDEA 2022.1 - 2022.1.4
JDK 8/11

Additional context

Static blocks are being executed without sandbox either:

import java.io.File;

class A {
    static {
        new File("a.txt").renameTo(new File("b.txt"));
    }
}

public class AnotherCheck {

    public int read(A a)  {
        return 10;
    }

}
@alisevych alisevych added the ctg-bug Issue is a bug label Aug 25, 2022
@korifey korifey moved this to Todo in UTBot Java Aug 25, 2022
@alisevych alisevych changed the title Implicit unpermitted operations should be restricted by Security Manager Implicit unpermitted operations should be sandboxed Aug 25, 2022
Repository owner moved this from Todo to Done in UTBot Java Sep 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ctg-bug Issue is a bug
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants