# Track Learning and Move From Learn/Detect to Prevent

When [a new asset is added](https://docs.openappsec.io/getting-started/using-the-web-ui-saas/protect-additional-assets) it is recommended that open-appsec runs in Learn/Detect mode to allow it to create an initial baseline. When the [Contextual Machine Learning](https://docs.openappsec.io/concepts/contextual-machine-learning)  is properly configured and the application receives a substantial amount of traffic, the learning period takes about 2-3 days.&#x20;

Depending on amount and variance of traffic the machine learning engine will reach a stage where it has observed a sufficient amount of web requests to understand how the application is used. The faster this stage is reached, the faster detection is accurate and it is recommended to move to Prevent mode.

To speed up the learning period the [Contextual Machine Learning](https://docs.openappsec.io/concepts/contextual-machine-learning) engine proposes **tuning suggestions**. The administrator can review the tuning suggestions and help the engine reach even better accuracy, a Machine Learning process also known as supervised learning.

When a certain maturity level is reached, open-appsec will advice to move into **Prevent** mode. In this section you will understand how to track the learning level and how to optimize and tune the model for faster learning.

## Understand The Learning Level

When HTTP requests are inspected the open-appsec [Contextual Machine Learning](https://docs.openappsec.io/concepts/contextual-machine-learning) model will reach different learning levels. Each level represents the maturity of the learning model and helps to understand what it needs to reach the next level. It will also indicate when it is time to move from **Learn/Detect to Prevent** mode. The model progresses through the following learning levels:

![](https://1225393248-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNcZmX14M2KdTBrq9EOnI%2Fuploads%2FUf5eRfDBW7DUcJEo6xOw%2Fappsec-track-learning-learning-levels.png?alt=media\&token=baaccf0c-6497-4d0e-bbcc-1127bc7fcc7c)

When the learning level becomes **Graduate,** it is recommended to change the asset **Mode** to **Prevent** for either High confidence or above or Critical confidence events. Graduate level ensures very good level of accuracy (e.g. low amount of false positives).  To reach **Master** or **PhD** level is is necessary to [configure Trusted Sources](https://docs.openappsec.io/how-to/configuration-and-learning/configure-contextual-machine-learning-for-best-accuracy). The **Phd** level is the highest level, which means that more learning is less likely going to improve the model further.

#### Step 1: Track the learning level

![](https://1225393248-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNcZmX14M2KdTBrq9EOnI%2Fuploads%2FUBCMZCk0duZ9ejCdzeq6%2Fopenappsec-assets-web-application-learn.png?alt=media\&token=cf808954-7367-495a-8c51-be5ae8b3a74c)

1. Go to **Assets** and select the Asset you want to track.
2. Select the **Learn** tab. This tab shows the learning **statistics of the last 7 days**, the **Elapsed Time**, the **Learning Level** and the **Recommendation** at this level.
3. Hover over the **Learning Level** tooltip:information\_source: to learn the current learning level and the next level. It will also indicate what is required to reach the next level in the '**Watch next?'** section. Positive contributing factors to the learning process are: number of [trusted sources](https://docs.openappsec.io/how-to/configuration-and-learning/configure-contextual-machine-learning-for-best-accuracy) defined by the admin, time elapsed, amount of traffic inspected, amount of supervised learning suggestions and some other model parameters.&#x20;

{% hint style="info" %}
The example below shows that the machine learning is in **Kindergarten** level and needs 999 additional HTTP requests and 6 additional learning hours to reach **Primary School** level.
{% endhint %}

![](https://1225393248-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNcZmX14M2KdTBrq9EOnI%2Fuploads%2FiQcEVrIwXYn70EBXgpC8%2Fappsec-assets-edit-learn-learning-level.png?alt=media\&token=cab8ddf9-dfab-43d2-83b1-36559924a8df)

When an agent enforcing open-appsec first sees a connection to a web application/web API defined URL, a banner will also show at the top of the management web application to denote that "Learning has started":

![](https://1225393248-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNcZmX14M2KdTBrq9EOnI%2Fuploads%2Fc7qKWEBkMuOTyEy0Q8nG%2Fappsec-banner-learning-started.PNG?alt=media\&token=31012627-ee1c-4e2b-8b11-a2fa2455b5a3)

#### Step 2: Learn the recommended action

1. Hover over the **Recommendation** tooltip:information\_source: to learn what the current recommended action is for the asset. Recommendations include:

| Recommendation                         | Action Required                                                                                                                                                                                                                                   |
| -------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Keep Learning                          | No action required. The machine learning model requires additional HTTP requests (and additional time).                                                                                                                                           |
| Review Tuning Suggestions              | The learning mechanism generated tuning suggestions. Go to the [**Optimize Learning And Tuning**](#optimize-learning-and-tuning) section in this documentation to learn how to review them and decide whether the events are malicious or benign. |
| Prevent Critical Severity Events       | The system is ready to prevent critical severity events. Navigate to the **Threat Prevention** tab and change the Web Attacks practice Mode to **Prevent** for Critical Severity events.                                                          |
| Prevent High Severity And Above Events | The system is ready to prevent high severity (and above) events. Navigate to the **Threat Prevention** tab and change the Web Attacks practice Mode to **Prevent** for High and above Severity events.                                            |

{% hint style="info" %}
In the example below the **Recommendation** is Keep Learning and additional HTTP requests are required to reach the next learning level.
{% endhint %}

![](https://1225393248-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNcZmX14M2KdTBrq9EOnI%2Fuploads%2FL0SYUJZYjwWxieqyT3J7%2Fappsec-assets-edit-learn-recommendation-keep-learning.png?alt=media\&token=4138e106-8346-492a-9f05-96a9a2ce7e9c)

{% hint style="info" %}
Another example shows sufficient learning is achieved and the **Recommendation** is to Prevent High Severity And Above events. Since the Web Attack Practice is already in **Prevent** mode the tool tip shows a '**Well done!**' message.
{% endhint %}

![](https://1225393248-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNcZmX14M2KdTBrq9EOnI%2Fuploads%2F4NvxUtuVpP4xcp8GxRRh%2Fappsec-assets-edit-learn-recommendation-prevent.png?alt=media\&token=e47fe845-0d51-4de1-ab72-2478caf8afa5)

## Tuning Suggestions

The [Contextual Machine Learning](https://docs.openappsec.io/concepts/contextual-machine-learning) model may ask to review certain events, also called **Tuning Suggestions**. Providing feedback to these suggestions is not mandatory as the engine is capable of learning by itself. However doing this, allows the machine learning engine to reach a higher maturity level and therefore a better accuracy faster based on human guidance.&#x20;

#### Step 1: Review Tuning Suggestions

1. Go to **Assets** and select the Asset you want to review.
2. Select the **Learn** tab. This tab shows **Tuning Suggestions** and **Tuning Decisions**.
3. Review the proposed **Tuning Suggestions**.

![](https://1225393248-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNcZmX14M2KdTBrq9EOnI%2Fuploads%2FpNFDt7qbTmgDmNeWc9K1%2Fappsec-assets-learn-tuning-suggestions.png?alt=media\&token=980b3d4a-aeee-4769-8c8c-eabb1a2f2e31)

#### Step 2: Provide feedback to the proposed Tuning Suggestions

1. Click on the **Malicious** or **Benign** button next to the line of the Tuning Suggestion. Your Tuning Suggestion now moves to the **Tuning Decisions** list.

![](https://1225393248-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNcZmX14M2KdTBrq9EOnI%2Fuploads%2FC4I7Vb9JHArTh0VQaXQq%2Fappsec-assets-learn-tuning-decisions.png?alt=media\&token=c92c83fc-8d46-4ee5-b50f-0604c23c6921)

#### Step 3: Review the new recommended action

1. Go to [Step 2: Learn the recommended action](#step-2-learn-the-recommended-action) of the previous section to learn what to do next to improve the learning process.

## Move To Prevent Mode <a href="#moving_to_prevent_mode" id="moving_to_prevent_mode"></a>

Follow these actions when it is time to change the Practice mode from **Learn/Detect** to **Prevent**.&#x20;

1. Go to **Assets** and select the Asset you wish to Protect.
2. Select the **Learn** tab and examine the recommendation.&#x20;
3. Select the **Events** tab and examine Critical and High Events for the asset from the last 1-2 days.&#x20;
4. If needed, right-click on event and add **Exceptions** for traffic that the machine learning engine may have misclassified (exceptions can be added based on the `uri,` source identifier, parameter, and more). See more about this [here](https://docs.openappsec.io/setup-instructions/setup-custom-rules-and-exceptions).
5. Select the **Threat Prevention** tab and change the mode to **Prevent**
6. You can further tune the sensitivity to block either **High or above** or just **Critical** events.&#x20;
   * Set the level based on the recommendation in the **Learn** tab as well as your impression when looking at the events during the last day of the learning period.&#x20;
   * You can also start with **Critical** for few days, examine the events and then move to **High or above**.&#x20;
7. **Enforce** policy.
