API Conformance Scan

API Conformance Scan is a dynamic runtime analysis of your API to check that the implementation behind your API and the behavior of the backend service matches the contract set out in the OpenAPI (formerly known as Swagger) definition of the API.

You can run a scan on an API you have imported to 42Crunch Platform and deployed to find out if there are any mismatches between the API definition describing your API and what it actually does. If Conformance Scan testing finds any discrepancies, it reports the issues clearly so that you can fix them.

The screenshot shows an example of the API summary tab of an API, with an overview of results from both API Security Audit and API Conformance Scan.

The scan generates real traffic to the selected API endpoint and could incur costs depending on your setup.

For best results, make sure that your OpenAPI definition is valid and well-formatted before you scan it. The API must be deployed so that the API endpoint is live, and the backend server your API uses must be accessible to Conformance Scan. Otherwise the API cannot be scanned.

If your account belongs to the free community organization, you cannot scan APIs in 42Crunch Platform, but you can still use the on-premises version of the scan.

Conformance Scan can have potential side effects: APIs can throw exceptions, fail, and data can be affected. As per our terms and conditions, you must only scan APIs that you own, and only against non-production systems and non-production data! Do not use Conformance Scan in production environment!

Scan v1 and Scan v2

We have introduced a new version of Conformance Scan, referred to as Scan v2. For backward compatibility and to avoid the adoption of the new version disrupting your day-to-day work, we have retained the previous version, Scan v1, and you can choose to continue to use it until the end of its deprecation period June 2024.

Both versions of Conformance Scan share the same core features and operation, but the new Scan v2 offers additional features and more flexibility, such as:

Where applicable, the difference between the scan versions has been clearly indicated in this documentation. Scan configurations and tokens are specific to a scan version: you cannot run Scan v2 using a Scan v1 scan token, and vice versa. When running a scan, make sure you specify the right scan token for the scan version you are using, otherwise Conformance Scan cannot use the associated scan configuration and fails to run.

You can run Scan v1 in 42Crunch Platform or on premises as a Docker image. Scan v2 is currently available only as Docker image for on-premises scan.

Scan v2 does not yet support customization rules.

What you can scan

Both OpenAPI Specification v2 and v3 are supported. The file size of your API should not exceed 10 MB.

By default, Conformance Scan limits the maximum length for strings in the requests it sends during the scan to 4096. If the properties minLength or maxLength or the length limits in a regular expression that you have defined for an API operation in your API definition conflict with this limit, it causes issues during the scan.

If the minimum length required is longer than the string length limit allowed in Conformance Scan, the scan cannot create the happy path request for that operation to establish a baseline. If the maximum length allowed in the API is longer than the allowed string length limit in Conformance Scan, the scan can create the happy path request but not the actual request during the scan.

In both cases, the operation is shown as a skipped operation in the scan report, but for different reasons. You must fix the operation in your API definition before it can be successfully scanned.

Conformance Scan does not support operations that require request bodies with the content type multipart/formData. Only request bodies with the content type application/json, application/x​-www-form-urlencoded, or text/plain are supported.

If your API definition has regular expressions with either positive or negative lookaheads defined, these may cause weird behavior, for example, in Conformance Scan.

How Conformance Scan works

The graphic shows the scand process as an arrow where the four steps follow each other from left to right.

  1. Preparation: Conformance Scan checks the defined scan configuration and prepares the pieces required for the scan:
  2. Happy path requests: Conformance Scan generates and sends a happy path request to all operations in your API to establish a successful benchmark. By default, any operations where the happy path request fails are skipped in the scan.
  3. Generating tests: The scan generates the test requests for the API operations in the scan based on the happy path requests. Each test request includes an intentionally tweaked element (header, body, parameters, HTTP method) so that the request no longer matches what the API expects. The implementation of the API should catch this and respond accordingly.
  4. Scan: Conformance Scan sends tests requests at a constant flow rate to the live API endpoint.
    • Conformance Scan waits for the API to respond within 30 seconds before it raises a timeout error for the request in the scan logs.
    • When the API responds, Conformance Scan analyzes the received response to determine if the API conforms to the contract it sets out in its OpenAPI definition.

Unlike the static testing in API Security Audit, Conformance Scan is dynamic testing and variable by nature. To better simulate real API traffic and more reliably test the API's behavior, the requests and parameter values that Conformance Scan generates are random, as is the order in which the requests are sent to the API. As a result, the API responses and the outcome of the scan can also vary. So do not be alarmed if you get slightly different results for your API in scans, that is completely normal.

You can customize how Conformance Scan behaves by creating scan rules and applying them to the APIs you want using tags. For more details, see Customizations.

Generating values for parameters

To successfully call the API operations in your API, Conformance Scan must follow the OpenAPI definition of the API and provide the required parameters in the calls. For this, when Conformance Scan loads the API definition in memory, it generates default values for each schema and parameter in the OpenAPI definition, and uses these values in the requests it sends. Because Conformance Scan scan does not generate any responses itself (it only validates the responses coming directly from the API), response schemas are excluded.

For the malformed test requests Conformance Scan can simply generate random values, intentionally disregarding the constraints for schemas and parameters. However, for the happy path requests, the generated values must match all defined constraints.

Some formats are not random at all, but follow a standard pattern as defined in the OpenAPI Specification (OAS). Conformance Scan uses a default generator to match the standard constraints of formats like:

  • Date and time (uses the current date and time by default, formats as defined by RFC 3339)
  • Email addresses
  • Hostnames
  • IP addresses (both IPv4 and IPv6)
  • URIs
  • JSON pointers
  • UUIDs

If the data format itself does not set a standard pattern, Conformance Scan uses the constraints set in your OpenAPI definition. If you provide a regular expression for a schema or parameter, Conformance Scan uses that to generate the value. Otherwise, Conformance Scan generates the value on its own.

Providing examples

It may be very difficult to create valid values for some things, like some object schemas, or strings with a very specific pattern. To ensure best performance, if you have complicated schemas in your API, we recommend including some examples for these kind of values directly in the OpenAPI definition.

There are several properties you can use for this, in the order of preference:

  • x-42c-sample
  • default
  • enum
  • example

If the property x-42c-sample contains a value that is not valid against the schema, Conformance Scan tries to load the value from the property default, and so on, until it finds a sample value it can use. As a last resort, or if no samples are provided at all, Conformance Scan generates a value from scratch. If Conformance Scan cannot generate a default value that an API operation requires, that operation is skipped in the scan.

For more details on the vendor extension, see x-42c-sample. For more details on the other properties, see the OpenAPI Specification (OAS).

Conflicts from regular expressions

When generating values, Conformance Scan considers the properties minLength, maxLength, and pattern separately. This means that if the string limitations in the regular expression in pattern do not match minLength and maxLength values Conformance Scan may not be able to generate a valid value. To prevent this, if Security Audit detects a conflict between these string properties, it raises an issue about it that prevents scanning the API until the issue has been resolved.

There are several reasons why the conflict could happen. For example, instead of defining exact for length in the regular expression, you could have used + or *:

"example": {
    "type": "string",
    "minLength": 2,
    "maxLength": 5,
    "pattern": "^[a-z]+$"
}

We recommend that instead of using + or *, you properly specify the length in the regular expression. If the regular expression is simple, you can specify the length in both the pattern and minLength and maxLength, as long as the values do not conflict:

"example": {
    "type": "string",
    "minLength": 2,
    "maxLength": 5,
    "pattern": "^[a-z]{2,5}$"
}

If you have a complex regular expression with multiple segments, the lengths of all segments and minLength and maxLength must match. In this case, it is probably better to properly specify the length limits in the regular expression, and omit minLength and maxLength:

"example": {
    "type": "string",
    "pattern": "^(https?:\\/\\/)?(www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{2,256}\\.[a-z]{2,6}\\b([-a-zA-Z0-9@:%_\\+.~#?&//=]*)$"
}

Remember to include the anchors ^ and $ in your regular expression, otherwise the overall length of the pattern could be considered infinite. If you include the anchors in the regular expression and the pattern only has fixed or constant quantifiers (like {10,64}, for example), you do not have to define the property maxLength separately for the object, as the length is fully constrained by the pattern. However, if the regular expression does not include the anchors or its quantifiers are not fixed (like in ^a.*b$), it can be considered to be just a part of a longer string and the property maxLength is required to constrain the length.

In both cases, it is always beneficial to provide an example value that Conformance Scan can use when generating happy path requests.

Types of requests

Conformance Scan sends different types of requests for different purposes. Happy path requests and test requests are part of both Scan v1 and Scan v2, but unhappy path requests and custom requests can only be configured for the new Scan v2, not for Scan v1.

Happy path requests

Conformance Scan needs a benchmark to determine if the incorrect behavior of the API was caused by the test request or some other failure. To establish this benchmark, Conformance Scan first sends a happy path request to the operations in the API before it starts the actual scan.

A happy path request is a valid request generated directly from the OpenAPI definition of your API, designed and expected to always succeed. Conformance Scan generates and sends this request to each operation defined in your API, and validates the responses it received.

For a happy path request to be a success, the response must be either successful or expected: the received HTTP status code must be 200399, or 404 (because the likelihood that the scan manages to generate a value that matches an existing ID is vanishingly small). Otherwise, the happy path request fails. If a happy path request fails, the operation in question is skipped in the scan, because any results for it would be inconclusive without a successful benchmark.

Happy path request failing often indicates significant issues in your OpenAPI definition that you must fix before Conformance Scan can scan the failing operation. Running Security Audit and checking what kind of issues it raises helps you find the culprits. The happy path request can also fail because the connection to the defined endpoint was broken, or the API took too long (over 30 seconds) to respond.

If any of the happy path requests fail during the scan, the scan is marked as incomplete. If all API operations cannot be scanned, it is impossible to know what sort of issues the scan might uncover on the untested ones and thus the achieved results cannot be considered as the full story. Only once all happy path requests are passing and all operations in the API can be scanned can the scan be considered complete.

If your API defines more than one HTTP status code for success and you want to test all of these, you can define additional scan scenarios to ensure happy path requests cover all response codes.

Unhappy path requests

This applies to Scan v2 only.

Happy path requests, as their name implies, are the cases where everything goes well, which in most cases is how things should go. But sometimes you might want to test the implementation for HTTP response status codes for errors (usually 4XX). Because the happy path requests consider these response codes as unsuccessful, they cannot provide the baseline for how the received response for error codes should look like. This is where unhappy path requests come into play.

To be able to see how the API responses from your error handling do in Conformance Scan, you can configure unhappy path requests that define what to normally expect for the specific error responses you want to test. Conformance Scan will run the unhappy path requests alongside the normal happy path requests to establish the baseline for the normal API responses from error handling, so that it can run the actual test requests against these endpoints during the scan.

Unhappy path requests are configured as scan scenarios.

Lax testing mode

This applies to Scan v2 only.

In the normal testing mode, any operations where the happy path request fails are skipped in the scan, because Conformance Scan could not establish a baseline against which to compare the scan results. However, sometimes it might be useful to scan operations regardless of failing happy paths, even if the scan results might not be as reliable.

For this purpose, you can change the setting for the scan testing mode from the normal mode to lax testing mode in the scan configuration of your API. In lax testing mode, Conformance Scan still runs happy path requests and notes if they succeeded or failed, but it also runs the conformance requests even on operations with failed happy path requests. You can see in the scan report which testing mode was used.

An example screenshot of a scan report summary that shows the scan was run in lax testing mode

Depending on your API and the scan configuration, changing the normal testing mode to lax may result in significantly more tests and bigger scan reports than before, so you may have to adjust your scan settings to get the full scan report.

Lax scan testing mode is only supported in the Scan v2 Docker image v2.0.6 or higher.

Conformance requests

Once Conformance Scan has the baseline for what a success for a particular API operation looks like, it is ready to test if the API implementation correctly catches and handles malformed or erroneous requests. These conformance requests are the actual test requests that Conformance Scan runs, designed to uncover issues in the error handling of your API implementation and where it does not conform to what the OpenAPI definition of the API declares.

Each test request includes an intentionally tweaked element (header, body, parameters, HTTP method) so that the request no longer matches what the API expects. The implementation of the API should catch this and respond accordingly. The tweaks that Conformance Scan does in the test requests fall into three categories:

  • Omit: Conformance Scan omits an element that the scanned API definition requires from the test request
  • Add: Conformance Scan adds an extra element that is not included the scanned API definition into the test request
  • Fuzz: Conformance Scan changes an element of the test request so that it no longer matches what is defined in the scanned API definition (for example, using a value that does not match the schema constraints)

Custom requests

This applies to Scan v2 only.

Sometimes you might want to test a very specific thing in your API implementation and the normal conformance tests cannot catch that. In this case, you can write your own custom test request that captures the issue you want to test. The custom test can be as complex or as simple as needed: for example, you might just want to check that an authorization scenario works with the correct credentials, or you might want to define a test that would inject a specific input to see how your API behaves.

Custom requests are configured as scan scenarios for a particular operation. You cannot define a custom test on a global level for your API.

Scan configuration

To successfully scan an API, Conformance Scan needs some basic information on what it is supposed to do:

  • What API to scan?
  • Which endpoint to send the requests to?
  • How to authenticate to the API, if that is required?

For this, Conformance Scan needs a scan configuration, a JSON file that captures these details for each API that you want to scan.

Scan configurations and tokens are specific to a scan version: you cannot run Scan v2 using a Scan v1 scan token, and vice versa. When running a scan, make sure you specify the right scan token for the scan version you are using, otherwise Conformance Scan cannot use the associated scan configuration and fails to run.

You can quickly create a basic scan configuration in 42Crunch Platform by providing some basic information, or if a more complex scan configuration is needed, you may choose to work on it outside the platform in an editor of your choice and upload the finished configuration to the platform. You can also update your existing configurations later, for example, to enhance them or take advantage of new improvements. Scan configurations are stored encrypted in 42Crunch Platform.

An example screenshot showing the Pixi API with four different scan configurations: one for Scan v1 in platform, one for Scan v1 on premises, and two configurations for Scan v2, one of which is not valid when compared against the OpenAPI defiinition of the API. The default scan configuration has been selected as the reference scan configuration.

All available scan configurations for an API are listed on the Conformance Scan page. How many scan configurations a single API can have depends on the version of the scan you want:

  • For Scan v1, you can have one scan configuration for running Conformance Scan on 42Crunch Platform and another for running it on premises. You can update these configurations as needed, but you cannot create more scan configurations.

    Scan v1 configurations do not state what percentage of the API operations in the API they cover, or the estimated number of tests that could be run with them. This information is provided only for Scan v2 configurations.

  • For Scan v2, you can have as many scan configurations as needed.

The details that you can view on a scan configuration depend if the configuration is for Scan v1 or Scan v2.

For more information on what you can do with scan configurations, see Scan configuration details .

Reference scan configuration

Reference scan configuration is the quality reference for your API: because a single API can have multiple scan configurations for different purposes (like testing in general or very specific scenarios), not all of them give as good a picture of the overall quality of your API.

For example, a configuration for testing a specific scenario might only need to cover a few of your APIs endpoints, so the results would not properly describe your API as a whole. Or you might have just started to experiment with Scan v2 and so your scan configuration for that might still be a work in progress. For this reason, it is possible to choose which of the scan configurations best represents how good the API implementation is overall.

The statistics and results of the reference scan configuration are the ones shown for your API in the list of APIs in the API collection, and on the scan results, scan trends, and the security quality gate (SQG) status that are displayed on the API summary tab. You can view the results from other configurations in the list of scan reports, but only the results from your reference scan configuration are shown elsewhere.

It usually makes sense to first try a scan configuration to see how the results look before choosing it as the reference configuration. If you set a scan configuration as the reference configuration before running Conformance Scan using it, your API will not show any scan results (except in the report list) even if you had scanned the API using other scan configurations. Of course, if your API only has one scan configuration, then that also automatically is the reference configuration.

Because the reference scan configuration is needed to provide scan statistics for your API, you cannot delete that scan configuration before you choose a new reference scan configuration.

Scan token

Creating a scan configuration also produces a scan token. The token indicates to Conformance Scan which API it should scan and with which settings. If running Conformance Scan on premises in a Docker container, the scan token is passed in the environment variable SCAN_TOKEN. When Conformance Scan starts, it connects to 42Crunch Platform and fetches the scan configuration that matches the specified scan token. This ensures that the on-premise scan runs the correct configuration for your API. If running Conformance Scan in 42Crunch Platform, you do not have to provide the scan token separately.

Scan configurations and tokens are specific to a scan version: you cannot run Scan v2 using a Scan v1 scan token, and vice versa. When running a scan, make sure you specify the right scan token for the scan version you are using, otherwise Conformance Scan cannot use the associated scan configuration and fails to run.

When the on-premises scan starts, it establishes a a two-way, HTTP/2 gRPC connection to 42Crunch Platform at the address services.<your hostname> and the port 8001. Make sure that your network configuration (like your network firewall) authorizes these connections. The on-premises scan uses this connection to verify the scan token and to download the scan configuration you have created. During runtime, on-premises scan uses the connection to send the scan report and logs to the platform.

If you are a user in the free Community organization and access 42Crunch Platform at https://platform.42crunch.com, your hostname is 42crunch.com, and the endpoint you must enable is services.42crunch.com.

If you are an enterprise customer not accessing 42Crunch Platform at https://platform.42crunch.com, your hostname is the same one as in your platform URL.

Scan configuration validation report (SCVR)

This applies to Scan v2 only.

Whenever you create, update, or upload a scan configuration for an API, Conformance Scan checks the created configuration and provides a scan configuration validation report (SCVR) that gives you useful information on the configuration, such as:

  • How many API endpoints and response HTTP status codes defined for the API in question does the scan configuration cover.
  • How many conformance tests Conformance Scan can run using this configuration.
  • How many custom tests have been defined in the scan configuration.

The screenshot shows the general infrormation tab of a scan configuration. The SCVR section provides statistics on the operation and response coverage and shows that no erros were found in the scan configuration, meaning that it  is valid for the API in question.

By default, the basic scan configuration that 42Crunch Platform creates automatically is based directly on the OpenAPI definition of the API, and thus always valid for that API. However, if you edit the basic configuration further, or indeed create a more complex scan configuration with additional features, it is possible that you might inadvertently introduce discrepancies or errors into the scan configuration so that Conformance Scan could no longer successfully scan the API because the scan configuration now contradicts its OpenAPI definition.

The SCVR lets you detect such errors already before you run Conformance Scan: if Conformance Scan finds any discrepancies that would automatically mean that the scan could not successfully run with that configuration, these errors are flagged to you in the SCVR so that you can fix them.

An exmple of a scan configuration that is not valid for the API in question, the SCVR is showing that there is an error in the configuration.

You cannot run a scan using a scan configuration that is not valid for API in question. You also do not get coverage statistics until the configuration has been fixed.

Response validation

Conformance Scan tests how the API implementation handles, for example, requests to operations not defined in the OpenAPI definition at all, or misconfigured requests to existing operations. How the API responds to the crafted test requests in the scan determines whether or not it conforms to the contract it sets out in its API definition. To catch issues, Conformance Scan validates the response from the API and considers, for example, the following:

  • Is the provided HTTP status code defined in the response object in the API definition?
  • Are all headers in the response defined in the response object in the API definition and do they match the defined schema? Are all required headers present in the response?
  • Is the returned response body too big?
  • Should the response even have a body (method HEAD or returned status code HTTP 204)?
  • Does the Content-Type of the returned response match the types defined in the content map in the API definition, and does it match the defined schema?

If the response body in the response from the API exceeds 8 KB, it is truncated.

Response validation is done in two parts:

  1. Response code: Did error handling work? Did the received HTTP status code in the API response match what Conformance Scan expected or not? Or in the worse case, did the intentionally malformed request not raise an error at all?
  2. Contract conformity: Did the received response match what is defined in the OpenAPI definition of the API?

From security risk perspective, incorrect error handling poses a bigger risk for the API implementation than response content, and therefore Conformance Scan focuses on it first.

  • For requests to non-existing operations, Conformance Scan expects the API to respond with HTTP 405 Method not allowed. Any other response is considered to be wrong.
  • For misconfigured requests to existing operations:
    • The returned HTTP status code must be equal to or greater than HTTP 400 to indicate an error.
    • The returned HTTP status code (or a default response) must be defined in the OpenAPI definition of the API.

Based on this, Conformance Scan splits the received response codes into three classes:

  • Incorrect: The API did not raise an error, but responded with a success to a malformed request. This means that the API implementation does not catch and handle the error at all, indicating serious problems.
  • Unexpected: The received response code does not match what Conformance Scan expected for the test request, but the API implementation still raised an error, if not the correct one. This means that there are some problems in the error handling in API implementation, but at least the issue is caught.
  • Expected: The received response code matches what Conformance Scan expected for the intentionally malformed request, and the API implementation raised the error correctly. This means that the API behavior is good.

However, even if response codes match what Conformance Scan expects, it does not mean all is well. Conformance Scan could also uncover discrepancies between the API contract set out in the OpenAPI definition and the backend API implementation:

  • The returned response body must match what is defined in the API definition for the returned HTTP status code.
  • The returned response headers must match what is defined in the API definition (if response headers are defined).

Based on analyzing the response bodies and headers, the received responses are flagged either conformant or not conformant in respect to the API definition.

By default, Conformance Scan does not follow redirects (HTTP 3XX) in API responses to analyze the final response, but instead analyzes the received redirect. Depending on your API, this could result in conformance failure if the response definition in you API is the expected final response that the redirects would lead to. You can change this behavior in scan settings, if needed, but we do not recommend it as it may prevent the scan from completing: the final response from a redirect could often be in an unsuitable format, resulting in error. By not following redirects, Conformance Scan can complete and successfully evaluate the main concern: is the error handling of your API implementation working as it should.

Scan report

Conformance Scan produces a scan report that provides valuable information on how well your API conforms to its API definition. The report summarizes how many tests were run, what was scanned, and how the scan went. You can also check how severe the found problems were.

The screenshot shows an API that has four scan reports listed in the scan report list: two for Scan v1 (one run on premises, another in 42Crunch Platform), and the two others for two different scan configurations for Scan v2.

You can download a copy of the report, for example, to share the results outside the platform.

Expected and unexpected HTTP status codes

HTTP status codes are a crucial part of API traffic: they allow communicating the status of a request back to its sender, like backend services responding back to clients and API consumers but also microservices communicating with other microservices within the same architecture. Especially in the latter case, sending back a wrong response code could have serious and unforeseen consequences down the line, which is why response code analysis is a critical part of Conformance Scan.

The issue details in the scan report show both which HTTP status codes Conformance Scan received and which it expected to receive for any given test. This helps you decide how to fix the possible discrepancies. For Scan v1, Conformance Scan also shows the source of its expectation for a particular HTTP code:

  • 42Crunch default expectations: These are HTTP status codes that Conformance Scan expects to receive based on standards, such as RFC 7231 or RFC 7235.
  • Customization rules: These are HTTP status codes that have been defined as expected response codes in the scan rules applied to the scanned API.

We recommend using HTTP status codes as defined in RFCs as much as possible to avoid any accidental mismatches between the sending and the receiving end.

Running Conformance Scan on premises

Running Conformance Scan in 42Crunch Platform is quick and straightforward, but in some cases it might not offer enough options for your needs, or you might want to store the data from scans in your own system. In this case, you can deploy and run Conformance Scan locally as a Docker image.

For users in the free Community organization, and currently for Scan v2, running the scan on premises is the only option available.

To run on-premises scan, you create a scan configuration in 42Crunch Platform and then pull and run the Conformance Scan Docker image from Docker Hub, using the configuration you created by providing the scan token of the configuration to be used in your Docker command. Scan configurations and tokens are specific to a scan version: you cannot run Scan v2 using a Scan v1 scan token, and vice versa. When running a scan, make sure you specify the right scan token for the scan version you are using, otherwise Conformance Scan cannot use the associated scan configuration and fails to run. You must update your scan configuration before you can see the effect from some updates to Conformance Scan.

When the on-premises scan starts, it establishes a a two-way, HTTP/2 gRPC connection to 42Crunch Platform at the address services.<your hostname> and the port 8001. Make sure that your network configuration (like your network firewall) authorizes these connections. The on-premises scan uses this connection to verify the scan token and to download the scan configuration you have created. During runtime, on-premises scan uses the connection to send the scan report and logs to the platform.

If you are a user in the free Community organization and access 42Crunch Platform at https://platform.42crunch.com, your hostname is 42crunch.com, and the endpoint you must enable is services.42crunch.com.

If you are an enterprise customer not accessing 42Crunch Platform at https://platform.42crunch.com, your hostname is the same one as in your platform URL.

Regular users can only create scan configurations and run the on-premises scan on APIs in their own API collections. Organization administrators can create scan configurations and run the on-premises scan on all APIs in their organization.

You can check where (in 42Crunch Platform or on premises) the latest scan run on the API summary page.

The screenshot shows the panel for Conformance Scan on the API summary: the badge on the upper right corner indicates that the latest scan was run on premises and the button to rerun the scan is not available.

If you are on the API summary page or in the list of scan reports on the UI when the scan finishes, you must refresh the page before the on-premises scan report is available on the UI.

For more details on how to run the on-premises scan and customize the scan configuration, see Scan API conformance.

Using environment variables in Scan v1

When running Conformance Scan on premises, you can use environment variables and supply values for them in your Docker command when you run the scan. This way you can easily test the different authentication methods for your API.

When configuring the authentication for on-premises scan configuration, you can enter an environment variable to any field instead of hard-coding a value. The environment variable can be called anything you want, as long as fulfills the following criteria:

  • Must be inside curly brackets ({})
  • Must start with $
  • Cannot contain other special characters than -, _, and .
  • Must be longer than one character (just {$} is not a valid environment variable)

An example screenshot showing configuring token authentication for scan. The header value has been replaced with an environment variable.

Environment variables are currently not supported for mutual TLS password.

When you run the on-premises scan, you provide the values for the environment variables in your run command. The variables must have a prefix SECURITY_ added before them, for example:

docker run -e SCAN_TOKEN=<your scan token> -e SECURITY_ACCESS_TOKEN='<the access token value you want to use>' 42crunch/scand-agent:latest

Providing authentication details for Scan v2

For Scan v2, the scan configuration is generated automatically from the OpenAPI definition of the APIThe credential values are not hardcoded to the configuration, instead the configuration lists the credentials and their corresponding environment variables (for example, SCAN42C_SECURITY_OAUTH2), and you can provide the credentials you want to use in your Docker command.

The basic scan configuration is generated automatically directly from your OpenAPI definition, and all found authentication methods are automatically given the environment variables (for example, SCAN42C_SECURITY_OAUTH2) that are used to provide the values for credentials in the Docker command when running the scan.

A compilation of three example screenshots show how the authentication details are shown on the Authentication and Web editor tabs of a Scan v2 configuration.

When you run Scan v2, you provide the values for the variables in your run command:

docker run -e SCAN_TOKEN=<your scan token> -e PLATFORM_SERVICE=services.42crunch.com:8001 -e SCAN42C_SECURITY_OAUTH2='<the token value you want to use>' 42crunch/scand-agent:v2

If you do not provide credentials to all required authentication methods listed in your scan configuration, Conformance Scan cannot run tests on all API operations because it cannot authenticate to your API.

Scan logs

As part of its operation Conformance Scan produces logs. By default, the logs are stored and can be viewed in the platform, but when running Conformance Scan (either Scan v1 or Scan v2) on premises, there are more options.

By default, Conformance Scan run on premises writes all log levels as standard output (STDOUT) to console and your terminal, but only uploads error and critical level scan logs to 42Crunch Platform. You can also direct the STDOUT logs to be consumed downstream services (see the documentation for your environment for how this is done), or write the logs in a volume that you mount as part of your run command. The scan writes logs to the file <your local filepath>/opt/scand/log/<task ID>-<epoch timestamp>-scand.log.

The default size limit for the log file is 100 MB, but you can also limit the size more, if needed. When you create the scan configuration for on-premises scan, you can also choose how many issues you want the scan to report (default is 1000). Decreasing the maximum number of reported issues also decreases the maximum possible size of a single scan report. Large response bodies do not inflate the logs: response bodies over 8 KB are truncated.

If the log file size exceeds the size of the volume you mounted, the scan raises errors but Conformance Scan continues to run normally. These errors are also uploaded to 42Crunch Platform, but the rest of the debug and info level logs are only written as STDOUT, not to file.

If you set the log level to debug in when running Scan v2, all the values of all variables in your scan configuration are printed in the clear in the scan logs. Depending on your API, this can include credentials.

Errors in Conformance Scan

Occasionally, Conformance Scan might fail to scan your API. The reason for this could be, for example:

  • Invalid OpenAPI definition: You API definition has critical errors that are preventing Conformance Scan from running. For example, the structure of your API might not conform to the OAS. Use API Security Audit to check your API definition and fix any found issues in Security Editor, then try Conformance Scan again.
  • Invalid scan configuration: The configuration you set up for the scan does not match your API definition and thus is not valid. For example, you might have chosen an authentication method that does not match the ones defined in your API definition. Try configuring and running Conformance Scan again, making sure the authentication details match your API definition.
  • Scan cannot reach API endpoint: Conformance Scan tried to run the scan but failed to reach the API endpoint you had selected for the scan. The API host could be down, or there could be an error in the URL, especially if entered a custom URL. Check the URL and the host of your API and try again.
  • Timeout: The scan took longer than the maximum scan duration (3600 seconds).