cisagov / cyhy-core

Core code for Cyber Hygiene (CyHy)
Other
8 stars 10 forks source link

Bug in `check_restricted_ip()` error-handling code #92

Closed jeffkause closed 7 months ago

jeffkause commented 7 months ago

🐛 Summary

When adding new IP addresses using cyhy-ip add TEST_ENTITY <IP address>, some IPs are returning an error.

To reproduce

cyhy-ip add TEST_ENTITY <IP address>
Traceback (most recent call last):
  File "/usr/local/bin/cyhy-ip", line 506, in <module>
    main()
  File "/usr/local/bin/cyhy-ip", line 484, in main
    add(db, args["OWNER"], nets)
  File "/usr/local/bin/cyhy-ip", line 175, in add
    country = geo_loc_db.check_restricted_ip(ip)
  File "/usr/local/lib/python2.7/dist-packages/cyhy/core/geoloc.py", line 81, in check_restricted_ip
    print >> sys.stderr, "CIDR %s not found in geolocation database" % cidr
NameError: global name 'cidr' is not defined

Expected behavior

We would expect for the code to return:

$ cyhy-ip add TEST_ENTITY <IP address>
IPs added to request, and initialized.  Tally sync required to start scan of new IPs.
▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶▶| ETA:  0:00:00

Any helpful log output or screenshots

To fix this bug, change this line from:

print >> sys.stderr, "CIDR %s not found in geolocation database" % cidr

to this:

print >> sys.stderr, "IP %s not found in geolocation database" % ip