-
Notifications
You must be signed in to change notification settings - Fork 20
Description
In the frontingEngine.py
file in the frontingEngine
library, we use the detectCDN
library to instantiate a list of objects which are of type domain
.
Issue
When instantiating a series of Domain
objects with letting the Domain
class set default values for all local variables for the object as defined in detectCDN.cdn_lookup.py
, it is observed that all Domain
objects in the pot list for DomainPot
all share the same address for their local variables Domain.cdns
, Domain.whois_data
, etc except for Domain.url
which is the only parameter passed when instantiating the object.
Replication
The original state of the of the DomainPot class code is the following:
class DomainPot:
def __init__(self, domains: List[str]):
self.domains = []
self.domain_to_cdn = {}
# Convert to list of type domain
for dom in domains:
domin = detectCDN.domain(dom)
self.domains.append(domin)
With the class in frontingEngine.py
changed back to the above, from the src/ directory, open up a python interpreter or run a script with the following commands:
import frontingEngine
domains = ["login.gov","censys.io","asu.edu","google.com"]
pot = frontingEngine.DomainPot(domains)
# Print addresses
for domain in pot.domains:
print("[%s]\tCDN list located at\t%s" % (domain.url,hex(id(domain.cdns))))
If the issue still exists, all addresses for the CDNs list will be the same
Current work-around
Instead of depending on the detectCDN class to define defaults, I am passing default list()
objects as parameters to the Domain
object. The code in frontingEngine.py
looks like the following:
class DomainPot:
def __init__(self, domains: List[str]):
self.domains = []
self.domain_to_cdn = {}
# Convert to list of type domain
for dom in domains:
domin = detectCDN.domain(
dom, list(), list(), list(), list(), list(), list(), list(), list()
)
self.domains.append(domin)
This of course is not ideal however, it stops the sharing of addresses between objects.
Current thoughts
I feel like this could be an issue with the namespace for which the class is being called. The library detectCDN
may have improper namespace definitions which could cause any variables such as default variables which the library defines, may cause subsequent objects which are instantiated from the same class which also have default variables defined by the library, to share the same address for their local variables.
The reason passing them from the calling python script/library, such as in how frontingEngine.py
calls upon detectCDN.py
, works is because the passed parameter is defined in the namespace of the calling library and the address is then passed to the called library by address (pass by address, not pass by value) therefore it is always different than other objects/parameters/values which are defined in the calling library because it understands how they should exist. Letting the library it calls handle its own internal variables and in its namespace may cause the sharing of addresses between objects.