duo-labs / cloudmapper

CloudMapper helps you analyze your Amazon Web Services (AWS) environments.
BSD 3-Clause "New" or "Revised" License
5.94k stars 800 forks source link

Incorrect JSON in config.json causes exception #775

Open jtyers opened 3 years ago

jtyers commented 3 years ago

I had a config.json with the following:

"cidrs": []

Running cloudmapper.py report then causes this exception:

Traceback (most recent call last):
  File "cloudmapper.py", line 72, in <module>
    main()
  File "cloudmapper.py", line 66, in main
    commands[command].run(arguments)
  File "/opt/cloudmapper/commands/report.py", line 471, in run
    report(accounts, config, args)
  File "/opt/cloudmapper/commands/report.py", line 263, in report
    public_nodes, _ = get_public_nodes(account, config, use_cache=True)
  File "/opt/cloudmapper/shared/public.py", line 89, in get_public_nodes
    network = build_data_structure(account, config, outputfilter)
  File "/opt/cloudmapper/commands/prepare.py", line 542, in build_data_structure
    for cidr in get_external_cidrs(account, config):
  File "/opt/cloudmapper/commands/prepare.py", line 198, in get_external_cidrs
    external_cidrs.append(Cidr(cidr, get_cidr_name(cidr, config)))
  File "/opt/cloudmapper/commands/prepare.py", line 203, in get_cidr_name
    return config["cidrs"].get(cidr, {}).get("name", None)
AttributeError: 'list' object has no attribute 'get'

After a bit of debugging I realised my config is wrong, since cloudmapper.py expects a dict for cidrs. Could some validation, e.g. JSON schemas, be added to the configuration when it is loaded?

0xdabbad00 commented 3 years ago

I'd be open to PRs for this.

jtyers commented 3 years ago

I've got one on the go in my fork. Once it has a bit more testing I'll open a PR for it :+1:

w0rmr1d3r commented 3 years ago

Hello @jtyers ! Did you open the PR? Will appreciate it!

Thank you!