Skip to content

Commit

Permalink
Code qa: sonarqube
Browse files Browse the repository at this point in the history
  • Loading branch information
ajinabraham committed Oct 29, 2024
1 parent a332e45 commit 65efce9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 31 deletions.
10 changes: 8 additions & 2 deletions mobsf/MobSF/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,10 @@ def get_scan_logs(checksum):
return []


class TaskTimeoutError(Exception):
pass


def run_with_timeout(func, limit, *args, **kwargs):
def run_func(result, *args, **kwargs):
result.append(func(*args, **kwargs))
Expand All @@ -964,5 +968,7 @@ def run_func(result, *args, **kwargs):
if thread.is_alive():
msg = (f'function <{func.__name__}> '
f'timed out after {limit} seconds')
raise Exception(msg)
return result[0] if result else None
raise TaskTimeoutError(msg)
if result and len(result) > 0:
return result[0]
return None
53 changes: 26 additions & 27 deletions mobsf/MobSF/views/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,39 +334,38 @@ def search(request, api=False):
query = request.POST['query']
else:
query = request.GET['query']
checksum = None
if not re.match(MD5_REGEX, query):
file_names = RecentScansDB.objects.filter(
FILE_NAME__icontains=query,
)
if file_names.exists():
checksum = file_names[0].MD5

package_names = RecentScansDB.objects.filter(
PACKAGE_NAME__icontains=query,
)
if package_names.exists():
checksum = package_names[0].MD5

app_names = RecentScansDB.objects.filter(
APP_NAME__icontains=query,
)
if app_names.exists():
checksum = app_names[0].MD5
else:
checksum = query

if not query:
msg = 'No search query provided.'
return print_n_send_error_response(request, msg, api)

checksum = query if re.match(MD5_REGEX, query) else find_checksum(query)

if checksum and re.match(MD5_REGEX, checksum):
db_obj = RecentScansDB.objects.filter(MD5=checksum)
if db_obj.exists():
e = db_obj[0]
url = f'/{e.ANALYZER}/{e.MD5}/'
db_obj = RecentScansDB.objects.filter(MD5=checksum).first()
if db_obj:
url = f'/{db_obj.ANALYZER}/{db_obj.MD5}/'
if api:
return {'checksum': e.MD5}
return HttpResponseRedirect(url)
return {'checksum': db_obj.MD5}
else:
return HttpResponseRedirect(url)

Check warning

Code scanning / CodeQL

URL redirection from remote source Medium

Untrusted URL redirection depends on a
user-provided value
.
Untrusted URL redirection depends on a
user-provided value
.
Untrusted URL redirection depends on a
user-provided value
.
Untrusted URL redirection depends on a
user-provided value
.

msg = 'You can search by MD5, app name, package name, or file name.'
return print_n_send_error_response(request, msg, api, 'Scan not found')


def find_checksum(query):
"""Get the first matching checksum from the database."""
search_fields = ['FILE_NAME', 'PACKAGE_NAME', 'APP_NAME']

for field in search_fields:
result = RecentScansDB.objects.filter(
**{f'{field}__icontains': query}).first()
if result:
return result.MD5

return None

# AJAX


Expand Down
3 changes: 1 addition & 2 deletions mobsf/StaticAnalyzer/views/ios/binary_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,9 @@ def ipa_macho_analysis(binary):
data['checksec'] = chksec
data['symbols'] = symbols
data['libraries'] = libs
return data
except Exception:
logger.exception('Running MachO Analysis')
return data
return data


def binary_analysis(checksum, src, tools_dir, app_dir, executable_name):
Expand Down

0 comments on commit 65efce9

Please sign in to comment.