├── .gitignore ├── scripts ├── github-event.json └── run-container-locally.sh ├── src ├── artifacts.js ├── report.js ├── matchers.js ├── report │ └── report.template ├── request.js ├── index.js ├── checks.js ├── severities.js ├── local-scanner.js ├── config.js └── scan.js ├── Dockerfile ├── .github ├── CODEOWNERS ├── workflows │ ├── validate.yaml │ └── release.yaml └── actions │ └── build-image │ └── action.yaml ├── eslint.config.mjs ├── package.json ├── action.yml ├── README.md └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | target 3 | log 4 | results.sarif 5 | scan-summary.json 6 | .contrast-scan/ 7 | .vscode -------------------------------------------------------------------------------- /scripts/github-event.json: -------------------------------------------------------------------------------- 1 | { 2 | "ref": "refs/local/test", 3 | "repository": { 4 | "default_branch": "test" 5 | } 6 | } -------------------------------------------------------------------------------- /src/artifacts.js: -------------------------------------------------------------------------------- 1 | const request = require("./request"); 2 | 3 | async function getArtifacts(version = "latest") { 4 | return await request(`/release-artifacts/local-scanner/${version}`); 5 | } 6 | 7 | module.exports = getArtifacts; 8 | -------------------------------------------------------------------------------- /src/report.js: -------------------------------------------------------------------------------- 1 | const Mustache = require("mustache"); 2 | const fs = require("fs"); 3 | const path = require("path"); 4 | 5 | const REPORT_TEMPLATE = fs 6 | .readFileSync(path.join(__dirname, "report", "report.template")) 7 | .toString(); 8 | 9 | module.exports = (scanDetails) => Mustache.render(REPORT_TEMPLATE, scanDetails); 10 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:3.21.3 2 | 3 | RUN apk upgrade && \ 4 | apk add nodejs npm openjdk21-jre-headless tar zstd 5 | 6 | COPY package.json /contrast-local-scanner/package.json 7 | RUN cd /contrast-local-scanner && npm i --production 8 | 9 | ENV ACTIONS_CACHE_SERVICE_V2=true 10 | 11 | COPY src /contrast-local-scanner/src 12 | 13 | ENTRYPOINT ["node", "/contrast-local-scanner/src/index.js"] -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # Lines starting with '#' are comments. 2 | # Each line is a file pattern followed by one or more owners. 3 | 4 | # More details are here: https://help.github.com/articles/about-codeowners/ 5 | 6 | # The '*' pattern is global owners. 7 | 8 | # Order is important. The last matching pattern has the most precedence. 9 | # The folders are ordered as follows: 10 | 11 | # In each subsection folders are ordered first by depth, then alphabetically. 12 | # This should make it easy to add new rules without breaking existing ones. 13 | 14 | # Global rule: 15 | # SAST Developers 16 | * @Contrast-Security-OSS/sast-admins -------------------------------------------------------------------------------- /src/matchers.js: -------------------------------------------------------------------------------- 1 | const PROJECT_ID_REGEX = 2 | /Retrieved project with name and id \[.+,(?.+)\]/m; 3 | const SCAN_ID_REGEX = /Running scan with scan id \[(?.+)\]/m; 4 | const NUMBER_OF_ISSUES_REGEX = /Found (?[0-9+]) issues/m; 5 | 6 | function getProjectId(text) { 7 | return text.match(PROJECT_ID_REGEX)?.groups?.projectId?.trim(); 8 | } 9 | 10 | function getScanId(text) { 11 | return text.match(SCAN_ID_REGEX)?.groups?.scanId?.trim(); 12 | } 13 | 14 | function getNumberOfIssues(text) { 15 | return text.match(NUMBER_OF_ISSUES_REGEX)?.groups?.numberOfIssues?.trim(); 16 | } 17 | 18 | module.exports = { 19 | getProjectId, 20 | getScanId, 21 | getNumberOfIssues, 22 | }; 23 | -------------------------------------------------------------------------------- /src/report/report.template: -------------------------------------------------------------------------------- 1 | # Contrast Local Scan 2 | 3 | | Description | | Critical | High | Medium | Low | Note | 4 | |-------------|------------------------------------------|------------------------|--------------------|----------------------|-------------------|--------------------| 5 | | Project level aggregated open vulnerabilities | [ {{ project.name }} ]({{ project.url }}) | {{ project.critical }} | {{ project.high }} | {{ project.medium }} | {{ project.low }} | {{ project.note }} | 6 | | Scan level individual results | [ {{ scan.name }} ]({{ scan.url }}) | {{ scan.critical }} | {{ scan.high }} | {{ scan.medium }} | {{ scan.low }} | {{ scan.note }} | -------------------------------------------------------------------------------- /src/request.js: -------------------------------------------------------------------------------- 1 | const httpm = require("@actions/http-client"); 2 | const core = require("@actions/core"); 3 | 4 | const { apiApiKey, apiAuthHeader, apiBaseUrl } = require("./config"); 5 | 6 | const httpClient = new httpm.HttpClient( 7 | 'contrast-local-scan-action', // Sets user-agent 8 | [], 9 | { 10 | allowRedirects: false 11 | } 12 | ); 13 | 14 | async function request(path) { 15 | const response = await httpClient.getJson(`${apiBaseUrl}/${path}`, { 16 | "api-key": apiApiKey, 17 | authorization: apiAuthHeader, 18 | }); 19 | 20 | core.debug({path, response}); 21 | 22 | if (response.statusCode !== 200) { 23 | throw new Error( 24 | `API ${path} returned a response code of ${response.statusCode}`, 25 | ); 26 | } 27 | 28 | return response.result; 29 | } 30 | 31 | module.exports = request; 32 | -------------------------------------------------------------------------------- /eslint.config.mjs: -------------------------------------------------------------------------------- 1 | import { defineConfig } from "eslint/config"; 2 | import globals from "globals"; 3 | import path from "node:path"; 4 | import { fileURLToPath } from "node:url"; 5 | import js from "@eslint/js"; 6 | import { FlatCompat } from "@eslint/eslintrc"; 7 | 8 | const __filename = fileURLToPath(import.meta.url); 9 | const __dirname = path.dirname(__filename); 10 | const compat = new FlatCompat({ 11 | baseDirectory: __dirname, 12 | recommendedConfig: js.configs.recommended, 13 | allConfig: js.configs.all 14 | }); 15 | 16 | export default defineConfig([{ 17 | extends: compat.extends("eslint:recommended", "prettier"), 18 | 19 | languageOptions: { 20 | globals: { 21 | ...globals.node, 22 | }, 23 | 24 | ecmaVersion: "latest", 25 | sourceType: "module", 26 | }, 27 | rules: { 28 | "no-unused-vars": "off", 29 | } 30 | }]); -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "contrast-local-scan-action", 3 | "version": "1.0.10", 4 | "description": "Github action that runs Contrast Local Scanner against the current github repository.", 5 | "author": "Contrast Security", 6 | "license": "Apache-2.0", 7 | "dependencies": { 8 | "@actions/cache": "^4.0.4", 9 | "@actions/core": "^1.11.1", 10 | "@actions/exec": "^1.1.1", 11 | "@actions/github": "^6.0.1", 12 | "@actions/http-client": "^2.2.3", 13 | "@actions/tool-cache": "^2.0.2", 14 | "@protobuf-ts/runtime-rpc": "^2.11.1", 15 | "mustache": "^4.2.0" 16 | }, 17 | "devDependencies": { 18 | "eslint": "^9.24.0", 19 | "eslint-config-prettier": "^10.1.2", 20 | "eslint-plugin-import": "^2.28.1", 21 | "eslint-plugin-prettier": "^5.1.3", 22 | "prettier": "^3.1.1", 23 | "release-it": "^19.0.3" 24 | }, 25 | "scripts": { 26 | "lint": "eslint src", 27 | "lint:check": "eslint src --max-warnings 0", 28 | "format:check": "prettier -c src", 29 | "lint-fix": "eslint **/*.js --fix", 30 | "release": "release-it --ci" 31 | }, 32 | "release-it": { 33 | "git": { 34 | "tagName": "v${version}", 35 | "commitMessage": "[Auto] Release ${version} [skip ci]" 36 | }, 37 | "npm": { 38 | "publish": false 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | const core = require("@actions/core"); 2 | const getLocalScannerPath = require("./local-scanner"); 3 | const scan = require("./scan"); 4 | const { startCheck, finishCheck } = require("./checks"); 5 | const { checks, title, severity, strategy } = require("./config"); 6 | 7 | async function runScan() { 8 | core.info(`Running ${title}`); 9 | 10 | const localScannerJar = await getLocalScannerPath(); 11 | 12 | const scanDetails = await scan(localScannerJar); 13 | 14 | if (severity && scanDetails.thresholdResults > 0) { 15 | core.setFailed( 16 | `Found ${scanDetails.thresholdResults} open results at ${strategy} level with severity ${severity} or higher.`, 17 | ); 18 | } 19 | 20 | core.setOutput("scanDetails", scanDetails); 21 | 22 | return scanDetails; 23 | } 24 | 25 | async function runScanWithChecks() { 26 | let scanDetails; 27 | 28 | await startCheck(); 29 | 30 | try { 31 | scanDetails = await runScan(); 32 | 33 | core.debug(JSON.stringify(scanDetails, null, 2)); 34 | } finally { 35 | await finishCheck(scanDetails); 36 | } 37 | } 38 | 39 | async function run() { 40 | try { 41 | const runFunction = checks ? runScanWithChecks : runScan; 42 | 43 | await runFunction(); 44 | } catch (error) { 45 | core.setFailed(error); 46 | core.debug(error.stack); 47 | } 48 | } 49 | 50 | run(); 51 | -------------------------------------------------------------------------------- /.github/workflows/validate.yaml: -------------------------------------------------------------------------------- 1 | name: Validate local scanner action 2 | 3 | on: 4 | push: 5 | branches: 6 | - '*' 7 | - '!main' 8 | 9 | env: 10 | REGISTRY: ghcr.io 11 | IMAGE_NAME: ${{ github.repository }} 12 | 13 | permissions: 14 | contents: write 15 | packages: write 16 | checks: write 17 | id-token: write 18 | 19 | jobs: 20 | lint: 21 | runs-on: ubuntu-latest 22 | steps: 23 | - uses: actions/checkout@v4 24 | - name: Install modules 25 | run: npm ci 26 | - name: eslint 27 | run: npm run lint:check 28 | 29 | build-action-docker-image: 30 | needs: [ lint ] 31 | runs-on: ubuntu-latest 32 | steps: 33 | - uses: actions/checkout@v4 34 | - uses: ./.github/actions/build-image 35 | name: Build and publish docker image 36 | with: 37 | registry: ${{ env.REGISTRY }} 38 | image_name: ${{ env.IMAGE_NAME }} 39 | username: ${{ github.actor }} 40 | password: ${{ secrets.GITHUB_TOKEN }} 41 | 42 | verify-action: 43 | runs-on: ubuntu-latest 44 | needs: [ build-action-docker-image ] 45 | steps: 46 | - uses: actions/checkout@v4 47 | with: 48 | ref: ${{ github.head_ref || github.ref_name }} 49 | - uses : ./ 50 | name: Run action against repository 51 | with: 52 | apiUrl: ${{ secrets.CONTRAST__API__URL }} 53 | apiUserName: ${{ secrets.CONTRAST__API__USER_NAME }} 54 | apiKey: ${{ secrets.CONTRAST__API__API_KEY }} 55 | apiServiceKey: ${{ secrets.CONTRAST__API__SERVICE_KEY }} 56 | apiOrgId: ${{ secrets.CONTRAST__API__ORGANIZATION }} 57 | checks: true 58 | severity: medium 59 | path: src 60 | -------------------------------------------------------------------------------- /scripts/run-container-locally.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # INPUT_${var} where var corresponds to those defined in action.yml uppercased 4 | # 5 | # Other env vars are those normally passed in by the github actions runner 6 | # as defined here https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables 7 | 8 | file=. 9 | project=contrast-local-scan-action-test 10 | 11 | while getopts "f:p:" opt; do 12 | case $opt in 13 | f) file="$OPTARG" ;; 14 | p) project="$OPTARG" ;; 15 | esac 16 | done 17 | 18 | docker run \ 19 | -e INPUT_APIURL=$CONTRAST__API__URL \ 20 | -e INPUT_APIUSERNAME=$CONTRAST__API__USER_NAME \ 21 | -e INPUT_APIKEY=$CONTRAST__API__API_KEY \ 22 | -e INPUT_APISERVICEKEY=$CONTRAST__API__SERVICE_KEY \ 23 | -e INPUT_APIORGID=$CONTRAST__API__ORGANIZATION \ 24 | -e INPUT_DEFAULTBRANCH=false \ 25 | -e INPUT_CHECKS=false \ 26 | -e INPUT_CODEQUALITY=false \ 27 | -e INPUT_LABEL="local-test" \ 28 | -e INPUT_TOKEN=unknown \ 29 | -e INPUT_PROJECTNAME=$project \ 30 | -e INPUT_RESOURCEGROUP=scan \ 31 | -e ACTIONS_RUNTIME_TOKEN=unknown \ 32 | -e RUNNER_TEMP=/tmp \ 33 | -e GITHUB_JOB="local-test" \ 34 | -e GITHUB_REF="refs/local/test" \ 35 | -e GITHUB_SHA=c9f043b \ 36 | -e GITHUB_EVENT_NAME="push" \ 37 | -e GITHUB_REPOSITORY=contrast-local-scan-action-test \ 38 | -e GITHUB_REPOSITORY_OWNER=Contrast-Security-OSS \ 39 | -e GITHUB_REPOSITORY_OWNER_ID=1 \ 40 | -e GITHUB_RUN_ID=1 \ 41 | -e GITHUB_RUN_NUMBER=1 \ 42 | -e GITHUB_WORKSPACE=/workspace \ 43 | -e GITHUB_EVENT_PATH=/github/github-event.json \ 44 | -w /workspace \ 45 | -v ./target:/root/contrast-local-scanner/ \ 46 | -v ./scripts/github-event.json:/github/github-event.json \ 47 | -v $file:/workspace \ 48 | $(docker build -q .) 49 | -------------------------------------------------------------------------------- /.github/actions/build-image/action.yaml: -------------------------------------------------------------------------------- 1 | name: build-and-deploy-image 2 | 3 | inputs: 4 | registry: 5 | description: The registry to deploy to 6 | required: true 7 | image_name: 8 | description: The name of the docker image 9 | required: true 10 | username: 11 | description: The username to login to the container registry 12 | required: true 13 | password: 14 | description: The password to login to the container registry 15 | required: true 16 | 17 | runs: 18 | using: composite 19 | steps: 20 | - uses: actions/checkout@v4 21 | - name: Log in to the Container registry 22 | uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 23 | with: 24 | registry: ${{ inputs.registry }} 25 | username: ${{ inputs.username }} 26 | password: ${{ inputs.password }} 27 | 28 | - name: Extract metadata (tags, labels) for Docker 29 | id: meta 30 | uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 31 | with: 32 | images: ${{ inputs.registry }}/${{ inputs.image_name }} 33 | tags: type=sha,format=long 34 | 35 | - name: Build and push Docker image 36 | id: push 37 | uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 38 | with: 39 | context: . 40 | push: true 41 | tags: ${{ steps.meta.outputs.tags }} 42 | labels: ${{ steps.meta.outputs.labels }} 43 | 44 | - name: Commit changes 45 | shell: bash 46 | env: 47 | IMAGE_TAG: docker://${{ steps.meta.outputs.tags }} 48 | run: | 49 | git config --global user.name 'Github' 50 | git config --global user.email 'github@users.noreply.github.com' 51 | 52 | git pull 53 | 54 | yq e ".runs.image = env(IMAGE_TAG)" -i action.yml 55 | 56 | git add action.yml 57 | git diff-index --quiet HEAD || (git commit -m "[Auto] Image tag updated latest pushed version" && git push) -------------------------------------------------------------------------------- /src/checks.js: -------------------------------------------------------------------------------- 1 | const github = require("@actions/github"); 2 | const core = require("@actions/core"); 3 | const buildReport = require("./report"); 4 | const { title, token } = require("./config"); 5 | 6 | const octokit = github.getOctokit(token); 7 | 8 | let CHECK_ID; 9 | 10 | async function startCheck() { 11 | const { owner, repo } = github.context.repo; 12 | 13 | const pullRequest = github.context.payload.pull_request; 14 | const sha = (pullRequest && pullRequest.head.sha) || github.context.sha; 15 | 16 | try { 17 | 18 | const response = await octokit.rest.checks.create({ 19 | owner, 20 | repo, 21 | name: title, 22 | head_sha: sha, 23 | status: "in_progress", 24 | output: { 25 | title, 26 | summary: "", 27 | text: "", 28 | }, 29 | }); 30 | 31 | CHECK_ID = response.data.id; 32 | } 33 | catch (error) { 34 | throw new Error("Error creating check. Ensure your workflow has the 'checks:write' permissions - https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs") 35 | } 36 | } 37 | 38 | function getOutputModel(details) { 39 | 40 | if (!details) { 41 | return { 42 | conclusion: "action_required", 43 | report: "Local scan completed with error, please see logs for details" 44 | }; 45 | } 46 | 47 | return { 48 | conclusion: details.thresholdResults > 0 ? "action_required" : "success", 49 | report: buildReport(details), 50 | }; 51 | } 52 | 53 | async function finishCheck(details) { 54 | const { owner, repo } = github.context.repo; 55 | const { conclusion, report } = getOutputModel(details); 56 | 57 | if (!CHECK_ID) { 58 | core.warning("No active check to finish."); 59 | return; 60 | } 61 | 62 | await octokit.rest.checks.update({ 63 | owner, 64 | repo, 65 | check_run_id: CHECK_ID, 66 | conclusion, 67 | status: "completed", 68 | output: { 69 | title, 70 | summary: "Scan Completed", 71 | text: report, 72 | }, 73 | }); 74 | } 75 | 76 | module.exports = { 77 | startCheck, 78 | finishCheck, 79 | }; 80 | -------------------------------------------------------------------------------- /.github/workflows/release.yaml: -------------------------------------------------------------------------------- 1 | name: Release local scanner action 2 | 3 | on: 4 | push: 5 | branches: 6 | - 'main' 7 | 8 | env: 9 | REGISTRY: ghcr.io 10 | IMAGE_NAME: ${{ github.repository }} 11 | 12 | permissions: 13 | contents: write 14 | packages: write 15 | checks: write 16 | id-token: write 17 | 18 | jobs: 19 | lint: 20 | runs-on: ubuntu-latest 21 | steps: 22 | - uses: actions/checkout@v3 23 | - name: Install modules 24 | run: npm ci 25 | - name: eslint 26 | run: npm run lint:check 27 | 28 | build-action-docker-image: 29 | needs: [ lint ] 30 | runs-on: ubuntu-latest 31 | steps: 32 | - uses: actions/checkout@v4 33 | - uses: ./.github/actions/build-image 34 | name: Build and publish docker image 35 | with: 36 | registry: ${{ env.REGISTRY }} 37 | image_name: ${{ env.IMAGE_NAME }} 38 | username: ${{ github.actor }} 39 | password: ${{ secrets.GITHUB_TOKEN }} 40 | 41 | verify-action: 42 | runs-on: ubuntu-latest 43 | needs: [ build-action-docker-image ] 44 | steps: 45 | - uses: actions/checkout@v4 46 | with: 47 | ref: ${{ github.head_ref || github.ref_name }} 48 | - uses : ./ 49 | name: Run action against itself 50 | with: 51 | apiUrl: ${{ secrets.CONTRAST__API__URL }} 52 | apiUserName: ${{ secrets.CONTRAST__API__USER_NAME }} 53 | apiKey: ${{ secrets.CONTRAST__API__API_KEY }} 54 | apiServiceKey: ${{ secrets.CONTRAST__API__SERVICE_KEY }} 55 | apiOrgId: ${{ secrets.CONTRAST__API__ORGANIZATION }} 56 | severity: medium 57 | path: src 58 | 59 | release: 60 | runs-on: ubuntu-latest 61 | needs: [ verify-action ] 62 | steps: 63 | - uses: actions/checkout@v4 64 | with: 65 | ref: ${{ github.head_ref || github.ref_name }} 66 | - name: Install modules 67 | run: npm ci 68 | - name: release 69 | run: | 70 | git config --global user.name 'Github' 71 | git config --global user.email 'github@users.noreply.github.com' 72 | 73 | npm run release 74 | 75 | -------------------------------------------------------------------------------- /src/severities.js: -------------------------------------------------------------------------------- 1 | const request = require("./request"); 2 | const core = require("@actions/core"); 3 | 4 | const COMPLETED = "COMPLETED"; 5 | const CANCELLED = "CANCELLED"; 6 | const FAILED = "FAILED"; 7 | 8 | const SCAN_FINISHED_STATUSES = [COMPLETED, CANCELLED, FAILED]; 9 | 10 | const RESULT_OPEN_STATUSES = [ 11 | "REPORTED", 12 | "CONFIRMED", 13 | "SUSPICIOUS", 14 | "REOPENED", 15 | ]; 16 | 17 | const RESULTS_OPEN_QUERY_STRING = RESULT_OPEN_STATUSES.reduce((query, status) => { 18 | query.append("status", status); 19 | return query; 20 | }, new URLSearchParams()).toString(); 21 | 22 | async function sleep() { 23 | return new Promise((resolve) => setTimeout(resolve, 5000)); 24 | } 25 | 26 | async function getScan(projectId, scanId) { 27 | return await request(`/projects/${projectId}/scans/${scanId}`); 28 | } 29 | 30 | async function waitForScanCompletion(projectId, scanId) { 31 | let scan; 32 | 33 | core.info("Waiting for results to be processed....."); 34 | 35 | do { 36 | if (scan) await sleep(); 37 | 38 | scan = await getScan(projectId, scanId); 39 | } while (!SCAN_FINISHED_STATUSES.includes(scan.status)); 40 | 41 | core.info(`Scan completed with status ${scan.status}`); 42 | 43 | return scan; 44 | } 45 | 46 | async function getProjectSeverities(projectId, newVulnerabilitiesOnly) { 47 | let projectSeveritiesQueryUrl = `/projects/${projectId}/results/severities?${RESULTS_OPEN_QUERY_STRING}`; 48 | 49 | if (newVulnerabilitiesOnly === true) { 50 | projectSeveritiesQueryUrl = projectSeveritiesQueryUrl + '&isNew=true'; 51 | } 52 | 53 | return await request(projectSeveritiesQueryUrl); 54 | } 55 | 56 | async function getScanSeverities(projectId, scanId) { 57 | return await request( 58 | `/projects/${projectId}/scans/${scanId}/result-instances/severities`, 59 | ); 60 | } 61 | 62 | async function getSeverities(projectId, scanId, newVulnerabilitiesOnly = false) { 63 | const scan = await waitForScanCompletion(projectId, scanId); 64 | 65 | if (scan.status !== COMPLETED) { 66 | throw new Error(`Scan finished with a status of ${scan.status}`); 67 | } 68 | 69 | const projectSeverities = await getProjectSeverities(projectId, newVulnerabilitiesOnly); 70 | const scanSeverities = await getScanSeverities(projectId, scanId); 71 | 72 | return { 73 | project: projectSeverities, 74 | scan: scanSeverities, 75 | }; 76 | } 77 | 78 | module.exports = getSeverities; 79 | -------------------------------------------------------------------------------- /src/local-scanner.js: -------------------------------------------------------------------------------- 1 | const tc = require("@actions/tool-cache"); 2 | const cache = require("@actions/cache"); 3 | const core = require("@actions/core"); 4 | const fs = require("fs"); 5 | const path = require("path"); 6 | const getArtifacts = require("./artifacts"); 7 | const { localScannerVersion } = require("./config"); 8 | 9 | const CONTRAST_LOCAL_SCANNER = "contrast-local-scanner"; 10 | const LOCAL_SCANNER_PATH = `${process.env.HOME}/${CONTRAST_LOCAL_SCANNER}`; 11 | const LOCAL_SCANNER_CACHE_KEY = `${CONTRAST_LOCAL_SCANNER}-${localScannerVersion}`; 12 | const JAR_NAME = `sast-local-scan-runner-${localScannerVersion}.jar`; 13 | const JAR_FULL_PATH = path.join(LOCAL_SCANNER_PATH, JAR_NAME); 14 | 15 | async function getLocalScannerArtifact(version) { 16 | const artifacts = await getArtifacts(version); 17 | 18 | if (artifacts && artifacts.length > 0) { 19 | const zipArtifacts = artifacts.filter((release) => release.name.endsWith(".zip")); 20 | 21 | if (zipArtifacts && zipArtifacts.length > 0) return zipArtifacts[0]; 22 | } 23 | 24 | throw new Error(`Unable to download local scanner ${version} artifact`); 25 | } 26 | 27 | const getLocalScannerLocation = (directory) => { 28 | const releaseDir = fs.readdirSync(directory); 29 | 30 | const jarLocations = releaseDir.filter((file) => file.endsWith(".jar")); 31 | 32 | if (jarLocations.length === 1) { 33 | return path.join(directory, jarLocations[0]); 34 | } 35 | 36 | throw new Error(`Unable to locate ${CONTRAST_LOCAL_SCANNER} jar`); 37 | }; 38 | 39 | async function restoreCache() { 40 | return cache.restoreCache([LOCAL_SCANNER_PATH], LOCAL_SCANNER_CACHE_KEY); 41 | } 42 | 43 | async function saveCache() { 44 | const cacheId = await cache.saveCache( 45 | [LOCAL_SCANNER_PATH], 46 | LOCAL_SCANNER_CACHE_KEY, 47 | ); 48 | 49 | core.info(`Cache saved with id ${cacheId}`); 50 | } 51 | 52 | async function getLocalScannerPath() { 53 | 54 | if (fs.existsSync(JAR_FULL_PATH)) { 55 | core.info(`${CONTRAST_LOCAL_SCANNER} exists locally`); 56 | return JAR_FULL_PATH; 57 | } 58 | 59 | core.info(`${JAR_FULL_PATH} not found locally, checking if exists in cache.`); 60 | 61 | const cacheKey = await restoreCache(); 62 | 63 | if (!cacheKey) { 64 | core.info(`${CONTRAST_LOCAL_SCANNER} not previously cached, downloading.`); 65 | 66 | const localScannerArtifact = 67 | await getLocalScannerArtifact(localScannerVersion); 68 | 69 | const downloadPath = await tc.downloadTool(localScannerArtifact.url); 70 | 71 | core.info(`${CONTRAST_LOCAL_SCANNER} downloaded to ${downloadPath}.`); 72 | 73 | const extractDirectory = await tc.extractZip( 74 | downloadPath, 75 | LOCAL_SCANNER_PATH, 76 | ); 77 | 78 | core.info(`${CONTRAST_LOCAL_SCANNER} extracted to ${extractDirectory}.`); 79 | 80 | await saveCache(); 81 | } 82 | 83 | return getLocalScannerLocation(LOCAL_SCANNER_PATH); 84 | } 85 | 86 | module.exports = getLocalScannerPath; 87 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: Contrast Local Scan 2 | description: Runs Contrast local scanner against the current repository 3 | branding: 4 | icon: crosshair 5 | color: green 6 | inputs: 7 | apiUrl: # id of input 8 | description: Url of your contrast instance, defaults to https://app.contrastsecurity.com/ 9 | required: true 10 | default: 'https://app.contrastsecurity.com/' 11 | apiUserName: 12 | description: User name for authentication 13 | required: true 14 | apiKey: 15 | description: API Key from user settings 16 | required: true 17 | apiServiceKey: 18 | description: Service Key from user settings 19 | required: true 20 | apiOrgId: 21 | description: Organization ID from user settings 22 | required: true 23 | checks: 24 | description: > 25 | If set, checks will be added to the current commit based on any vulnerabilities found. Requires the 'checks: write' permission. 26 | 27 | required: false 28 | default: false 29 | codeQuality: 30 | description: Set this to true to include code quality rules when executing source code scanner. 31 | required: false 32 | default: false 33 | defaultBranch: 34 | description: > 35 | Set this to true or false explicitly override the default branching behviour in scan whereby scan results not on the default github branch are not saved against the main project. 36 | 37 | required: false 38 | label: 39 | description: Label to associate with the current scan. Defaults to the current ref e.g. refs/heads/main 40 | memory: 41 | description: Memory setting passed to the underlying scan engine. Defaulted to 8g 42 | required: false 43 | new: 44 | description: Set this to true or false to only fail the action on new vulnerabilities. This defaults to true when on a non default branch. 45 | required: false 46 | path: 47 | description: Path to scan with local scanner. Defaults to the current repository path. 48 | required: false 49 | projectName: 50 | description: Project to associate scan with. Defaults to current github repository name e.g. Example-ORG/example-repo 51 | required: false 52 | resourceGroup: 53 | description: Resource group to assign newly created projects to. 54 | required: false 55 | strategy: 56 | description: > 57 | Used in conjuction with severity or checks, set this valid to fail the build based on agreggated project vulnerabilities or scan level. Valid values are "project" or "scan". Defaults to "project". 58 | 59 | required: false 60 | default: "project" 61 | severity: 62 | description: > 63 | Set this to cause the build to fail if vulnerabilities are found exceeding this severity or higher. Valid values are CRITICAL, HIGH, MEDIUM, LOW, NOTE. 64 | 65 | required: false 66 | timeout: 67 | description: Execution timeout (in seconds) setting passed to the underlying scan engine. Defaulted to 60 minutes. 68 | required: false 69 | token: 70 | description: > 71 | GitHub token for GitHub API requests. Defaults to GITHUB_TOKEN. 72 | 73 | required: true 74 | default: ${{ github.token }} 75 | runs: 76 | using: 'docker' 77 | image: 'docker://ghcr.io/contrast-security-oss/contrast-local-scan-action:sha-7f62ad6839d1a35d591b3d273925954ff9abdbab' 78 | -------------------------------------------------------------------------------- /src/config.js: -------------------------------------------------------------------------------- 1 | const core = require("@actions/core"); 2 | const github = require("@actions/github"); 3 | 4 | const PULL_REQUEST_EVENT = 'pull_request'; 5 | const WORKFLOW_DISPATCH = 'workflow_dispatch'; 6 | const PUSH_EVENT = 'push'; 7 | const DEFAULT_BRANCH_NAME = github.context.payload?.repository?.default_branch; 8 | 9 | const getRef = () => { 10 | 11 | switch (github.context.eventName) { 12 | case PULL_REQUEST_EVENT: { 13 | return github.context.payload?.pull_request?.head?.ref; 14 | } 15 | case PUSH_EVENT: 16 | case WORKFLOW_DISPATCH: { 17 | return github.context.payload?.ref; 18 | } 19 | default: { 20 | core.warning(`Received unexpected github event ${github.context.eventName}`); 21 | return github.context.payload?.ref || github.context.ref; 22 | } 23 | } 24 | }; 25 | 26 | const thisBranchName = () => { 27 | 28 | const ref = getRef(); 29 | 30 | try { 31 | 32 | const refParts = ref.split('/'); 33 | 34 | return refParts[refParts.length-1]; 35 | } 36 | catch (error) { 37 | core.error(`Unable to get current branch name from ref ${ref} : ${error.message}`); 38 | } 39 | 40 | return DEFAULT_BRANCH_NAME 41 | }; 42 | 43 | const isDefaultBranch = () => { 44 | 45 | const input = core.getInput("defaultBranch")?.toLowerCase(); 46 | 47 | if (["true", "false"].includes(input)) { 48 | core.info(`User set defaultBranch to ${input}`); 49 | return core.getBooleanInput("defaultBranch"); 50 | } 51 | 52 | return DEFAULT_BRANCH_NAME === thisBranchName(); 53 | }; 54 | 55 | const isNewVulnerabilitiesOnly = () => { 56 | 57 | const input = core.getInput("new")?.toLowerCase(); 58 | 59 | if (["true", "false"].includes(input)) { 60 | core.info(`User set new to ${input}`); 61 | return core.getBooleanInput("new"); 62 | } 63 | 64 | // If not specified, we look for new vulnerabilities only when not on the default branch 65 | return !isDefaultBranch(); 66 | }; 67 | 68 | const requiredInputOptions = {required:true}; 69 | 70 | const apiUrl = core.getInput("apiUrl", requiredInputOptions); 71 | const apiUserName = core.getInput("apiUserName", requiredInputOptions); 72 | const apiApiKey = core.getInput("apiKey", requiredInputOptions); 73 | const apiServiceKey = core.getInput("apiServiceKey", requiredInputOptions); 74 | const apiOrgId = core.getInput("apiOrgId", requiredInputOptions); 75 | 76 | const apiBaseUrl = `${ 77 | new URL(apiUrl).origin 78 | }/Contrast/api/sast/v1/organizations/${apiOrgId}`; 79 | const apiAuthHeader = Buffer.from(`${apiUserName}:${apiServiceKey}`).toString( 80 | "base64", 81 | ); 82 | 83 | const checks = core.getBooleanInput("checks"); 84 | const codeQuality = core.getBooleanInput("codeQuality"); 85 | const defaultBranch = isDefaultBranch(); 86 | const newVulnerabilitiesOnly = isNewVulnerabilitiesOnly(); 87 | 88 | const ref = getRef(); 89 | const label = core.getInput("label") || ref; 90 | 91 | // Pinning the local scanner version 92 | const localScannerVersion = "2.0.2"; 93 | 94 | const memory = core.getInput("memory"); 95 | const path = core.getInput("path") || process.env.GITHUB_WORKSPACE; 96 | const projectName = 97 | core.getInput("projectName") || process.env.GITHUB_REPOSITORY; 98 | 99 | const resourceGroup = core.getInput("resourceGroup"); 100 | const severity = core.getInput("severity")?.toLowerCase() || undefined; 101 | const strategy = core.getInput("strategy") || "project"; 102 | const timeout = core.getInput("timeout"); 103 | const title = "Contrast Local Scan"; 104 | const token = core.getInput("token"); 105 | 106 | core.debug(`Default branch name : ${DEFAULT_BRANCH_NAME}`); 107 | core.debug(`This branch name : ${thisBranchName()}`); 108 | core.debug(`Default branch resolved setting : ${defaultBranch}`) 109 | core.debug(JSON.stringify(github.context, null, 2)); 110 | 111 | module.exports = { 112 | apiUrl, 113 | apiBaseUrl, 114 | apiUserName, 115 | apiApiKey, 116 | apiServiceKey, 117 | apiOrgId, 118 | apiAuthHeader, 119 | checks, 120 | codeQuality, 121 | defaultBranch, 122 | label, 123 | localScannerVersion, 124 | memory, 125 | newVulnerabilitiesOnly, 126 | path, 127 | projectName, 128 | ref, 129 | resourceGroup, 130 | severity, 131 | strategy, 132 | timeout, 133 | title, 134 | token, 135 | }; 136 | -------------------------------------------------------------------------------- /src/scan.js: -------------------------------------------------------------------------------- 1 | const exec = require("@actions/exec"); 2 | const getSeverities = require("./severities"); 3 | const { getProjectId, getScanId, getNumberOfIssues } = require("./matchers"); 4 | 5 | const { 6 | apiApiKey, 7 | apiBaseUrl, 8 | apiOrgId, 9 | apiUserName, 10 | apiServiceKey, 11 | checks, 12 | codeQuality, 13 | defaultBranch, 14 | label, 15 | memory, 16 | newVulnerabilitiesOnly, 17 | path, 18 | projectName, 19 | ref, 20 | resourceGroup, 21 | severity, 22 | strategy, 23 | timeout, 24 | title, 25 | } = require("./config"); 26 | 27 | const SEVERITIES = ["critical", "high", "medium", "low", "note"]; 28 | 29 | function envOpts() { 30 | return { 31 | ...process.env, 32 | CONTRAST__API__URL: apiBaseUrl, 33 | CONTRAST__API__USER_NAME: apiUserName, 34 | CONTRAST__API__API_KEY: apiApiKey, 35 | CONTRAST__API__SERVICE_KEY: apiServiceKey, 36 | CONTRAST__API__ORGANIZATION: apiOrgId, 37 | }; 38 | } 39 | 40 | function scanOpts(jar) { 41 | const options = [ 42 | "-jar", 43 | jar, 44 | "--project-name", 45 | projectName, 46 | "--label", 47 | label, 48 | ]; 49 | 50 | if (codeQuality) { 51 | options.push("-q"); 52 | } 53 | 54 | if (memory) { 55 | options.push("--memory", memory); 56 | } 57 | 58 | if (timeout) { 59 | options.push("--timeout", timeout); 60 | } 61 | 62 | if (resourceGroup) { 63 | options.push("-r", resourceGroup); 64 | } 65 | 66 | if (!defaultBranch) { 67 | options.push("--branch", ref); 68 | } 69 | 70 | options.push(path); 71 | 72 | return options; 73 | } 74 | 75 | function mapSeverities(severityCounts) { 76 | const mappedSeverities = severityCounts.reduce((severities, severity) => { 77 | severities[severity.severity.toLowerCase()] = severity.count; 78 | return severities; 79 | }, {}); 80 | 81 | return { 82 | critical: 0, 83 | high: 0, 84 | medium: 0, 85 | low: 0, 86 | note: 0, 87 | ...mappedSeverities, 88 | }; 89 | } 90 | 91 | function addFailedResult(scanDetails, severity = "note") { 92 | scanDetails.thresholdResults = 0; 93 | 94 | const includedSeverities = SEVERITIES.slice( 95 | 0, 96 | SEVERITIES.indexOf(severity) + 1, 97 | ); 98 | 99 | for (const includedSeverity of includedSeverities) { 100 | scanDetails.thresholdResults += scanDetails[strategy][includedSeverity]; 101 | } 102 | 103 | return scanDetails; 104 | } 105 | 106 | async function getScanDetailsFromOutput(scanOutput) { 107 | const numberOfIssues = getNumberOfIssues(scanOutput); 108 | const projectId = getProjectId(scanOutput); 109 | const scanId = getScanId(scanOutput); 110 | 111 | if (!projectId || !scanId) { 112 | throw new Error(`Could not get valid details to query scan results`); 113 | } 114 | 115 | const host = new URL(apiBaseUrl).origin; 116 | 117 | const scanDetails = { 118 | numberOfIssues, 119 | thresholdResults: 0, 120 | project: { 121 | id: projectId, 122 | name: projectName, 123 | url: `${host}/Contrast/static/ng/index.html#/${apiOrgId}/scans/${projectId}`, 124 | }, 125 | scan: { 126 | id: scanId, 127 | name: label, 128 | url: `${host}/Contrast/static/ng/index.html#/${apiOrgId}/scans/${projectId}/scans/${scanId}`, 129 | }, 130 | }; 131 | 132 | if (severity || checks) { 133 | const { project, scan } = await getSeverities(projectId, scanId, newVulnerabilitiesOnly); 134 | Object.assign(scanDetails.project, mapSeverities(project)); 135 | Object.assign(scanDetails.scan, mapSeverities(scan)); 136 | } 137 | 138 | return addFailedResult(scanDetails, severity); 139 | } 140 | 141 | async function scan(jar) { 142 | let rawOutput = ""; 143 | 144 | const exitCode = await exec.exec("java", scanOpts(jar), { 145 | env: envOpts(), 146 | ignoreReturnCode: true, 147 | listeners: { 148 | stdout: (data) => { 149 | rawOutput += data.toString(); 150 | }, 151 | }, 152 | }); 153 | 154 | if (exitCode !== 0) { 155 | throw new Error(`${title} failed with exitCode ${exitCode}`); 156 | } 157 | 158 | const scanDetails = await getScanDetailsFromOutput(rawOutput); 159 | 160 | return { 161 | exitCode, 162 | baseUrl: new URL(apiBaseUrl).origin, 163 | orgId: apiOrgId, 164 | ...scanDetails, 165 | }; 166 | } 167 | 168 | module.exports = scan; 169 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Use Contrast Local Scanner to analyze your code 2 | 3 | This GitHub action lets you use Contrast Local Scanner to detect vulnerabilities in your code without uploading your code to Contrast's servers. 4 | 5 | ## Local Scan Engine 6 | 7 | The github action uses Contrast local scan engine version 2.0.2. 8 | 9 | Release notes for the local scan engine can be viewed here [Scan Release Notes](https://docs.contrastsecurity.com/en/scan-release-notes-and-archive.html) 10 | 11 | ## Supported Languages 12 | - ASP.NET 13 | - C 14 | - C# 15 | - C++ 16 | - COBOL 17 | - GO 18 | - HTML 19 | - Java 20 | - JavaScript/TypeScript 21 | - JSP 22 | - Kotlin 23 | - PHP 24 | - Python 25 | - Ruby 26 | - Scala 27 | - VB.NET 28 | 29 | ## **Initial steps for using the action** 30 | If you are not familiar with GitHub actions read the 31 | [GitHub Actions](https://docs.github.com/en/actions) documentation to learn what GitHub Actions are and how to set them 32 | up. After which, complete the following steps: 33 | 34 | 1. Configure the following GitHub secrets 35 | 36 | - CONTRAST__API__API_KEY 37 | - CONTRAST__API__ORGANIZATION 38 | - CONTRAST__API__SERVICE_KEY 39 | - CONTRAST__API__USER_NAME 40 | - CONTRAST__API__URL 41 | 42 | ![secrets](https://github.com/Contrast-Security-OSS/contrast-local-scan-action/assets/6448060/a40f01a3-b179-4837-abd2-df91a5a220fb) 43 | 44 | 2. Get your authentication details for the secrets from the 'User Settings' menu in the Contrast web interface: You will need the following 45 | 46 | - Organization ID 47 | - Your API key 48 | - Service key 49 | - User name 50 | - You will also need the URL of your Contrast UI host. This input includes the protocol section of the URL (https://). 51 | 52 | ![credentials](https://github.com/Contrast-Security-OSS/contrast-local-scan-action/assets/6448060/7a123c22-1f5f-4091-90d3-f297959d1e20) 53 | 54 | 3. Create a workflow, or update an existing one to run this action against your code (for example, on push) 55 | 56 | ```yaml 57 | name: Scan with local scanner 58 | 59 | on: 60 | push: 61 | branches: 62 | - 'main' 63 | 64 | permissions: 65 | contents: read 66 | 67 | jobs: 68 | scan: 69 | runs-on: ubuntu-latest 70 | steps: 71 | - uses: actions/checkout@v3 72 | - uses: Contrast-Security-OSS/contrast-local-scan-action@v1 73 | with: 74 | apiUrl: ${{ secrets.CONTRAST__API__URL }} 75 | apiUserName: ${{ secrets.CONTRAST__API__USER_NAME }} 76 | apiKey: ${{ secrets.CONTRAST__API__API_KEY }} 77 | apiServiceKey: ${{ secrets.CONTRAST__API__SERVICE_KEY }} 78 | apiOrgId: ${{ secrets.CONTRAST__API__ORGANIZATION }} 79 | ``` 80 | 81 | 4. To fail the step based on vulnerabilities being found at a severity or higher, set the severity option to one of critical, high, medium, low, note. 82 | 83 | *Note: this is based on the aggregated vulnerabilities found at the project level.* 84 | 85 | ```yaml 86 | scan: 87 | runs-on: ubuntu-latest 88 | steps: 89 | - uses: actions/checkout@v3 90 | - uses: Contrast-Security-OSS/contrast-local-scan-action@v1 91 | with: 92 | apiUrl: ${{ secrets.CONTRAST__API__URL }} 93 | apiUserName: ${{ secrets.CONTRAST__API__USER_NAME }} 94 | apiKey: ${{ secrets.CONTRAST__API__API_KEY }} 95 | apiServiceKey: ${{ secrets.CONTRAST__API__SERVICE_KEY }} 96 | apiOrgId: ${{ secrets.CONTRAST__API__ORGANIZATION }} 97 | severity: high 98 | ``` 99 | 100 | 5. To add GitHub checks to the current commit (e.g. the current PR), set the checks option to true. 101 | 102 | *Note: You need the checks: write permission to be set if enabling this.* 103 | 104 | ![checks](https://github.com/Contrast-Security-OSS/contrast-local-scan-action/assets/6448060/d39d14c4-1f05-4ac6-8e3d-c09912ed9559) 105 | 106 | ## Required Inputs 107 | 108 | - apiUserName : A valid user name from the Contrast platform. 109 | - apiKey : An API key from the Contrast platform. 110 | - apiServiceKey : An API Service Key from the Contrast platform 111 | - apiOrgId : The ID of your organization in Contrast. 112 | 113 | ## Optional Inputs 114 | 115 | - apiUrl : Url of your Contrast instance, defaults to https://app.contrastsecurity.com/ 116 | - checks : If set, GitHub checks will be added to the current commit based on any vulnerabilities found. 117 | - codeQuality : Passes the -q option to the Contrast local scanner to include code quality rules in the scan. 118 | - defaultBranch : Set this to true or false, to explicitly overwrite the default branching behaviour of this action. See note on branching below. 119 | - label : Label to associate with the current scan. Defaults to the current ref e.g. **refs/heads/main** 120 | - memory : Memory setting passed to the underlying scan engine. Defaulted to 8g. 121 | - path : Path to scan with Contrast local scanner. Defaults to the current repository path. 122 | - projectName : Project to associate scan with. Defaults to current GitHub repository name e.g. **Contrast-Security-OSS/contrast-local-scan-action** 123 | - resourceGroup : Passes the -r option to the Contrast local scanner to associate newly created projects with the specified resource group. 124 | - severity : Set this to cause the build to fail if vulnerabilities are found at this severity or higher. Valid values are critical, high, medium, low, note. 125 | - timeout: Execution timeout (in minutes) setting passed to the underlying scan engine. Defaulted to 60 minutes. 126 | - new: If set to true, only new vulnerabilities will cause a failure in the job or checks conditions. (Defaulted to true if scanning a branch). 127 | 128 | ## Branching 129 | 130 | When a scan completes, results for the scan are aggretegated against overall results for the project. 131 | 132 | For scans that are performed against a non default branch, results are aggregated separately from the main project, just for the current branch. 133 | 134 | By default, this is determined by comparing the current branch name against the default for the repository, as specified by the "Default Branch" setting under repository settings. 135 | 136 | This behaviour can be explicitly overwritten by setting the "**defaultBranch**" setting for this action to "**true**" or "**false**". 137 | 138 | 139 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [2024] [Contrast Security, Inc] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. --------------------------------------------------------------------------------