-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update known flaws files 4.5.2 #4379
Update known flaws files 4.5.2 #4379
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you change the base branch to 4.5.2 in this PR @nico-stefani?
Also, if these known flaws are merged in QA 4.5.2, they should reflect the Wazuh code in v4.5.2 too. However, it seems to find some flaws currently:
$ pytest tests/scans/code_analysis/test_python_flaws.py --disable-warnings --exclude_directories tests,test --reference 4.5.2
============================================================================================ test session starts =============================================================================================
platform linux -- Python 3.10.12, pytest-7.1.2, pluggy-1.0.0
rootdir: /home/selu/Git/wazuh-qa/tests, configfile: pytest.ini
plugins: html-3.1.1, testinfra-5.0.0, metadata-2.0.4
collected 1 item
tests/scans/code_analysis/test_python_flaws.py F [100%]
================================================================================================== FAILURES ==================================================================================================
_________________________________________________________________________________________ test_check_security_flaws __________________________________________________________________________________________
clone_wazuh_repository = '/tmp/tmp22p01_mf'
get_test_parameters = {'directories_to_check': ['framework/', 'api/', 'wodles/'], 'directories_to_exclude': 'tests,test', 'min_confidence_level': 'MEDIUM', 'min_severity_level': 'LOW', ...}
def test_check_security_flaws(clone_wazuh_repository, get_test_parameters):
"""Test whether the directory to check has python files with possible vulnerabilities or not.
The test passes if there are no new vulnerabilities. The test fails in other case and generates a report.
In case there is at least one vulnerability, a json file will be generated with the report. If we consider this
result or results are false positives, we will move the json object containing each specific result to the
`known_flaws/known_flaws_{framework|api|wodles}.json` file.
Args:
clone_wazuh_repository (fixture): Pytest fixture returning the path of the temporary directory path the
repository cloned. This directory is removed at the end of the pytest session.
get_test_parameters (fixture): Pytest fixture returning the a dictionary with all the test parameters.
These parameters are the directories to check, directories to exclude, the minimum confidence level, the
minimum severity level and the repository name.
"""
# Wazuh is cloned from GitHub using the clone_wazuh_repository fixture
assert clone_wazuh_repository, "Error while cloning the Wazuh repository from GitHub, " \
"please check the Wazuh branch set in the parameter."
# Change to the cloned Wazuh repository directory
os.chdir(clone_wazuh_repository)
directories_to_check = get_test_parameters['directories_to_check']
bandit_output_list = \
run_bandit_multiple_directories(directories_to_check,
get_test_parameters['directories_to_exclude'],
get_test_parameters['min_severity_level'],
get_test_parameters['min_confidence_level'])
flaws_already_found = {}
for bandit_output, directory in zip(bandit_output_list, directories_to_check):
assert not bandit_output['errors'], \
f"\nBandit returned errors when trying to get possible vulnerabilities in the directory " \
f"{directory}:\n{bandit_output['errors']}"
bandit_result = bandit_output['results']
known_flaws = update_known_flaws_in_file(known_flaws_directory=KNOWN_FLAWS_DIRECTORY,
directory=directory,
is_default_check_dir=
directory.replace('/', '') in
DEFAULT_DIRECTORIES_TO_CHECK.replace('/', '').split(','),
bandit_results=bandit_result)
flaws_already_found = get_new_flaws(bandit_results=bandit_result,
known_flaws=known_flaws,
directory=directory,
flaws_already_found=flaws_already_found,
new_flaws_output_dir=TEST_PYTHON_CODE_PATH)
> assert not any(
flaws_already_found.get(directory, None) for directory in directories_to_check), \
f"\nThe following possible vulnerabilities were found: {json.dumps(flaws_already_found, indent=4, sort_keys=True)}"
E AssertionError:
E The following possible vulnerabilities were found: {
E "api/": "Vulnerabilities found in files: api/api/configuration.py, api/scripts/wazuh-apid.py, check them in /home/selu/Git/wazuh-qa/tests/scans/code_analysis/new_flaws_api.json",
E "wodles/": "Vulnerabilities found in files: wodles/azure/azure-logs.py, check them in /home/selu/Git/wazuh-qa/tests/scans/code_analysis/new_flaws_wodles.json"
E }
E assert not True
E + where True = any(<generator object test_check_security_flaws.<locals>.<genexpr> at 0x7f0528a01bd0>)
/home/selu/Git/wazuh-qa/tests/scans/code_analysis/test_python_flaws.py:64: AssertionError
========================================================================================== short test summary info ===========================================================================================
FAILED tests/scans/code_analysis/test_python_flaws.py::test_check_security_flaws - AssertionError:
======================================================================================= 1 failed, 2 warnings in 12.06s =======================================================================================
{
"new_flaws": [
{
"code": " # Build the request\n md5_hash = md5(args.la_query.encode()).hexdigest()\n url = f\"{url_analytics}/v1/workspaces/{args.workspace}/query\"\n",
"filename": "wodles/azure/azure-logs.py",
"issue_confidence": "HIGH",
"issue_severity": "MEDIUM",
"issue_text": "Use of insecure MD2, MD4, MD5, or SHA1 hash function.",
"line_number": 305,
"line_range": [
305
],
"more_info": "https://bandit.readthedocs.io/en/latest/blacklists/blacklist_calls.html#b303-md5",
"test_id": "B303",
"test_name": "blacklist"
}
]
}
6d8ea87
to
fcc7215
Compare
Now is Ok with
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, I'm adding the execution outputs to speed up the process since this should be merged today.
Run 1
$ pytest tests/scans/code_analysis/test_python_flaws.py --disable-warnings --exclude_directories tests,test --reference 4.5.2
============================================================================================ test session starts =============================================================================================
platform linux -- Python 3.10.12, pytest-7.1.2, pluggy-1.0.0
rootdir: /home/selu/Git/wazuh-qa/tests, configfile: pytest.ini
plugins: html-3.1.1, testinfra-5.0.0, metadata-2.0.4
collected 1 item
tests/scans/code_analysis/test_python_flaws.py . [100%]
======================================================================================= 1 passed, 2 warnings in 9.60s ========================================================================================
Run 2
$ pytest tests/scans/code_analysis/test_python_flaws.py --disable-warnings --exclude_directories tests,test --reference 4.5.2
============================================================================================ test session starts =============================================================================================
platform linux -- Python 3.10.12, pytest-7.1.2, pluggy-1.0.0
rootdir: /home/selu/Git/wazuh-qa/tests, configfile: pytest.ini
plugins: html-3.1.1, testinfra-5.0.0, metadata-2.0.4
collected 1 item
tests/scans/code_analysis/test_python_flaws.py . [100%]
======================================================================================= 1 passed, 2 warnings in 9.14s ========================================================================================
Run 3
$ pytest tests/scans/code_analysis/test_python_flaws.py --disable-warnings --exclude_directories tests,test --reference 4.5.2
============================================================================================ test session starts =============================================================================================
platform linux -- Python 3.10.12, pytest-7.1.2, pluggy-1.0.0
rootdir: /home/selu/Git/wazuh-qa/tests, configfile: pytest.ini
plugins: html-3.1.1, testinfra-5.0.0, metadata-2.0.4
collected 1 item
tests/scans/code_analysis/test_python_flaws.py . [100%]
======================================================================================= 1 passed, 2 warnings in 9.47s ========================================================================================
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Description
This PR updates the known flaws files with the recent scan results.
Updated
Testing performed