STIX 2.x Validator

3.2.0 · active · verified Fri Apr 17

The stix2-validator library provides APIs and scripts for validating STIX 2.x documents against the official STIX specifications. It is currently at version 3.2.0 and receives regular updates, typically with minor releases addressing fixes and dependency updates, and less frequent major releases for specification updates and significant feature enhancements.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the `Validator` and use it to validate a STIX object represented as a Python dictionary. It shows both standard and verbose validation output. To validate a STIX document from a file, load its JSON content into a dictionary first.

from stix2validator import Validator
import json

# Example STIX 2.1 Indicator object for validation
stix_object = {
    "type": "indicator",
    "spec_version": "2.1",
    "id": "indicator--a79f0462-8789-4b67-8c0c-52643a2d1d07",
    "created": "2024-01-01T12:00:00.000Z",
    "modified": "2024-01-01T12:00:00.000Z",
    "pattern": "[file:hashes.MD5 = 'd41d8cd98f00b204e9800998ecf8427e']",
    "pattern_type": "stix",
    "valid_from": "2024-01-01T12:00:00.000Z"
}

# Initialize the validator
validator = Validator()

# Validate a STIX dictionary (e.g., loaded from JSON)
results = validator.validate(stix_object)

if not results:
    print("STIX object is valid.")
else:
    print("STIX object has validation issues:")
    for result in results:
        print(f"  - {result}")

# For more detailed output, instantiate with verbose=True
verbose_validator = Validator(verbose=True)
verbose_results = verbose_validator.validate(stix_object)
if verbose_results:
    print("\nVerbose validation results:")
    for result in verbose_results:
        print(f"  - {result}")

view raw JSON →