-
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
Add test to check new possible flaws in wodles, framework and API code #1659
Conversation
PR UPDATE
eg: Because of this change, the
Format of the new flaws generated by the test:
Example:
Test result:
Regards, |
PR updateI have included parameters to add the possibility to use this test with more repositories, directories, minimum confidence and severity level and different excluded directories. These are the parameters:
|
PR updateThe test works with all the default values of the parameters. I have included a fix as the Parameters we have:
The test will fail if the repository or branch are not valid.
Example of the test with the wazuh-qa repository and a directory of this repo. example 1
Example of the test with the wazuh-qa repository and a directory of this repo with no security flaws (the test passes). example 2
Example of the test with the wazuh repo and the default values but with a different branch (vulnerability in wodle and known_flaws updated (new lines)). example 3
The test will pass with the default parameters. It will also pass with a different branch if there are no new possible flaws. When changing the rest of parameters, the test will fail if new flaws are detected. |
320aed5
to
a2f8d91
Compare
tests/security/test_python_code/known_flaws/known_flaws_framework.json
Outdated
Show resolved
Hide resolved
tests/security/test_python_code/known_flaws/known_flaws_framework.json
Outdated
Show resolved
Hide resolved
tests/security/test_python_code/known_flaws/known_flaws_framework.json
Outdated
Show resolved
Hide resolved
tests/security/test_python_code/known_flaws/known_flaws_framework.json
Outdated
Show resolved
Hide resolved
tests/security/test_python_code/known_flaws/known_flaws_framework.json
Outdated
Show resolved
Hide resolved
This test seems to work correctly, running without any fail if python3.9.6 is used and it fails for python3.6
In order to use this test in the Jenkins environment, it should be necessary to install a proper python version, otherwise, the test will fail. Also, it could affect the development tool qactl. We should consider the python version in environment provision. |
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.
GJ, but some changes are required
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
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
Hi team,
This PR closes #1615.
In this pull request, I have added a new unit test to check the possible code flaws in our Python.
The unittest uses
Bandit
to look for new possible vulnerabilities in the wodles, framework and api code.In order to find new vulnerabilities, the test compares the Bandit output with vulnerabilities we already know.
The test is located at
wazuh-qa/tests/security/test_python_code
.Inside this folder, we can find the test itself, called
test_python_flaws.py
, a raw file calledwazuh_branch
and a folder calledknown_flaws
.known_flaws
: contains three files. Each line of each file contains a false positive vulnerability detected by Bandit in JSON format. It can also be a known vulnerability that needs to be fixed. These files must be edited after analyzing new vulnerabilities with the test.wazuh_branch
: raw file containing the branch name where we are going to look for vulnerabilities.test_python_flaws.py
: the test itself. This test is going to be passed using the same environment used in the Wazuh framework and API unittests. If the test fails, new txt files will be created inwazuh-qa/tests/security/test_python_code
showing information about the new vulnerabilities found.So, the workaround for this test will be: passing the test, if it passes, everything is correct. If the test fails, new code vulnerabilities will be found in
wazuh-qa/tests/security/test_python_code/new_flaws_{module}.txt
. After analyzing this vulnerabilities there are 2 options:known_flaws.txt
file if we consider it is a false positive. Note that the JSON showing the new flaw is prettified and has line number, we should replace the line number in thecode
key to*
and unprettify the JSON.Test output example:
test_output
And the vulnerability detected is:
After analyzing the possible flaw, we see it is a false positive, we move it to
known_flaws/known_flaws_api.txt
.known_flaws/known_flaws_api.txt
If we pass the test again, it will pass.
Regards,
Manuel.
Tests
pycodestyle --max-line-length=120 --show-source --show-pep8 file.py
.provision_documentation.sh
generate the docs without errors.