oasis-open / cti-taxii-client

OASIS TC Open Repository: TAXII 2 Client Library Written in Python
https://taxii2client.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
108 stars 52 forks source link

Don't know how to handle type 'Bundle' #106

Closed Dan-Vizor closed 2 years ago

Dan-Vizor commented 2 years ago

I've been trying to upload the following STIX data to a local TAXII 2.1 server:

{
    "type": "bundle",
    "id": "bundle--7bc35967-3410-4a31-836f-900aa3f37919",
    "objects": [
        {
            "type": "indicator",
            "spec_version": "2.1",
            "id": "indicator--a831ca15-2b0a-4a61-a1c8-967a5f7a2d4a",
            "created": "2020-09-15T15:50:30.000Z",
            "modified": "2022-06-21T12:28:09.045432Z",
            "name": "Test Event",
            "pattern": "[domain-name:value='example.com']",
            "pattern_type": "stix",
            "pattern_version": "2.1",
            "valid_from": "2020-09-15T15:50:23Z"
        }
    ]
}

when uploading using collection.add_objects() it gives the error

TypeError: Don't know how to handle type 'Bundle'

This bundle was generated using the stix2 python module. I don't believe this is a formatting error as I have put it through the stix2-validator which said it's valid.

Does anyone know what would be causing this error?

chisholm commented 2 years ago

This library expects the objects to add to the collection to be in a TAXII envelope structure. This is because the "add objects" endpoint is defined as having a TAXII envelope as the payload of the request. So you need to create an envelope structure to pass your objects in. A simple structure like:

{
    "objects": [  ]
}

ought to work, where the objects property contains the contents of your bundle. Note that this library doesn't support passing stix2 library objects; supported types include plain dicts and JSON. So you would have to convert your stix2 library objects, e.g. by serializing them to JSON.