CYBEX-P / tahoe

A Cyberthreat Language (CTL) to replace STIX
Other
0 stars 1 forks source link

Initializing a child of Object with _backend=b1 will result in wrong backend utilization #33

Open nachobacanful opened 4 years ago

nachobacanful commented 4 years ago

by the time we set the correct backend is set the parent backend has already been used.

Affected

children of Objects:

When creating a User instance we can do the following:

b = MongoBackend(...)
u1 =User(...., _backend=b)

the issue is that all the attributes/events/etc will use the wrong backend. since self._backend is defined by the parent class it exists and we can use to create tahoe objects and attributes. for example line 17-22 in the image above. it sets these attributes\' backend to be self.backend. the problem is that this backend is not the one specified in User(_backend=b) because this is not set until later in the User.__init__() by the super().__init__()(line24). so by the time we set the correct backend is set the parent backend has already been used.

nachobacanful commented 4 years ago

Possible fix

class Child(Object):  
    def __init__(self, stuff ..., **kwargs):
        if "_backend" in kwargs:
            self._backend = kwargs.pop("_backend")
        plugin = Attribute('plugin', plugin, _backend=self._backend)
        ....
        super().__init__('cybexp_input_config', data, **kwargs)

we dont want to add _backend to the child __init__ signature because we will force the programmer to specify a _backend or we will be forced to add a default value to the child signature, by using the kwargs we allow the child class to inherit the default value from the parent.

nachobacanful commented 4 years ago

The above solution works