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

Sandbox Phase 2 - Java Container Feature#568h #592

Open
wants to merge 159 commits into
base: develop
Choose a base branch
from
Open

Conversation

danidiazd
Copy link
Collaborator

@danidiazd danidiazd commented Sep 20, 2024

Description

- Implemented a Chain of Responsibility with the following filters:

  • UnescapeJava: Replaces escaped characters that the Frontend must use to send the code to the Backend.
  • ASCIIFilter: Verifies that the code contains only valid ASCII characters (0-127).
  • HTMLSanitizer: Sanitizes the code to prevent possible HTML injection attacks.
  • KeywordFilter: Checks that the code does not contain reserved keywords that could pose a risk during execution.
  • SecurityFilter: Ensures that the code does not use libraries or modules that could be dangerous for execution.

- Created the DockerExecutor class
The DockerExecutor is responsible for launching a Docker container with a Java image to execute the user's code. It includes a method to terminate the container in case of issues such as infinite loops, and implements AutoCloseable to ensure proper resource management.
Used a openjdk:11-slim and apply a restrictive.policy to more security.

- Created the CodeProcessingManager class
The CodeProcessingManager manages the entire flow of processing user code. It first applies the chain of filters to validate the code, and if the filters pass, it invokes DockerExecutor to execute the code within a container. After execution, it performs the following steps to calculate the score:

Compilation Check: Verifies if the code compiled successfully.
Execution Check: Verifies if the code executed without errors.
Result Comparison: Compares the execution result with the expected output. The scoring logic handles different levels of accuracy:

  • Exact match with the expected result.
  • Partial match (i.e., the result contains the expected output).
  • No match (i.e., the result does not contain the expected output).
  • Don't compile the code.
  • Code compile but no execute.

Finally, it generates a ScoreResponse based on these checks and returns it to the controller.

Copy link

sonarcloud bot commented Oct 7, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Docker Docker enhancement New feature or request ita-score micro ita-score micro Level 3 Level 3
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sandbox Phase 2A - Creation a Sandbox using Docker container
7 participants