Skip to content

Commit 2ae4aee

Browse files
authored
fix(api): Code scanning alerts (#254)
1 parent 46238b8 commit 2ae4aee

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

cmdb-api/api/lib/cmdb/attribute.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ def _get_choice_values_from_other(choice_other):
8181
elif choice_other.get('script'):
8282
try:
8383
x = compile(choice_other['script'], '', "exec")
84-
exec(x)
85-
res = locals()['ChoiceValue']().values() or []
84+
local_ns = {}
85+
exec(x, {}, local_ns)
86+
res = local_ns['ChoiceValue']().values() or []
8687
return [[i, {}] for i in res]
8788
except Exception as e:
8889
current_app.logger.error("get choice values from script: {}".format(e))

cmdb-api/api/lib/cmdb/auto_discovery/auto_discovery.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ def parse_plugin_script(script):
3636
attributes = []
3737
try:
3838
x = compile(script, '', "exec")
39-
exec(x)
40-
unique_key = locals()['AutoDiscovery']().unique_key
41-
attrs = locals()['AutoDiscovery']().attributes() or []
39+
local_ns = {}
40+
exec(x, {}, local_ns)
41+
unique_key = local_ns['AutoDiscovery']().unique_key
42+
attrs = local_ns['AutoDiscovery']().attributes() or []
4243
except Exception as e:
4344
return abort(400, str(e))
4445

cmdb-api/api/lib/cmdb/search/ci/db/search.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from flask import current_app
1010
from flask_login import current_user
1111
from jinja2 import Template
12+
from sqlalchemy import text
1213

1314
from api.extensions import db
1415
from api.lib.cmdb.cache import AttributeCache
@@ -312,7 +313,7 @@ def _execute_sql(self, query_sql):
312313
start = time.time()
313314
execute = db.session.execute
314315
# current_app.logger.debug(v_query_sql)
315-
res = execute(v_query_sql).fetchall()
316+
res = execute(text(v_query_sql)).fetchall()
316317
end_time = time.time()
317318
current_app.logger.debug("query ci ids time is: {0}".format(end_time - start))
318319

@@ -525,7 +526,7 @@ def _facet_build(self):
525526
if k:
526527
table_name = TableMap(attr=attr).table_name
527528
query_sql = FACET_QUERY.format(table_name, self.query_sql, attr.id)
528-
result = db.session.execute(query_sql).fetchall()
529+
result = db.session.execute(text(query_sql)).fetchall()
529530
facet[k] = result
530531

531532
facet_result = dict()

0 commit comments

Comments
 (0)