doc/user/application_security/dependency_scanning/experiment_libbehave_dependency.md
{{< details >}}
{{< /details >}}
Libbehave is an experimental feature that scans your dependencies during merge request pipelines to identify newly added libraries and their potentially risky behaviors. While traditional dependency scanning looks for known vulnerabilities, Libbehave gives insight into what features and behaviors your dependencies exhibit.
Each feature detected by Libbehave is assigned a "riskiness" score of either:
Features that Libbehave detects include:
For demos of Libbehave for each supported package manager type, see our Libbehave demo projects.
The following languages and package managers are supported by Libbehave:
Directory.Build.props files (replacing property values if found)*.deps.json files**/*.dll and **/*.exe filesgo.mod filespom.xml files (replacing property values if found)**/gradle.lockfile* files**/package-lock.json files**/yarn.lock files**/pnpm-lock.yaml files**/*requirements*.txt files**/poetry.lock files**/Pipfile.lock files**/setup.py files**/*dist-info/METADATA, **/*egg-info/PKG-INFO, **/*DIST-INFO/METADATA, and
**/*EGG-INFO/PKG-INFO files**/installed.json files**/composer.lock files**/php/.registry/.channel.*/*.reg" files**/Gemfile.lock files**/specifications/**/*.gemspec files**/*.gemspec filesThe previous files are analyzed for new dependencies only if the files have been modified in the source branch.
Prerequisites:
To enable Libbehave:
In the top bar, select Search or go to and find your project.
Select Code > Repository.
Select the .gitlab-ci.yml file.
Select Edit > Edit single file.
Add the Libbehave CI/CD components:
include:
- component: $CI_SERVER_FQDN/security-products/experiments/libbehave/[email protected]
inputs:
stage: test
Select Commit changes.
This configuration creates a new job called libbehave-experiment in the test stage.
To configure merge request comments for Libbehave, configure a project access token.
Prerequisites:
To configure merge request comments:
In the top bar, select Search or go to and find your project.
Select Settings > Access tokens.
Select Add new token and complete the fields:
libbehave-bot.Select Create project access token.
Copy the project access token to your clipboard. It's required in the next step.
Select Settings > CI/CD.
Expand Variables.
Select Add variable and complete the fields:
BEHAVE_TOKEN.Select Add variable.
The CI/CD component automatically uses the BEHAVE_TOKEN so you do not need to specify it in the
component inputs.
[!note] Merge request comments appear only when the source branch is either a protected branch or when the Protect variable option is unchecked for the
BEHAVE_TOKENvariable.
You can use CI/CD variables to customize the CI component of Libbehave.
The following variables configure the behavior of how Libbehave runs.
| CI/CD variable | CLI argument | Default | Description |
|---|---|---|---|
CI_MERGE_REQUEST_SOURCE_BRANCH_NAME | -source | "" | Source branch to diff against (for example, feature-branch) |
CI_MERGE_REQUEST_TARGET_BRANCH_NAME | -target | "" | Target branch to diff against (for example, main) |
BEHAVE_TIMEOUT | -timeout | "30m" | Maximum time allowed to analyze and download packages (example: 30m) |
BEHAVE_TOKEN | -token | "" | Optional. Access token (required to create a merge request comment) |
CI_PROJECT_ID | -project | "" | Optional. Project ID to create a merge request note with results |
CI_MERGE_REQUEST_IID | -mrid | "" | Optional. Merge request ID to create a merge request note with results |
The following flags are available, but are untested and should be left at their default values:
| CI/CD variable | CLI argument | Default | Description |
|---|---|---|---|
BEHAVE_RULE_PATHS | -rules | "/dist" | The path to the rule files. |
BEHAVE_TARGET_DIR | -dir | "" | The target directory to run behave against. |
BEHAVE_NO_GIT_IGNORE | -no-git-ignore | true | Whether to scan files in .gitignore. Providing the argument will not scan them, by default it will. |
BEHAVE_OUTPUT_PATH | -output | "behaveout" | The path to store scan results, extracted artifacts and report results. |
BEHAVE_INCLUDE_LANG | -include-lang | "" | Include a language, one of: csharp, go, java, js, php, python, or ruby, separated by ',' excludes all others not specified. |
BEHAVE_EXCLUDE_LANG | -exclude-lang | "" | Exclude a language, one of: csharp, go, java, js, php, python, or ruby, separated by ',', includes all others not specified. |
BEHAVE_EXCLUDE_FILES | -exclude- | "" | Exclude files or paths by regular expressions, individual regular expressions are separated by ','. |
Because all variables have not been tested, you may find some that work and others that do not. If you need one that does not work, submitting a feature request or contributing to the code to enable it to be used.
Libbehave analyzes and reports findings on any newly added dependencies and is meant to run in merge request pipelines. That means if your merge request does not include any new dependencies, then Libbehave returns zero results.
Detection works differently, depending on the language and package manager used. By default, those supported package managers have their package manager related files parsed to identify which dependencies are being added. This information is gathered and then used to call out to the respective package manager API to download the identified package's artifacts.
After they're downloaded, the dependencies are extracted and analyzed using static analysis methods based on Semgrep, with a configured set of checks.
In the case of Java and C#, an additional step is taken to decompile the binary artifacts prior to running static analysis.
Each language has its own known issues.
All package files such as Gemfile.lock and requirements.txt must provide explicit versions.
Version ranges are not supported.
.props or .csproj files do not account for nested project files.
It replaces any variable that matches a global set of extracted variables and their values.pom.xml files.bdist_wheel package which may not match the target OS.Libbehave produces the following output:
The job summary requires no extra configuration and will always be presented after a successful analysis.
Example of what the Job Summary output looks like:
# Job output #
[=== libbehave: New packages detected ===]
šŗ 4 new packages have been detected in this MR.
[= java - open-vulnerability-clients 6.1.7 =]
The https://mvnrepository.com/artifact/io.github.jeremylong/open-vulnerability-clients package was found to exhibit the following behaviors:
- š§ GzipReadArchive (Risk: Medium)
-----------------
[= java - jdiagnostics 1.0.7 =]
The https://mvnrepository.com/artifact/org.anarres.jdiagnostics/jdiagnostics package was found to exhibit the following behaviors:
- š„ CryptoMD5 (Risk: High)
- š§ WriteFile (Risk: Medium)
- š§ ReadFile (Risk: Medium)
- š§ ReadEnvVars (Risk: Medium)
-----------------
[= java - commons-dbcp2 2.12.0 =]
The https://mvnrepository.com/artifact/org.apache.commons/commons-dbcp2 package was found to exhibit the following behaviors:
- š„ JavaObjectSerialization (Risk: High)
- š§ Passwords (Risk: Medium)
-----------------
[= java - jmockit 1.49 =]
The https://mvnrepository.com/artifact/org.jmockit/jmockit package was found to exhibit the following behaviors:
- š„ JavaObjectSerialization (Risk: High)
- š§ WriteFile (Risk: Medium)
- š§ ReadFile (Risk: Medium)
- šØ CryptoRAND (Risk: Low)
-----------------
The MR comment summary output requires an access token with Guest level access be created for the project that the Libbehave component has been configured for. The access token should then be configured for the project. Because feature branches are not protected by default, ensure the Protect variable setting is cleared. Otherwise the Libbehave job cannot read the access token's value.
The HTML artifact will appear in your jobs artifacts output (behaveout/gl-libbehave.html) and
should be accessible in your job artifact downloads.
Libbehave does not work in offline environments as it pulls down dependencies directly from the various package managers.
If the Libbehave job is not run, ensure your project is configured to run merge request pipelines.
This is usually due to the BEHAVE_TOKEN not being set. Ensure the access token has Guest level
access and the Protect variable option is unchecked in the Settings > CI/CD variables
settings.
{401 Permission Denied}This is usually due to the BEHAVE_TOKEN not containing the correct value. Ensure the access token
has Guest level access.