API Scanning: CI/CD Integration

 

This article describes how to start a scan against a specific API using Data Theorem’s API.

This can for example be used as part of a CI/CD pipeline in order to start API scans after deploying a new version of the API.

 

Starting a scan against a RESTful API

Data Theorem’s API can be used to start a scan against a specific RESTful API:

  1. Retrieve an API Key that has the permission to start API Secure scans; API keys are available in the Data Theorem portal at https://www.securetheorem.com/devsecops/v2/scancicd.

  2. Retrieve the RESTful API’s ID from the API’s page in the Data Theorem portal:

     

  3. An API scan can then started using the following CURL command:

    curl -X POST https://api.securetheorem.com/apis/devops/v1/asset_scans/restful_api_scans \ -H "Content-Type: application/json" \ -d '{"asset_id":"89ad145e-8242-41a4-93c1-5fc2c633b49d", \ "asset_base_url":"https://orderfood.google.com"}' \ -H "Authorization: APIKey ABCD123456="

    The response will contain information about the scan in the following format:

    { "id":"06bd22cb-ad9b-48d3-8158-4b3cd6142db6", "asset_id":"89ad145e-8242-41a4-93c1-5fc2c633b49d", "asset_base_url":"https://orderfood.google.com", "asset_type":"RESTFUL_API", "status":"ONGOING", "failed_reason":null }

     

  4. (Optional) Using the ID of the scan that was returned in the previous call, the following CURL command can be used to check the status of the scan:

    curl -X GET 'https://api.securetheorem.com/apis/devops/v1/asset_scans/restful_api_scans/06bd22cb-ad9b-48d3-8158-4b3cd6142db6 \ -H "Authorization: APIKey ABCD123456="


    Once completed, the results of the scan will be visible in the Data Theorem portal in the RESTful API’s asset page.

Additional options for RESTful API scans

Optionally, the following configuration settings can be specified within the

  • should_perform_pii_analysis: If set to True, the API responses received by the scanner will be analyzed for PII data (Hack&Extract).

  • should_perform_sql_injection_scan: If set to True, the API’s parameters will be scanned for SQL injection issues (Detect&Inject).

    • Warning: this type of scan requires sending a lot of requests to the API, will significantly increase the load on the API, and could potentially disrupt it.

For example, the following CURL command will enable PII scanning:

Starting a scan against a GraphQL API

Similarly to RESTful APIs, Data Theorem’s API can be used to start a scan against a specific GraphQL API:

  1. Retrieve an API Key that has the permission to start API Secure scans; API keys are available in the Data Theorem portal at https://www.securetheorem.com/devsecops/v2/scancicd.

  2. Retrieve the GraphQL API’s ID from the API’s page in the Data Theorem portal:

     

  3. An API scan can then started using the following CURL command:


    Once completed, the results of the scan will be visible in the Data Theorem portal in the GraphQL API’s asset page.

Starting a scan against all assets in an Asset Group

In addition Data Theorem’s API can also be used to start a scan against all API-type assets that are currently supported by the integration in a specified asset group:

  1. Retrieve an API Key that has the permission to start API Secure scans; API keys are available in the Data Theorem portal at https://www.securetheorem.com/devsecops/v2/scancicd.

  2. Retrieve the Asset Group’s ID from the API’s page in the Data Theorem portal:

     

  3. An API scan can then started using the following CURL command:


    One scan per supported asset in the asset group will be created, and once completed, the results of the individual scans will be visible in the Data Theorem portal on the API’s asset pages.

Integrating into a CI/CD pipeline

GitHub Action

A Github Action for API scanning is available at https://github.com/marketplace/actions/data-theorem-api-secure.

Other CI/CD platforms

Most CI/CD platforms (Travis CI, CircleCI, etc.) allow running a bash script as a step within the CI pipeline.

The following file is an example of a GitHub workflow that will trigger an API scan every time the repository is tagged with a new version. A similar workflow can be configured on other CI/CD platforms.

To setup the workflow:

  1. Create a new secret containing your API key (called DATATHEOREM_API_KEY in the below example).

  2. Create a new workflow by creating a file at .github/workflows/datatheorem.yaml with the following content: