Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions CONTAINER_DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Inputs documented in the GitHub Actions [README](README.md#inputs) are all suppo
|`failThreshold`|`FAIL_THRESHOLD`|`CONTRAST_FAIL_THRESHOLD`|
|`jobStartTime`|`JOB_START_TIME`|`CONTRAST_JOB_START_TIME`|
|`severities`|`SEVERITIES`|`CONTRAST_SEVERITIES`|
|`sessionMetadata`|`SESSION_METADATA`|`CONTRAST_SESSION_METADATA`|
|`routeCoverageThreshold`|`ROUTE_COVERAGE_THRESHOLD`|`CONTRAST_ROUTE_COVERAGE_THRESHOLD`|

The `CONTRAST_` prefix is optional.

Expand Down
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ This action verifies an application that's onboarded to Contrast by determining
|`failThreshold`|Number of vulnerabilities that are needed to fail the build (not used if there is a defined job outcome policy)|No, defaults to `0`|
|`jobStartTime`|Filter vulnerabilities first found after this timestamp (formatted **in milliseconds** since the epoch)|No, defaults to `0`|
|`severities`|Comma separated list of vulnerability severities to consider (not used if there is a defined job outcome policy). Values allowed are `CRITICAL`, `HIGH`, `MEDIUM`, `LOW` and `NOTE`|No, defaults to `CRITICAL,HIGH`|
|`sessionMetadata`|Session metadata to filter vulnerabilities and route coverage by, in the same `key=value` format as the agent's `session_metadata` configuration, e.g. `branchName=main,commitHash=abc123`. See [Session Metadata](#session-metadata)|No|
|`routeCoverageThreshold`|Minimum route coverage percentage (`0`-`100`) required to pass. Filtered by `sessionMetadata` if provided|No, route coverage is not checked if unset|


## Example usage
Expand Down Expand Up @@ -65,6 +67,32 @@ You may also pass a `buildNumber` input which will filter for vulnerabilities fo

If both `jobStartTime` and `buildNumber` are provided, the step will consider only vulnerabilities found since the specified start time, **and** with the provided `buildNumber`.

### Session Metadata

Contrast agents can tag the vulnerabilities and routes they observe with [session metadata](https://docs.contrastsecurity.com/en/session-metadata.html), configured via `CONTRAST__APPLICATION__SESSION_METADATA` (or `application.session_metadata` in YAML), for example `branchName=main,commitHash=abc123`.

Pass the same key/value pairs to the `sessionMetadata` input to verify only results from that session. Entries may be separated by commas or newlines, and keys may be the agent key (`branchName`) or the TeamServer display label (`Branch Name`). When `sessionMetadata` is provided:

- Job outcome policies are **not** used. Instead, open vulnerabilities matching **all** of the provided metadata (plus `severities`, and `buildNumber`/`jobStartTime` if set) are counted, and the step fails if the count is above `failThreshold`.
- If `routeCoverageThreshold` is set, route coverage (exercised routes / discovered routes) is calculated for the matching session, and the step fails if it is below the threshold.

`routeCoverageThreshold` may also be used without `sessionMetadata`, in which case route coverage for the whole application is checked. If multiple checks fail, all failures are reported.

If any `sessionMetadata` key or value has not been reported to TeamServer for the application, a warning is logged and both checks fall back to the whole application: all open vulnerabilities (still filtered by `severities`, `buildNumber` and `jobStartTime`) are compared against `failThreshold`, and route coverage is calculated for the whole application.

```yaml
- name: Contrast Verify
uses: Contrast-Security-OSS/integration-verify-github-action@main
with:
apiKey: ${{ secrets.CONTRAST_API_KEY }}
orgId: <organization id>
authHeader: ${{ secrets.CONTRAST_AUTH_HEADER }}
appName: App_Name_Here
sessionMetadata: "branchName=${{ github.ref_name }},commitHash=${{ github.sha }}"
failThreshold: 0
routeCoverageThreshold: 80
```

## Use outside of GitHub Actions

This integration is available as a Docker image which allows it to be used in other environments outside of GitHub Actions, for example, in GitLab pipelines. For more details, see [Container Documentation](CONTAINER_DOCS.md).
Expand Down
4 changes: 4 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ inputs:
severities:
description: 'Comma separated list of vulnerability severities to consider (not used if there is a defined job outcome policy)'
default: 'CRITICAL,HIGH'
sessionMetadata:
description: 'Session metadata to filter vulnerabilities and route coverage by, in the same format as the agent session_metadata configuration, e.g. "branchName=main,commitHash=abc123". When set, job outcome policies are not used and matching open vulnerabilities are compared against failThreshold.'
routeCoverageThreshold:
description: 'Minimum route coverage percentage (0-100) required to pass. Route coverage is filtered by sessionMetadata if provided. Not checked if unset.'

runs:
using: 'docker'
Expand Down
27 changes: 27 additions & 0 deletions contrastverify/helpers/input_output_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,33 @@ def get_included_severities(severities_csv: str) -> list[str]:
if severity in input_severities
]

@staticmethod
def parse_session_metadata(session_metadata: str | None) -> dict[str, str]:
"""
Parse session metadata in the same format used by the Contrast agent's `application.session_metadata`
configuration, e.g. `branchName=main,commitHash=abc123,buildNumber=42`.
Entries may be separated by commas or newlines; keys and values are trimmed.
:raises ValueError: if an entry is not a key=value pair, or a key is repeated
"""
metadata = {}
if not session_metadata:
return metadata

for entry in session_metadata.replace("\n", ",").split(","):
entry = entry.strip()
if entry == "":
continue
key, separator, value = entry.partition("=")
key = key.strip()
value = value.strip()
if not separator or key == "" or value == "":
raise ValueError(f'"{entry}" is not in the format key=value')
if key in metadata:
raise ValueError(f'key "{key}" is specified more than once')
metadata[key] = value

return metadata

@staticmethod
def load_certs(output_helper: OutputHelper) -> Path | None:
certs_to_add = InputHelper.get_input("CA_FILE")
Expand Down
Loading
Loading