Bitbucket Cloud Code Insights Executor¶
Category: Source Code Analysis
Script: bitbucket_security.py
Integration: REST API
Faraday Plugin: Raw JSON
Website: https://support.atlassian.com/bitbucket-cloud/docs/code-insights/
Description¶
Imports Bitbucket Cloud Code Insights security reports for one commit into Faraday. Code Insights is the mechanism CI/CD pipelines (Snyk, JFrog, Checkmarx and others) use to post SAST results back to a Bitbucket repository, and each finding becomes a vulnerability on a host that represents the repository.
Prerequisites¶
- A Bitbucket Cloud workspace and repository with Code Insights reports posted against the commit you want to import
- A Bitbucket App Password (or Workspace/Project Access Token) with
repository:readscope
Configuration¶
Environment Variables (Setup)¶
| Variable | Required | Description |
|---|---|---|
BB_HOST |
No | Bitbucket Cloud API host (default: https://api.bitbucket.org). Change it only for a custom endpoint. |
BB_USER |
No | Bitbucket username paired with the app password. Not needed when BB_APP_PASSWORD is a Workspace/Project Access Token. |
BB_APP_PASSWORD |
Yes | Bitbucket Cloud App Password with repository:read scope, or a Workspace/Project Access Token |
These variables are also accepted as execution arguments, so a single run can override them.
Execution Arguments¶
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
BB_WORKSPACE |
string | Yes | Bitbucket Cloud workspace slug (e.g., mycompany) |
BB_REPO |
string | Yes | Repository slug (e.g., payments-api) |
BB_COMMIT |
string | Yes | Full 40-character commit SHA whose Code Insights reports should be imported |
BB_MIN_SEVERITY |
string | No | Minimum severity to import: info, low, medium, high or critical (default: info) |
BB_INCLUDE_NON_VULN |
string | No | Set to true to also import non-security annotations (code smells, bugs, tests). Default: only security/vulnerability findings. |
YAML Configuration Example¶
executors:
bitbucket_security:
repo_executor: bitbucket_security.py
max_size: 65536
varenvs:
BB_HOST: "https://api.bitbucket.org"
BB_USER: "<bb_user>"
BB_APP_PASSWORD: "<bb_app_password>"
params:
BB_WORKSPACE:
mandatory: true
type: string
base: string
BB_REPO:
mandatory: true
type: string
base: string
BB_COMMIT:
mandatory: true
type: string
base: string
BB_MIN_SEVERITY:
mandatory: false
type: string
base: string
BB_INCLUDE_NON_VULN:
mandatory: false
type: string
base: string
How It Works¶
- Authenticates with HTTP Basic (
BB_USER+BB_APP_PASSWORD), or as a Bearer token ifBB_APP_PASSWORDholds one - Reads the repository metadata for the host description
- Lists the Code Insights reports posted against
BB_COMMITand, for each SECURITY-type report (or every report ifBB_INCLUDE_NON_VULNis set), reads its annotations - Maps each annotation to a Faraday vulnerability:
- Name:
[SAST]followed by the annotation summary, for security-type reports and vulnerability annotations - Severity: the annotation's severity, or its CVSS score when present
- Status:
PASSEDbecomes closed,FAILED/SKIPPEDstay open,IGNOREDbecomes risk-accepted - Details: file and line location, CWE and OWASP references, and a link to the finding
- Name:
Notes¶
- The whole repository becomes one host with the IP
0.0.0.0and the hostname<workspace>/<repo>, because Code Insights findings belong to source code rather than IP addresses. - Only one commit is imported per run. Run the executor again for other commits (for example the HEAD of each branch or pull request).
- By default only SECURITY-type reports and
VULNERABILITYannotations are imported. SetBB_INCLUDE_NON_VULNto also bring in code smells, bugs and test results. - TLS certificates are not verified.
- The run stops if the app password is rejected (HTTP 401).
- The shared agent parameters (
AGENT_CONFIG_*tags and severity filters) are not applied by this executor. UseBB_MIN_SEVERITYto filter by severity.