Skip to content

Conversation

@seansica
Copy link
Contributor

@seansica seansica commented Jan 6, 2026

Summary

Implements validation to:

  1. ensure no duplicates exist, as determined by the objects' id key
  2. ensure that all IDs referenced in x_mitre_contents are present in the objects array

Changes

New Features

Reusable Refinement Functions

  • src/refinements/index.ts: Implemented validateNoDuplicates, which can be used in any schema to validate that no duplicates exist for any key (including composite keys)
  • src/refinements/index.ts: Implemented validateXMitreContentsReferences, which validates that all STIX IDs referenced in x_mitre_contents actually exist in the bundle's objects array

STIX Bundle Schema

  • Validate that the first object in the objects arary is of type x-mitre-collections
  • Validate that all IDs referenced in x_mitre_contents are present in the objects array
  • Validate that no duplicate objects are present in the objects array

Refactors

  • analytics.schema.ts: Replaced custom refinement with validateNoDuplicates for validating that no duplicate log source references exist
  • data-component.schema.ts: Replaced custom refinement with validateNoDuplicates for validating that no duplicate log sources in x_mitre_log_sources exist
  • detection-strategy.schema.ts: Replaced custom refinement with validateNoDuplicates for validating that no duplicate analytic refs in x_mitre_analytic_refs exist

Testing

  • test/objects/detection-strategy.test.ts: Changed one of the test conditions to throw when the schema detections duplicate analytic refs
  • test/objects/stix-bundle.test.ts: Added the following tests
    • Evaluate uniqueness constraints:
      • 'should accept bundle with unique object IDs (true positive)'
      • 'should reject bundle with duplicate object IDs (true negative)'
      • 'should report the duplicate ID in error message'
      • 'should handle multiple duplicates in a single bundle'
    • Evaluate x_mitre_contents constraints:
      • 'should accept bundle where all x_mitre_contents references exist in objects (true positive)'
      • 'should reject bundle where x_mitre_contents references a missing object (true negative)'
      • 'should report the missing STIX ID in error message'
      • 'should handle multiple missing references in x_mitre_contents'
      • 'should accept bundle with mix of valid and present references in x_mitre_contents'
  • **test/refinements/validate-no-duplicates.test.ts:
    • Added a new test suite to validate the behavior of the new validateNoDuplicates refinement factory function.
    • We should add a test suite for each of the factory functions in refinements/index.ts in a future change.

Add createUniqueObjectsOnlyRefinement to validate that all objects in a
STIX bundle have unique IDs. Includes comprehensive test coverage and
removes unused helper code from generics.ts.
@seansica seansica self-assigned this Jan 6, 2026
@seansica seansica linked an issue Jan 6, 2026 that may be closed by this pull request
@seansica
Copy link
Contributor Author

seansica commented Jan 6, 2026

@jondricek

Notably:

  1. This does not bump ATTACK_SPEC_VERSION. It remains 3.3.0. Given that this is new functionality, we should consider bumping to 3.4.0.
  2. This constraint (uniqueness of the objects in STIX bundles) is NOT specified in STIX 2.1. Adding this would be an ATT&CK-specific behavior.

… replace inline dupe checks

Add a new validateNoDuplicates refinement factory function that provides
flexible duplicate validation for:
- Object arrays with single or composite keys
- Primitive arrays (strings, numbers, etc.)
- Nested array paths with custom error messages

Replace inline duplicate checking logic in analytic, data-component, and
detection-strategy schemas with the new generic refinement, improving code
reuse and maintainability.

The new function supports template-based error messages with placeholders
for key values, primitive values, and array indices. Deprecate the existing
createUniqueObjectsOnlyRefinement in favor of the more flexible approach.
… STIX bundle integrity

Add a new validateXMitreContentsReferences refinement factory function that
validates all STIX IDs referenced in a collection's x_mitre_contents property
have corresponding objects in the bundle's objects array. This ensures
referential integrity within STIX bundles.

Replace the deprecated createUniqueObjectsOnlyRefinement with the more flexible
validateNoDuplicates refinement in stix-bundle schema for improved consistency.

Add comprehensive test coverage with 5 tests validating:
- Valid references pass validation
- Missing references are rejected with appropriate error messages
- Multiple missing references are all reported
- Multiple valid references are accepted

Fix test setup to reference the collection's own ID instead of a non-existent
object in the minimal test fixture.
@seansica seansica merged commit 2c75c7d into main Jan 16, 2026
4 checks passed
@seansica seansica deleted the 62-request-implement-uniqueness-validation-for-stix-bundle-objects branch January 16, 2026 20:49
@github-actions
Copy link

🎉 This PR is included in version 4.7.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[REQUEST] Implement uniqueness validation for STIX bundle objects

2 participants