Skip to content

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:read scope

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

  1. Authenticates with HTTP Basic (BB_USER + BB_APP_PASSWORD), or as a Bearer token if BB_APP_PASSWORD holds one
  2. Reads the repository metadata for the host description
  3. Lists the Code Insights reports posted against BB_COMMIT and, for each SECURITY-type report (or every report if BB_INCLUDE_NON_VULN is set), reads its annotations
  4. 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: PASSED becomes closed, FAILED/SKIPPED stay open, IGNORED becomes risk-accepted
    • Details: file and line location, CWE and OWASP references, and a link to the finding

Notes

  • The whole repository becomes one host with the IP 0.0.0.0 and 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 VULNERABILITY annotations are imported. Set BB_INCLUDE_NON_VULN to 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. Use BB_MIN_SEVERITY to filter by severity.