swimlane / pyattck

A Python package to interact with the Mitre ATT&CK Framework
MIT License
468 stars 87 forks source link

is_url almost always returns true so can't load JSON from disk #121

Closed thebleucheese closed 2 years ago

thebleucheese commented 2 years ago

Hey, I ran into a quirk trying to use JSON files from disk. Tracked it down to the is_url() function

utils.py line 26

Environment is ubuntu / poetry / python 3.8.10

Quick sample of testing just this function:

from urllib.parse import urlparse

def is_url(value: str) -> bool:
    try:
        urlparse(value).scheme in ["http", "https"]
        return True
    except Exception as e:
        pass
    return False

if __name__ == '__main__':
    print(is_url("TEST NOT A URL"))
True

And since the configuration.py get_data() call uses the URL check to determine where to load config data from, it's always calling the request getter to load from URL.

thebleucheese commented 2 years ago

And one more note - I get a stacktrace with use_config=True

Traceback (most recent call last):
  File "/path/to/project/main.py", line 28, in <module>
    print_attack()
  File "/path/to/project/main.py", line 13, in print_attack
    attack = Attck(nested_techniques=True,
  File "/poetry-dir-fLaP9Psg-py3.8/lib/python3.8/site-packages/pyattck/attck.py", line 222, in __init__
    Base.config = Options(
  File "<attrs generated init pyattck.configuration.Options>", line 15, in __init__
  File "/poetry-dir-fLaP9Psg-py3.8/lib/python3.8/site-packages/pyattck/configuration.py", line 154, in __attrs_post_init__
    self.config = self._read_from_disk(self.config_file_path)
  File "/poetry-dir-fLaP9Psg-py3.8/lib/python3.8/site-packages/attr/_make.py", line 642, in _frozen_setattrs
    raise FrozenInstanceError()
attr.exceptions.FrozenInstanceError

Looks like use_config is trying to modify something set as immutable by attrs

MSAdministrator commented 2 years ago

@thebleucheese Can you tell me which version you are seeing this on?

MSAdministrator commented 2 years ago

@thebleucheese Actually, just found it and have a fix. Looking at the second thing you mentioned now.

MSAdministrator commented 2 years ago

@thebleucheese Actually just figured that one out as well. This will be released in 7.0.0 #123