Skip to content

SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.

SpiderFootDb: validate result hash IDs

Brendan Coles5be6687bff3f
diff --git a/sfdb.py b/sfdb.py
index 1bd89485..e827bd1b 100644
--- a/sfdb.py
+++ b/sfdb.py
@@ -1162,6 +1162,14 @@ class SpiderFootDb:
if not isinstance(elementIdList, list):
raise TypeError("elementIdList is %s; expected list()" % type(elementIdList))
+ hashIds = []
+ for hashId in elementIdList:
+ if not hashId:
+ continue
+ if not hashId.isalnum():
+ continue
+ hashIds.append(hashId)
+
# the output of this needs to be aligned with scanResultEvent,
# as other functions call both expecting the same output.
qry = "SELECT ROUND(c.generated) AS generated, c.data, \
@@ -1172,13 +1180,9 @@ class SpiderFootDb:
FROM tbl_scan_results c, tbl_scan_results s, tbl_event_types t \
WHERE c.scan_instance_id = ? AND c.source_event_hash = s.hash AND \
s.scan_instance_id = c.scan_instance_id AND \
- t.event = c.type AND c.hash in ("
+ t.event = c.type AND c.hash in ('%s')" % "','".join(hashIds)
qvars = [instanceId]
- for hashId in elementIdList:
- qry = qry + "'" + hashId + "',"
- qry += "'')"
-
with self.dbhLock:
try:
self.dbh.execute(qry, qvars)
@@ -1204,6 +1208,14 @@ class SpiderFootDb:
if not isinstance(elementIdList, list):
raise TypeError("elementIdList is %s; expected list()" % type(elementIdList))
+ hashIds = []
+ for hashId in elementIdList:
+ if not hashId:
+ continue
+ if not hashId.isalnum():
+ continue
+ hashIds.append(hashId)
+
# the output of this needs to be aligned with scanResultEvent,
# as other functions call both expecting the same output.
qry = "SELECT ROUND(c.generated) AS generated, c.data, \
@@ -1214,13 +1226,9 @@ class SpiderFootDb:
FROM tbl_scan_results c, tbl_scan_results s, tbl_event_types t \
WHERE c.scan_instance_id = ? AND c.source_event_hash = s.hash AND \
s.scan_instance_id = c.scan_instance_id AND \
- t.event = c.type AND s.hash in ("
+ t.event = c.type AND s.hash in ('%s')" % "','".join(hashIds)
qvars = [instanceId]
- for hashId in elementIdList:
- qry = qry + "'" + hashId + "',"
- qry += "'')"
-
with self.dbhLock:
try:
self.dbh.execute(qry, qvars)
diff --git a/sfwebui.py b/sfwebui.py
index b1eb230a..5bedd041 100644
--- a/sfwebui.py
+++ b/sfwebui.py
@@ -736,6 +736,9 @@ class SpiderFootWebUi:
# Cannot set FPs if a scan is not completed
status = dbh.scanInstanceGet(id)
+ if not status:
+ return self.error("Invalid scan ID: %s" % id)
+
if status[5] not in [ "ABORTED", "FINISHED", "ERROR-FAILED" ]:
return json.dumps(["WARNING", "Scan must be in a finished state when " + \
"setting False Positives."])
@@ -931,9 +934,8 @@ class SpiderFootWebUi:
for id in ids.split(","):
errState = False
scaninfo = dbh.scanInstanceGet(id)
-
- if scaninfo is None:
- return self.error("Invalid scan ID specified.")
+ if not scaninfo:
+ return self.error("Invalid scan ID: %s" % id)
scanname = str(scaninfo[0])
scanstatus = scaninfo[5]