oasis-open / cti-stix-slider

OASIS TC Open Repository: The repository cti-stix-slider supports development of a Python application to convert STIX 2.0 content to STIX 1.x content
https://cti-stix-slider.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
21 stars 15 forks source link

AttributeError: 'NoneType' object has no attribute 'append' #51

Closed stmtstk closed 4 years ago

stmtstk commented 4 years ago

Hi, All,

When I tried to convert from a six 2.1 content with some external_reference properties, an AttributeError has occurred.

At a create_references function in convert_stix.py, this library tried to info_source.add_reference(rt).

In add_reference function, it tried to append an argument value into a self.references property, however self.references is None.

I will recommend to insert a None check in add_reference, if self.references is None then self.references = [] and append a value.

stmtstk commented 4 years ago

Sorry...

A self.references.append(value) is in python-stix library. I should publish this issue in python-stix.

rpiazza commented 4 years ago

Hi @stmtstk,

We are planning to release a new version of the slider soon. In it, there is much improved code for handling external references. However, I'd like to make sure that the error you are hitting is handled by the new code. Can you send me the example STIX 2.x content that caused the error?

The python-stix code should probably handle this too. I will look into that - you don't need to.

stmtstk commented 4 years ago

I used master version library (not version 2.0.0).

In convert_stix.py, if an object contains a "created_by_ref" property, convert_bundle function calls process_created_by_ref (line: 1382). process_created_by_ref calls create_information_source function (line: 1171) due to generating an InformationSource object. However, in create_information_source, there are no references argument.

    if used_before:
        return InformationSource(identity=Identity(idref=identity_obj.id_))
    else:
        identity2x_tuple[1] = True
        return InformationSource(identity=identity_obj)

If InformationSource is called without a references argument, this references variable is None.

if STIX 2.x object contains a "external_references" property, "create_references" is called (line: 1384). In "create_references", if an external_references property contains an url and an object_type is not Indicator, call add_references (line: 1137) and an AttributeError occurs (because references is None).

I recommend to modify to generate an InformationSource object below.

    if used_before:
        return InformationSource(identity=Identity(idref=identity_obj.id_), references=References())
    else:
        identity2x_tuple[1] = True
        return InformationSource(identity=identity_obj, references=References())
rpiazza commented 4 years ago

Thanks @stmtstk

This fix looks great. I will be testing it and assuming no other problems, it will be included in the next release.

rpiazza commented 4 years ago

@emmanvg,

Can you look into the python-stix aspect of this issue?

I tested the fix suggested by @stmtsk, but if there are no references then you get a

            <stixCommon:References/>

in the STIX 1.x content, which I would like to avoid. Perhaps fixing the python-stix code is what is really needed.

rpiazza commented 4 years ago

Closing this. It should be fixed in python-stix - see https://github.com/STIXProject/python-stix/issues/366