Skip to content

Introduce utbot taint analysis #1966

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

Merged
merged 8 commits into from
Jun 9, 2023
Merged

Introduce utbot taint analysis #1966

merged 8 commits into from
Jun 9, 2023

Conversation

mmvpm
Copy link
Collaborator

@mmvpm mmvpm commented Mar 16, 2023

Description

  • All changes are under UtSettings.useTaintAnalysis flag which is false by default (the user can change it in idea settings by checking the box "Use taint analysis")

    image
  • Taint analysis configuration are provided from resources utbot-framework/src/main/resources/taint/config.yaml and from custom user's file <path-to-user-project>/.idea/utbot-taint-config.yaml. To reduce parsing time, the first config is cached to the %TEMP%/UTBot/ directory

    image

  • The generated test which leads to TaintAnalysisError looks like

    @Test
    @DisplayName("process: log(data) : True -> DetectTaintAnalysisError")
    public void testProcess_AGreaterThanZero() {
        Example example = new Example();
    
        example.process(1);
        fail("'java.lang.String' marked 'sensitive-data' was passed into 'Example.log' method");
    }
  • The problems view tab with taint error

    image

How to test

Automated tests

org/utbot/taint/parser

Manual tests

  1. Open any project
  2. Enable taint analysis in IDEA settings by checking the box "Use taint analysis"
  3. Create the file .idea/utbot-taint-config.yaml
  4. Write the code and specify the rules according to configuration format https://github.com/UnitTestBot/UTBotJava/blob/main/docs/TaintAnalysis.md
  5. Run test generation

Sample code:

package org.utbot.examples.taint;

public class Example {

    private String getPassword() { return "password"; }

    private void log(String text) { System.out.println(text); }

    public void process(int a) {
        String data = "";
        if (a > 0) {
            data = getPassword();
        }
        log(data);
    }
}

Sample config:

sources:
  - org.utbot.examples.taint.Example.getPassword:
      add-to: return
      marks: sensitive-data

sinks:
  - org.utbot.examples.taint.Example.log:
      check: arg1
      marks: sensitive-data

Self-check list

  • I've set the proper labels for my PR (at least, for category and component).
  • PR title and description are clear and intelligible.
  • I've added enough comments to my code, particularly in hard-to-understand areas.
  • The functionality I've repaired, changed or added is covered with automated tests.
  • Manual tests have been provided optionally.
  • The documentation for the functionality I've been working on is up-to-date.

@mmvpm mmvpm added ctg-enhancement New feature, improvement or change request comp-taint-analysis labels Mar 16, 2023
@mmvpm mmvpm self-assigned this Mar 16, 2023
@mmvpm mmvpm force-pushed the ideaseeker/uta_draft branch from 8b446b0 to a2a9c32 Compare April 4, 2023 11:50
@mmvpm mmvpm changed the title Draft: Introduce utbot taint analysis Introduce utbot taint analysis Apr 5, 2023
@mmvpm mmvpm force-pushed the ideaseeker/uta_draft branch from ef50dba to 90ecb92 Compare April 5, 2023 10:56
@mmvpm mmvpm changed the title Introduce utbot taint analysis Draft: Introduce utbot taint analysis Apr 5, 2023
@mmvpm mmvpm force-pushed the ideaseeker/uta_draft branch from 90ecb92 to 501bb1c Compare April 5, 2023 12:01
@mmvpm mmvpm force-pushed the ideaseeker/uta_draft branch from 3a9612b to 9a52264 Compare May 30, 2023 10:36
@mmvpm mmvpm force-pushed the ideaseeker/uta_draft branch 3 times, most recently from d82460c to 0bccb4f Compare June 8, 2023 06:49
@mmvpm mmvpm requested a review from CaelmBleidd June 8, 2023 06:52
Copy link
Member

@CaelmBleidd CaelmBleidd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed verbally

@mmvpm mmvpm force-pushed the ideaseeker/uta_draft branch 3 times, most recently from b364e6c to 0698fb3 Compare June 8, 2023 13:05
@mmvpm mmvpm changed the title Draft: Introduce utbot taint analysis Introduce utbot taint analysis Jun 8, 2023
@alisevych
Copy link
Member

As an enhancement suggestion:
Empty <path-to-user-project>/.idea/utbot-taint-config.yaml file can be generated when user enables Taint analysis setting in the project. That can be done when EmptyYamlDocumentException is handled.

@mmvpm mmvpm force-pushed the ideaseeker/uta_draft branch from 0698fb3 to 9f2d100 Compare June 9, 2023 09:09
Copy link
Member

@CaelmBleidd CaelmBleidd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, add documentation for the added options

@mmvpm mmvpm force-pushed the ideaseeker/uta_draft branch from fbc5d4e to a142d8d Compare June 9, 2023 12:40
Copy link
Member

@CaelmBleidd CaelmBleidd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mmvpm mmvpm enabled auto-merge (squash) June 9, 2023 12:44
@mmvpm mmvpm merged commit 90f384e into main Jun 9, 2023
@mmvpm mmvpm deleted the ideaseeker/uta_draft branch June 9, 2023 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp-taint-analysis ctg-enhancement New feature, improvement or change request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants