> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/sast-and-sca/prezero/autofix.md).

# AutoFix

<<<<<<< HEAD

## AutoFix <a href="#autofix" id="autofix"></a>

\=======

## AutoFix

> > > > > > > 360f0d79472b206ce2e1e63b6fd69717487dacce

{% hint style="info" %}
This capability is not enabled by default. Please contact Customer Success if you need assistance.
{% endhint %}

Qwiet AI AutoFix uses large language models (LLMs) to generate potential code fix suggestions for findings produced by Qwiet AI by Harness analyses. In addition to code changes, AutoFix also provides steps to address the vulnerability findings.

AutoFix suggestions are provided in context of a particular analysis and the existing application source code. To generate the fix, the LLM uses data available in the Code Property Graph (CPG) generated during the application analysis, including relevant source code snippets captured only when this capability is enabled. Qwiet AI AutoFix LLMs are deployed in Qwiet AI's virtual private cloud, and none of the data is shared with any third party.

{% hint style="info" %}
Qwiet AI does NOT do any model training with customer data
{% endhint %}

AutoFix suggestions are generated automatically while the application is being analyzed in the cloud. This is an asynchronous process, and will not slow down the reporting of findings. Suggestions might take several seconds to be available for a particular finding. At the moment, AutoFix suggestions are generated for the top ten SAST findings for each application, sorted by severity in descending order (critical, high, medium, low).

### Limitations <a href="#limitations" id="limitations"></a>

Users must always consider the limitations of AI and review and edit the suggestion or pull request to ensure that the resulting code and application are correct, secure, performant, compliant, etc.

Qwiet AI AutoFix capability has the following known limitations:

* The system primarily uses English data. If code and comments are written in other languages, the quality of the suggestions might be diminished
* The AutoFix suggestion might contain code that is not syntactically correct. Linters and proper test coverage should help mitigate this issue
* AutoFix suggestions might change the semantics of the application. Good test coverage should help mitigate this issue
* Some AutoFix suggestions might not fix or resolve the vulnerability finding, and in some cases it might introduce additional issues. Review suggestions carefully

### Viewing and using AutoFix suggestions <a href="#viewing-and-using-autofix-suggestions" id="viewing-and-using-autofix-suggestions"></a>

The main goal of Qwiet AI AutoFix suggestions is to help software developers and security practitioners fix vulnerability findings faster.

AutoFix suggestions generally include the updated code and steps to address the vulnerability finding. The user can copy the code and paste it in an IDE or code editor, verify that the code works as intended, and then re-analyze the application. The user can also ignore the code and use the steps to address the finding to write their own code, and then re-analyze the application. A combination of both approaches could also work well.

To view an AutoFix suggestion, click on a finding in the Vulnerabilities tab in the application details page, and then click on the **AutoFix** tab.

![Finding Details AutoFix panel](https://1323456121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHJwuqV3Cg06KbulvSaUS%2Fuploads%2Fgit-blob-62ebecc45c7947d87d7c7556cf34c35cf905d358%2Fautofix-autofix-bbced32c42.png?alt=media)

To help streamline the amount of information displayed, you can toggle on **Qwiet the Noise**, which filters for only **critical** and **high** severity vulnerabilities. You can also enable the **AutoFix Available** filter, which lists only findings that have an AutoFix suggestion available.

Please provide feedback by scrolling down to the bottom of the AutoFix suggestion panel, and clicking the thumbs up/down button. Optionally, select a reason for the thumbs up/down, type in additional feedback, and click the *Submit* button.

![Finding Details AutoFix rating form](https://1323456121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHJwuqV3Cg06KbulvSaUS%2Fuploads%2Fgit-blob-b0c1e529087d466e6e8ad62c21eeb3b71c280ccd%2Fautofix-autofix-rating-a717dfe7ee.png?alt=media)

### Agentic Workflow <a href="#agentic-workflow" id="agentic-workflow"></a>

By default, the AutoFix capability is powered by multiple AI agents. These agents collaborate with each other to provide a final result for the user, as well as individual results that could help in the resolution of a finding.

The final result appears at the top of the AutoFix tab, and it's usually provided by **Catherine AppSec Team Lead** or **Nova Refactoring Engineer** (for cases where a code refactoring was necessary).

To view additional results, scroll down and click on **View results from other agents >>**.

![Agentic Workflow](https://1323456121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHJwuqV3Cg06KbulvSaUS%2Fuploads%2Fgit-blob-8cc3979e521a0fa23f7e21aa2e41628d935e5f1f%2Fautofix-agentic-workflow-c91451a78e.png?alt=media)

The following agents are currently available:

* **Scout Threat Analyst**: Cybersecurity expert. Identifies potential attack vectors in vulnerable code and generates attack payloads
* **Toby Test Engineer**: Cybersecurity expert and Quality Assurance Engineer. Generates test cases based on attack payloads provided by Scout
* **Clara AppSec Engineer**: Application Security Engineer. Analyzes mitigation notes and test cases provided by Toby and fixes the code accordingly
* **Evan Security Engineer**: Security expert and Software Engineer. Examines the vulnerable code and provides notes suggesting a more effective and improved approach that mitigates the vulnerability
* **Hal Dependency Inspector**: Software and Security Engineer. Assesses the reliability of the dependencies/imports suggested in the fixed code
* **Nova Refactoring Engineer**: Refactoring Engineer. Identifies and rectifies dependency issues, refactoring the code as necessary
* **Catherine AppSec Team Lead**: AppSec team lead. Reviews results from other agents in the team and fixes any additional issues, ensuring that every piece of code maintains high standards of efficiency and security

### Enabling or disabling AutoFix suggestions <a href="#enabling-or-disabling-autofix-suggestions" id="enabling-or-disabling-autofix-suggestions"></a>

AutoFix can be configured at the organization level in the [Organization Settings](https://app.shiftleft.io/organization/settings) page. Use the **Enable AutoFix** toggle to turn the feature on or off. When enabled, AutoFix will work for all applications in the organization unless it's explicitly disabled, since the default application setting for AutoFix is **Inherit** (see below).

![Organization Settings](https://1323456121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHJwuqV3Cg06KbulvSaUS%2Fuploads%2Fgit-blob-d18faf8fbcadd5014e37254ca195501d217a5079%2Fautofix-autofix-org-settings-6fbe7d4bc7.png?alt=media)

Autofix can also be configured at the application level, in each application's Settings page. The AutoFix section has three options: **Inherit** (which is the default), **Enable**, and **Disable**. When the **Inherit** option is selected, AutoFix will be enabled or disabled for this application based on the organization settings. When **Enable** or **Disable** are selected, Autofix will be enabled or disabled irrespective of the organization settings.

![Application Settings](https://1323456121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHJwuqV3Cg06KbulvSaUS%2Fuploads%2Fgit-blob-5d79823e8c48f8d765fb51ad3dd09777a30ba021%2Fautofix-autofix-app-settings-6f81c7f069.png?alt=media)

### AutoFix Pull Requests <a href="#autofix-pull-requests" id="autofix-pull-requests"></a>

{% hint style="info" %}
AutoFix pull requests work with **GitHub**, **Azure DevOps**, **BitBucket** and **Harness** repositories. Additional providers will be available at a later time.
{% endhint %}

AutoFix can manually or automatically submit a [pull request](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests) once an application analysis is completed and AutoFix suggestions are available. Note that if the pull request remains open, subsequent analyses will amend the existing pull request, instead of creating a new one. This behavior can be changed by choosing **Create Standalone Pull Request** when creating a Pull Request.

![Application Findings - Create Standalone Pull Request](https://1323456121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHJwuqV3Cg06KbulvSaUS%2Fuploads%2Fgit-blob-f987da2fcfd1774b15c2ed7bb2354aa640eac7c1%2Fautofix-create-standalone-pull-request-fba55bdeda.png?alt=media)

Once a pull request is created by AutoFix, it can be treated as a normal pull request (e.g. reviewed, approved, receive additional commits).

To enable this functionality, you will need to provide following credentials:

#### Github Repositories <a href="#github-repositories" id="github-repositories"></a>

1. Owner (GitHub organization)
2. [Personal Access Token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens)

The following scopes are required for **Tokens (classic)**:

* `repo`

The following scopes are required for **Fine-grained tokens**:

<<<<<<< HEAD

* `Read and Write access to pull requests`
* `Read access to metadata` (automatically added by GitHub) =======
* `Read and Write access to pull requests`
* `Read access to metadata` (automatically added by GitHub)

> > > > > > > 360f0d79472b206ce2e1e63b6fd69717487dacce

{% hint style="info" %}
Please note that if your GitHub organization has SAML SSO enabled (e.g. GitHub Enterprise Managed Users), you must [authorize the PAT](https://docs.github.com/en/enterprise-cloud@latest/authentication/authenticating-with-saml-single-sign-on/authorizing-a-personal-access-token-for-use-with-saml-single-sign-on) after its creation before it can access repositories in the organization.
{% endhint %}

#### Azure DevOps Repos <a href="#azure-devops-repos" id="azure-devops-repos"></a>

<<<<<<< HEAD

1. Owner (Azure DevOps organization)
2. [Personal Access Token](https://learn.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=azure-devops\&tabs=Windows#create-a-pat) =======
3. Owner (Azure DevOps organization)
4. [Personal Access Token](https://learn.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=azure-devops\&tabs=Windows#create-a-pat)

> > > > > > > 360f0d79472b206ce2e1e63b6fd69717487dacce

{% hint style="info" %}
Azure DevOps PAT should have minimum **Code: Read & Write** scopes.
{% endhint %}

#### BitBucket <a href="#bitbucket-repositories" id="bitbucket-repositories"></a>

AutoFix pull requests are supported for Bitbucket repositories. You can configure AutoFix to create pull requests for repositories hosted in **BitBucket Cloud** or **BitBucket DataCenter**.

<<<<<<< HEAD

{% hint style="info" %}

* Access token can be created at [repository](https://support.atlassian.com/bitbucket-cloud/docs/create-a-repository-access-token/) level, [project](https://support.atlassian.com/bitbucket-cloud/docs/create-a-project-access-token/) level or [workspace](https://support.atlassian.com/bitbucket-cloud/docs/create-a-workspace-access-token/) level.
* The name of the token set (i.e. **Harness SAST and SCA**) will be used as the author name and shown in Commit history / Pull request updates.
* Token must have **pullrequest:write** scope.
  {% endhint %}

#### Harness Code Repos <a href="#harness-code-repos" id="harness-code-repos"></a>

1. Owner (Repo Owner's Account ID)
2. [Personal Access Token](/harness-ai/use-harness-platform/automation/api/api-quickstart.md#create-a-harness-api-key-and-token) or [Service Account Token](/harness-ai/use-harness-platform/automation/api/add-and-manage-api-keys.md#create-service-account-api-keys-and-tokens) ======= The configuration requirements differ depending on where your Bitbucket repositories are hosted. The following tabs provide configuration instructions for the different types of Bitbucket repositories:

{% tabs %}
{% tab title="BitBucket Cloud repositories" %}

1. Owner (BitBucket workspace)
2. Access Token

{% hint style="info" %}

* Access token can be created at [repository](https://support.atlassian.com/bitbucket-cloud/docs/create-a-repository-access-token/) level, [project](https://support.atlassian.com/bitbucket-cloud/docs/create-a-project-access-token/) level or [workspace](https://support.atlassian.com/bitbucket-cloud/docs/create-a-workspace-access-token/) level.
* The name of the token set (i.e. **Harness SAST and SCA**) will be used as the author name and shown in Commit history / Pull request updates.
* Token must have **pullrequest:write** scope.
  {% endhint %}
  {% endtab %}

{% tab title="BitBucket DataCenter repositories" %}
Configuring AutoFix for Bitbucket DataCenter repositories requires additional connection details to connect to your self-hosted Bitbucket DataCenter instance. You must provide the URL of your Bitbucket DataCenter instance, the project key, and a user’s Personal Access Token with the required permissions.

{% hint style="info" %}
AutoFix supports Bitbucket Data Center **7.0 and later**. Instances running an earlier version are not supported.
{% endhint %}

To configure AutoFix pull requests for Bitbucket Data Center repositories, complete the following steps:

1. Navigate to your onboarded Qwiet application. For more information on onboarding an application, go to [Quickstart](https://developer.harness.io/sast-and-sca/getting-started/quickstart/quickstart).\
   The **Scans** tab opens by default.
2. Select the **Settings** tab to configure the application settings.
3. Scroll down to find the **BitBucket DataCenter** collapsible under **Pull Request Credentials**.
4. Click the **Expand** button next to **BitBucket DataCenter** to view its configuration options.
5. Under **Personal Access Token**, enter the following details:
   * Enter the **Project Key** in the **Owner** field.
   * Enter the **Base URL** of your BitBucket DataCenter instance in the `https://<host>[:<port>][/<context-path>]` format.
   * Enter the **Personal Access Token** for your BitBucket account in the **Token** field. For more information on creating a Personal Access Token, go to [Personal access tokens](https://confluence.atlassian.com/bitbucketserver0717/personal-access-tokens-1087535496.html).

{% hint style="info" %}
The Personal Access Token must have `REPO_WRITE` permission.
{% endhint %}

<figure><img src="https://1323456121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHJwuqV3Cg06KbulvSaUS%2Fuploads%2FDOaMjirCmuIb5bVaJnqy%2Fbitbucket-datacenter-repositories.png?alt=media&amp;token=abbaa741-621f-4103-84e1-411bab89b8d9" alt="BitBucket DataCenter Repositories Configuration"><figcaption></figcaption></figure>
{% endtab %}
{% endtabs %}

#### Harness Code Repos <a href="#harness-code-repos" id="harness-code-repos"></a>

1. Owner (Repo Owner's Account ID)
2. [Personal Access Token](/harness-ai/use-harness-platform/automation/api/api-quickstart.md#create-a-harness-api-key-and-token) or [Service Account Token](/harness-ai/use-harness-platform/automation/api/add-and-manage-api-keys.md#create-service-account-api-keys-and-tokens)

> > > > > > > 360f0d79472b206ce2e1e63b6fd69717487dacce

{% hint style="info" %}
The Harness Service Account Token should have minimum **Users:view** and **Repository:view, review, push** permissions. The built-in **Code Contributor** role has all these permissions.
{% endhint %}

#### Configuring PAT Credentials <a href="#configuring-pat-credentials" id="configuring-pat-credentials"></a>

These credentials can be provided at the user, application, team, and organization levels. AutoFix will look for the credentials in the following order:

1. User
2. Application
3. Team
4. Organization

For example: if the credentials are provided in an Application's settings, in the application's Team settings, and in Organization's Settings, but not provided for the organization user, it will use the PAT provided in the Application's settings and ignore any Team and Organization credentials.

Note that only the following roles or custom roles with the `autofix_pat:read` scope can read a PAT and use it to create an AutoFix Pull Request:

* Organization
  * Owner
  * Super admin
  * Power user
* Team
  * Team admin
  * Team manager
  * Team developer

See the [User permissions](/sast-and-sca/prezero/users/permissions.md) page for additional details about permissions.

#### Organization-level PAT configuration <a href="#organization-level-pat-configuration" id="organization-level-pat-configuration"></a>

For the Organization, provide PAT credentials in the **Enable AutoFix** section of the [Organization Settings](https://app.shiftleft.io/organization/settings) page.

You can choose whether the pull request should be created automatically (default) or manually with the **Create Pull Request** button, when reviewing findings that have an AutoFix suggestion available. Go to [Viewing and using AutoFix suggestions](#viewing-and-using-autofix-suggestions) to see an example.

![Organization Settings - AutoFix Pull Requests](https://1323456121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHJwuqV3Cg06KbulvSaUS%2Fuploads%2Fgit-blob-df9ef923b1c5e08b03e560e96211689ea0e49674%2Fautofix-automatic-pull-requests-settings-2cfd301ba8.png?alt=media)

#### Team-level PAT configuration <a href="#team-level-pat-configuration" id="team-level-pat-configuration"></a>

For teams, provide the PAT credentials in the [Manage Teams](https://app.shiftleft.io/organization/teams) page by clicking on the Pull Requests button.

![Manage Teams page - AutoFix Pull Requests settings](https://1323456121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHJwuqV3Cg06KbulvSaUS%2Fuploads%2Fgit-blob-ab2cfd88e1e39dbb5dd6aa2e2de736488d4d35a5%2Fautofix-team-pull-requests-settings-d22800b74d.png?alt=media)

#### Application-level PAT configuration <a href="#application-level-pat-configuration" id="application-level-pat-configuration"></a>

For apps, provide the GitHub credentials in the **Application Settings** page, under the **AutoFix** section.

![Application Settings page - AutoFix settings](https://1323456121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHJwuqV3Cg06KbulvSaUS%2Fuploads%2Fgit-blob-2bccee3ae05d4d3affec9f17e8c802ad0865d8f4%2Fautofix-app-pull-requests-settings-d67690668f.png?alt=media)

#### User-level PAT configuration <a href="#user-level-pat-configuration" id="user-level-pat-configuration"></a>

Users can provide their PAT credentials in the **Organization Overview** page, under the **User Information** section.

![Organization Overview page - User Information PAT](https://1323456121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHJwuqV3Cg06KbulvSaUS%2Fuploads%2Fgit-blob-cded899cade3db565c2a3790a8428f50dbc81f6d%2Fautofix-user-pull-requests-settings-a2192a913d.png?alt=media)

### Supported languages <a href="#supported-languages" id="supported-languages"></a>

Qwiet AI AutoFix is available for applications written in the following programming languages:

* Apex
* C#
* Go
* Java
* JavaScript
* PHP
* PL/SQL
* Python
* Terraform
* TypeScript

Coming soon:

<<<<<<< HEAD

* C/C++
* Groovy
* Ruby
* Swift =======
* C/C++
* Groovy
* Ruby
* Swift

> > > > > > > 360f0d79472b206ce2e1e63b6fd69717487dacce

{% hint style="info" %}
In most cases, only the latest "src" CPG frontend is supported (e.g. `--jssrc` instead of `--js`, `--javasrc` instead of `--java`, `--pythonsrc` instead of `--python`). This is the default behavior when language detection is in use.
{% endhint %}

For further assistance or inquiries, please contact your Customer Success representative.

{% @harness-feedback/feedback %}
