Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
193 changes: 193 additions & 0 deletions docs/codacy-api/examples/running-dast-scans.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
---
description: Instructions on how to run DAST/App using the API.
---

# Run DAST/App scans
Comment thread
joanasteodoro marked this conversation as resolved.
Outdated

Thanks to the new app scanning capabilities available on the Security and Risk Management dashboard, it's now possible to automate application scanning via the API. This means that, with little effort, you'll be able to run ZAP on demand every time you deploy a new version of your app or your APIs.

Check failure on line 7 in docs/codacy-api/examples/running-dast-scans.md

View workflow job for this annotation

GitHub Actions / vale

[vale] reported by reviewdog 🐶 [Vale.Spelling] Did you really mean 'APIs'? Raw Output: {"message": "[Vale.Spelling] Did you really mean 'APIs'?", "location": {"path": "docs/codacy-api/examples/running-dast-scans.md", "range": {"start": {"line": 7, "column": 295}}}, "severity": "ERROR"}
Comment thread
joanasteodoro marked this conversation as resolved.
Outdated

!!! important
App scanning is a business feature. If you are a Codacy Pro customer, contact our customer success team to access a short trial.
Check your permissions. Only git provider admins and organization managers will be able to Create new targets and run scans (in app and via the API).
Comment thread
joanasteodoro marked this conversation as resolved.
Outdated
Get your API key. All the methods below require you to authenticate via your account's API token.
Comment thread
joanasteodoro marked this conversation as resolved.
Outdated

## Creating targets

Before the automation process itself, you need to create a target. Targets are single units that contain all the configurations of your scan, in this case the URL (and later on other configurations, like authentication, scan type or open API definition).
Comment thread
joanasteodoro marked this conversation as resolved.
Outdated
Targets only need to be defined once. The target's URL is immutable, so, if you need to change it, you'll need to delete it and create a new target.
Comment thread
joanasteodoro marked this conversation as resolved.
Outdated

To create a target:

```bash
curl -X POST https://app.codacy.com/api/v3/organizations/{GIT_PROVIDER}/{ORGANIZATION}/dast/targets \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "api-token: {API_KEY}" \
-d '{"url": "https://api.domain.com/v1"}'
```

Replace the placeholders with your own values:

- **API_KEY:** [Account API token](../api-tokens.md#account-api-tokens) used to authenticate on the Codacy API.
- **GIT_PROVIDER:** Git provider hosting of the organization, using one of the values in the table below. For example, `gh` for GitHub Cloud.

| Value | Git provider |
|-------|-------------------|
| `gh` | GitHub Cloud |
| `ghe` | GitHub Enterprise |
| `gl` | GitLab Cloud |
| `gle` | GitLab Enterprise |
| `bb` | Bitbucket Cloud |
| `bbe` | Bitbucket Server |

- **ORGANIZATION:** Name of the organization on the Git provider. For example, `codacy`. You must have admin permissions over the organization on the Git provider.

Once you create the target you'll get the TargetId as a response. That Id will be used later to trigger DAST scans.
Comment thread
joanasteodoro marked this conversation as resolved.
Outdated

## Running DAST analysis scans
Comment thread
joanasteodoro marked this conversation as resolved.
Outdated

Once your targets are created you can trigger an analysis by running the POST /dast/targets/{dastTargetId}/analyze method.
Comment thread
joanasteodoro marked this conversation as resolved.
Outdated

```bash
curl -X POST https://app.codacy.com/api/v3/organizations/{GIT_PROVIDER}/{ORGANIZATION}/dast/targets/{DAST_TARGET_ID}/analyze \
-H "Accept: application/json" \
-H "api-token: {API_KEY}"
```

Replace the placeholders with your own values:

- **API_KEY:** [Account API token](../api-tokens.md#account-api-tokens) used to authenticate on the Codacy API.
- **GIT_PROVIDER:** Git provider hosting of the organization, using one of the values in the table below. For example, `gh` for GitHub Cloud.

| Value | Git provider |
|-------|-------------------|
| `gh` | GitHub Cloud |
| `ghe` | GitHub Enterprise |
| `gl` | GitLab Cloud |
| `gle` | GitLab Enterprise |
| `bb` | Bitbucket Cloud |
| `bbe` | Bitbucket Server |

- **ORGANIZATION:** Name of the organization on the Git provider. For example, `codacy`. You must have admin permissions over the organization on the Git provider.
- **DAST_TARGET_ID:** Identifier of a DAST target to analyze (obtained from the POST endpoint used to create a target or GET endpoint used to get a list of targets). For example, `457`. You must have admin permissions over the organization on the Git provider.
Comment thread
joanasteodoro marked this conversation as resolved.
Outdated

Scans will be asynchronous to your deployment pipeline. Once completed, you can access all scan results by navigating to the **Security dashboard**, selecting the **Findings tab** and filtering by **Scan types > DAST/App scanning**.
Comment thread
joanasteodoro marked this conversation as resolved.
Outdated

## Examples to Run scans on Deployment

!!! note
The examples below trigger scans on deployment which may analyze, not the latest, but the previous version of the application. To run DAST post deployment you may explore options such as:
Comment thread
joanasteodoro marked this conversation as resolved.
Outdated

GitHub Action:

```bash
name: DAST Scan with Codacy

on:
# Trigger on deployment or push to main branch
deployment:
branches: [ main ]
# Allow manual trigger
workflow_dispatch:

jobs:
dast-scan:
runs-on: ubuntu-latest
steps:
- name: Run DAST scan
env:
CODACY_API_TOKEN: "${CODACY_API_TOKEN}"
PROVIDER: "gh" # Github in Codacy
ORG_NAME: "${REPOSITORY_OWNER}" # Gets repo organization
TARGET_ID: "12590" # Replace with your target ID
run: |
curl -X POST "https://app.codacy.com/api/v3/organizations/${PROVIDER}/${ORG_NAME}/dast/targets/${TARGET_ID}/analyze" \
-H "Accept: application/json" \
-H "api-token: ${CODACY_API_TOKEN}"
```

CircleCI:

```bash
version: 2.1
jobs:
dast-scan:
docker:
- image: cimg/base:2021.04
steps:
- checkout
- run:
name: Run DAST Analysis
command: |
curl -X POST "https://app.codacy.com/api/v3/organizations/${PROVIDER}/${ORG_NAME}/dast/targets/${TARGET_ID}/analyze" \
-H "Accept: application/json" \
-H "api-token: ${CODACY_API_TOKEN}"

workflows:
version: 2
deploy-and-scan:
jobs:
# Your deployment job here
- dast-scan:
requires:
# Require your deployment job to finish first
- deploy
context:
- codacy-credentials # Store your secrets in a context
```

GitLab CI/CD:

```bash
stages:
- deploy
- security

dast_scan:
stage: security
image: alpine:latest
variables:
PROVIDER: "gitlab"
ORG_NAME: "${CI_PROJECT_NAMESPACE}"
TARGET_ID: "12590" # Replace with your target ID
script:
- apk add --no-cache curl
- |
curl -X POST "https://app.codacy.com/api/v3/organizations/${PROVIDER}/${ORG_NAME}/dast/targets/${TARGET_ID}/analyze" \
-H "Accept: application/json" \
-H "api-token: ${CODACY_API_TOKEN}"
# Run after deployment
needs:
- deploy
```

Jenkins:

```bash
pipeline {
agent any

environment {
PROVIDER = 'github' // or your git provider
ORG_NAME = 'your-organization'
TARGET_ID = '12590' // Replace with your target ID
}

stages {
// Your deployment stage here

stage('DAST Scan') {
steps {
// Use credentials from Jenkins credentials store
withCredentials([string(credentialsId: 'codacy-api-token', variable: 'CODACY_API_TOKEN')]) {
sh '''
curl -X POST "https://app.codacy.com/api/v3/organizations/${PROVIDER}/${ORG_NAME}/dast/targets/${TARGET_ID}/analyze" \
-H "Accept: application/json" \
-H "api-token: ${CODACY_API_TOKEN}"
'''
}
}
}
}
}
```
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 44 additions & 4 deletions docs/organizations/managing-security-and-risk.md
Original file line number Diff line number Diff line change
Expand Up @@ -522,9 +522,9 @@
The dependency tab is a business-tier feature. If you are a Codacy Pro customer interested in upgrading to gain access to this feature, contact our customer success team.


The **Security and risk management dependencies** page displays a unified view of all dependencies used by your repositories.
The **Security and Risk Management Dependencies** page displays a unified view of all dependencies used by your repositories.

To access the dependencies page, access the [overview page](#dashboard) and click the **Findings** tab.
To access the dependencies page, access the [overview page](#dashboard) and click the **Dependencies** tab.

![Security and risk management dependencies page](images/security-risk-management-dependencies-list.png)

Expand All @@ -534,12 +534,52 @@

![Security and risk management dependency page](images/security-risk-management-dependencies-single.png)

The dependency overview page offers a quick birds-eye view of that particular dependency. You'll be able to see all different versions that are being used, including which repository is using them, the oldest and most recent versions you're leveraging, as well as the highest criticality of security issues and the license <a href="#license-scanning"><sup>6</sup></a> applied to any particular version of that dependency.
The dependency overview page offers a quick bird's-eye view of that particular dependency. You'll be able to see all different versions that are being used, including which repository is using them, the oldest and most recent versions you're leveraging, as well as the highest criticality of security issues and the license <a href="#license-scanning"><sup>6</sup></a> applied to any particular version of that dependency.


<sup><span id="semgrep">1</span></sup>: Semgrep supports additional security rules when signing up for [Semgrep Pro](https://semgrep.dev/pricing/).
<sup><span id="yaml-only">2</span></sup>: Currently, Trivy only supports scanning YAML files on this platform.
<sup><span id="client-side">3</span></sup>: Supported as a [client-side tool](../repositories-configure/local-analysis/client-side-tools.md).
<sup><span id="spotbugs-plugin">4</span></sup>: Includes the plugin [Find Security Bugs](https://find-sec-bugs.github.io/).
<sup><span id="eslint-plugin">5</span></sup>: Includes the plugins [no-unsanitized](https://www.npmjs.com/package/eslint-plugin-no-unsanitized), [security](https://www.npmjs.com/package/eslint-plugin-security), [security-node](https://www.npmjs.com/package/eslint-plugin-security-node), and [xss](https://www.npmjs.com/package/eslint-plugin-xss).
<sup><span id="license-scanning">6</span></sup>: Visit the [supported languages and tools](../getting-started/supported-languages-and-tools.md#supported-languages-and-tools) page for a list of supported languages.
<sup><span id="license-scanning">6</span></sup>: Visit the [supported languages and tools](../getting-started/supported-languages-and-tools.md#supported-languages-and-tools) page for a list of supported languages.


## App scanning {: id="app-scanning"}

!!! important
App scanning is a business feature. If you are a Codacy Pro customer, contact our customer success team to access a short trial.

The **Security and risk management app scanning** page allows organizations to scan APIs and Web Applications for security vulnerabilities. This is part of our DAST (Dynamic Application Security Testing) capabilities, powered by ZAP.

Check failure on line 553 in docs/organizations/managing-security-and-risk.md

View workflow job for this annotation

GitHub Actions / vale

[vale] reported by reviewdog 🐶 [Vale.Spelling] Did you really mean 'APIs'? Raw Output: {"message": "[Vale.Spelling] Did you really mean 'APIs'?", "location": {"path": "docs/organizations/managing-security-and-risk.md", "range": {"start": {"line": 553, "column": 85}}}, "severity": "ERROR"}
Comment thread
joanasteodoro marked this conversation as resolved.

To access the app scanning page, access the [overview page](#dashboard) and click the **App scanning** tab.

![Security and risk management app scanning page](images/security-risk-management-app-scanning.png)
Comment thread
joanasteodoro marked this conversation as resolved.

App scanning tests applications in real-world scenarios, making it possible to find configuration and authentication issues or other runtime vulnerabilities that may impact your application’s functionality and security. It’s also a good method for preventing regressions and doesn’t depend on a specific programming language. As long as the application can be accessed through a browser, a DAST tool can typically scan it for vulnerabilities.

!!! note
Already using ZAP? [Upload your results via the API.](../codacy-api/examples/uploading-dast-results.md)

### How to scan a target
To scan a target, you can either go to the Security and Risk Management dashboard and access the App Scanning tab, or set it up for automation using our API.

!!! important
Only admins and organization managers will be able to create new targets and run scans (both in-app and via the API).
Comment thread
joanasteodoro marked this conversation as resolved.
Outdated


<div>
<iframe width="100%" height="472" src="https://www.youtube.com/embed/qPwHlIGJYXs?si=Q2Y5cmRelodtc05n" title="DAST targets" frameborder="0"
Comment thread
joanasteodoro marked this conversation as resolved.
Outdated
allowfullscreen>
</iframe>
</div>


Comment thread
joanasteodoro marked this conversation as resolved.
From within the tab, you're able to configure a new target by inputting the URL of the app or API you'd like to scan. You can configure up to 6 targets within your organization (if you need more, talk to your customer success representative).
Comment thread
joanasteodoro marked this conversation as resolved.
Outdated
Scans can be triggered manually via the app or the API. As you click to start a scan, it will be first added to that target's queue and then run. If you've got a new version of the app while running a scan, no problem: just add a new scan to the queue, and it will run immediately after. There are no limits to how many scans an organization can run per target, so this should accommodate all your deployment needs.
Comment thread
joanasteodoro marked this conversation as resolved.
Outdated
Once a scan is complete, its findings will be added to the findings tab, where you can review them using the filter **Scan types > DAST/App scanning**.

!!! note
Currently, DAST issues are only visible to admin and organization admin roles. We'll be reviewing this issue soon.
Comment thread
joanasteodoro marked this conversation as resolved.
Outdated

Next steps for this release include adding Authentication, which will allow scans to have a wider coverage and better, more meaningful results. If you have any feedback, feel free to share it with us or with your customer success manager.
Comment thread
joanasteodoro marked this conversation as resolved.
Outdated
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,7 @@ nav:
- codacy-api/examples/obtaining-current-issues-in-repositories.md
- codacy-api/examples/identifying-commits-without-coverage-data.md
- codacy-api/examples/uploading-dast-results.md
- codacy-api/examples/running-dast-scans.md
- Managing Codacy Self-hosted: "!include submodules/chart/mkdocs.yml"
- Troubleshooting and FAQs:
- General:
Expand Down
Loading