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 panel also shows that the latest scan was run in 42Crunch Platform.

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!

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 and application/x​-www-form-urlencoded are supported.

How Conformance Scan works

After you have created a scan configuration for your API, Conformance Scan takes over and starts the scan process:

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 scan configuration you created 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. Any operations where the happy path request fails are skipped in the scan (see Happy path requests).
  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 (see Response validation).

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 set 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 meas 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.

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.

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.

An example screenshot showing scanned and skipped operations on the filter sidebar.

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.

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. This is the worst case and the result is shown in red.
  • 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. The result is shown in amber.
  • 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 and the result is shown in green.

The screenshot shows an example filter row for results from a scan. The results on response codes and contract conformance are ordered from the worst cases on the left to those where everything is good on the right. The filter bar also shows the percentage of each result class from the total number of tests run.

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 as failures or successes in contract conformity.

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.

API endpoints in Conformance Scan

By default, Conformance Scan lists endpoint URLs that are parsed directly from your OpenAPI definition. However, if you want to use a URL that is not listed, you can also enter it when you configure the scan settings.

A screenshot of selecting the API endpoint in the scan configuration wizard

If you want to override the API endpoint defined in your API definition and scan a different endpoint, make sure you specify a valid host for the paths in your API definition. For example, if your API follows OAS v2 and uses a basePath, make sure you include the basePath in the URL you enter, otherwise the basePath is ignored in the scan configuration.

The URL you enter for the API endpoint must fulfill the following criteria:

  • It is a public URL.
  • It specifies either http or https (for example, or https://api.example.com/v2).
  • It is not an internal address (for example, http://localhost or
  • It does not include parameters (for example, http://www.example.com/products?id=1&page=2).
  • It does not include anchors (for example, http://www.example.com#up).

Authentication in Conformance Scan

If you have defined authentication for your API or its operations, Conformance Scan must provide the required details to authenticate when it sends requests to the API.

When you configure the scan, you must therefore fill in the details for the security schemes in your API that you want to use in the scan. The configuration wizard shows all security schemes defined in the OpenAPI definition of your API:

A screenshot of authentication configuration. Two security schemes and the fields for configuring their details are listed, one for API key and one for session ID.

Fill in the details for the security schemes you want to use in the scan. You can leave the security schemes that you do not want to use in the scan empty and Conformance Scan will ignore these schemes. Any API operations that use only these security schemes for authentication are skipped in the scan.

If you have not defined any security requirements in the API definition, no authentication is required.

With on-premises scan, instead of hard-coding the authentication details in the scan configuration, you can use environment variables. See Using environment variables with on-premises scan.

Conformance Scan currently supports the following authentication types:

  • Basic authentication
  • API keys in headers, query strings, or cookies
  • Bearer token
  • OAuth 2
  • OpenID Connect (OAS v3 only)

To configure OAuth2 authentication, you must first manually obtain an access token that Conformance Scan can use to authenticate to your API. In the scan configuration wizard, authentication with OAuth token is configured like bearer token. For more details on OAuth2, see RFC 6749.

If needed, you can also configure mutual TLS for client authentication. The client certificate must be in p12 format. For more details, see Scan API conformance.

If your run Conformance Scan from the platform, the authentication details are only used in the current scan and are not stored anywhere. If your run Conformance Scan on premises, the authentication details are stored encrypted as part of the scan configuration in the platform. The authentication details are not retrievable and credentials are hidden.

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).

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 tests and their findings are listed by path and operation, and one operation can have multiple tests run against it, in which case it lists the results for all of them. Above the list of found issues, you have "Critical to Success" filter bar that you can use to home in on the scan results:

  • OWASP vulnerabilities: Which OWASP API Security Top 10 vulnerabilities Conformance Scan found in your API.
  • Operations not tested: Which operations could not be tested in the scan and why.
  • Test results: How the received API responses were classified in response validation. The results are grouped in the order of severity, starting with the most critical issues on the left. As you address the issues, they move to the right towards the other end of the scale where everything is good.

An example of a scan report

The filter bar also shows the distribution (in percentage) of the test results between different result classes.

To see this latest version of scan report with the "Critical to Success" filter bar, you need to scan your API again. Otherwise, you see the old style can report with the bars charts for paths above the list of found issues. If running Conformance Scan on premises, you need 42crunch/scand-agent:v1.16.0 or later to get the new style scan report.

You can click on the filters to view only the results you are interested in. These filters are not cumulative, meaning that clicking on one changes the listing completely, it does not add more results to the existing view. However, within these main filters, you can further refine the current result list using the additional dropdown filters.

The filter sidebar on the left lets you filter the results by path, and also shows how many issues were found in each path, as well as which operations the scan had to skip, for example, because the happy path request failed.

An example screenshot showing scanned and skipped operations on the filter sidebar.

Clicking an issue in the result list provides further details on it, such as the description and ID of the test that the scan performed, the URL the scan called, the response time of the API, and the size and content type of the response. The issue details also show which response codes Conformance Scan expected to receive as well as where that expectation comes from.

An example on the details of an issue the scan found, including the ID of the test that was run.

To make it easier to reproduce the results, the report also provides the cURL requests the scan used to detect each issue.

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

Like with the audit score, you can also see how the number of issues that Conformance Scan found in your API has changed over time in the Conformance Scan trends chart on the API summary page.

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.

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.

On-premises scan

Instead of running Conformance Scan from the platform UI, you can deploy and run it locally as a Docker image. For users in the free community organization, running Conformance Scan on premises is the only option available.

To run on-premises scan, you create a scan configuration and then pull and run the Conformance Scan Docker image from Docker Hub, using the configuration you created.

On-premises scan produces a scan report just like when you run the scan from 42Crunch Platform, and you can view it the on-premises scan tab of the API. This tab also provides a menu to view the scan logs and the scan configuration of the API.

An example screenshot of the report from on-premises scan for the Pixi API.

At the moment, the on-premises scan status of an API is not shown separately on the API collection page. However, clicking the scan results in the API collection or the read report button on the API summary tab takes you to view the latest available report regardless of was the scan run in 42Crunch Platform or on premises.

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. If the latest scan was on premises, you cannot rerun the scan directly from 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.

However, you can keep running Conformance Scan on premises normally. If you want to run the scan in the platform instead, you can start it either from the main menu or the platform landing page.

Scan configuration and scan token

On-premises scan requires a scan configuration that provides the details and settings what kind of scan to run and on which API. This configuration is created and updated in 42Crunch Platform, and it is stored encrypted. Currently, each API can have only one scan configuration.

An example screenshot of a scan configuration. The scan token is hidden by default and shown as Xs.

Choosing the API and the API endpoint to be scanned and configuring the possible authentication are same as for a regular scan. In addition, for on-premises scan, you can configure some additional settings to customize it. Configuring these settings is entirely optional and not needed in most cases, the default settings that Conformance Scan uses are usually enough. However, for more advanced use, the settings let you tweak some aspects of the scan, such as memory limits. For more details, see Adjust the scan configuration for on-premises scan.

Creating a scan configuration also produces a scan token. The token indicates to the on-premises scan which API it should scan and with which settings. When you run the Docker container for on-premises scan, the scan token is passed in the environment variable SCAN_TOKEN. When the on-premises 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.

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.

For more details on how to run the on-premises scan and customize the scan configuration, see Run Conformance Scan on your premises.

Using environment variables with on-premises scan

Because each API can have only one scan configuration that on-premises scan uses, you must delete the existing configuration before you can reconfigure the scan. However, for authentication details, you can use environment variables and supply the values when you run the on-premises 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 value.

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

On-premises scan logs

As part of its operation Conformance Scan produces logs. When running the scan in 42Crunch Platform, the logs are in the platform too. However, when running Conformance Scan on premises, there are more options.

By default, on-premises scan 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.