diff options
author | Brian <bayuan@purdue.edu> | 2023-10-20 01:14:02 -0400 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2023-12-17 13:06:39 +1000 |
commit | 7adfe8ddc1d8045c14f4ca37d9479f7506b11fb9 (patch) | |
tree | ab31d608dc62e72e7422bfa44390d9b4b78f36c1 /.github/workflows/fail_on_error.py | |
parent | 58a7d6c6ebf356f9518a44d8816a700a030e9e4f (diff) | |
download | jimtcl-7adfe8ddc1d8045c14f4ca37d9479f7506b11fb9.zip jimtcl-7adfe8ddc1d8045c14f4ca37d9479f7506b11fb9.tar.gz jimtcl-7adfe8ddc1d8045c14f4ca37d9479f7506b11fb9.tar.bz2 |
Add CodeQL Workflow for Code Security Analysis
Add CodeQL Workflow for Code Security Analysis
This pull request introduces a CodeQL workflow to enhance the security analysis of our repository. CodeQL is a powerful static analysis tool that helps identify and mitigate security vulnerabilities in our codebase. By integrating this workflow into our GitHub Actions, we can proactively identify and address potential issues before they become security threats.
We added a new CodeQL workflow file (.github/workflows/codeql.yml) that
- Runs on every pull request (functionality to run on every push to main branches is included as a comment for convenience).
- Runs daily.
- Excludes queries with a high false positive rate or low-severity findings.
- Does not display results for git submodules, focusing only on our own codebase.
Testing:
To validate the functionality of this workflow, we have run several test scans on the codebase and reviewed the results. The workflow successfully compiles the project, identifies issues, and provides actionable insights while reducing noise by excluding certain queries and third-party code.
Deployment:
Once this pull request is merged, the CodeQL workflow will be active and automatically run on every push and pull request to the main branch. To view the results of these code scans, please follow these steps:
1. Under the repository name, click on the Security tab.
2. In the left sidebar, click Code scanning alerts.
Additional Information:
- You can further customize the workflow to adapt to your specific needs by modifying the workflow file.
- For more information on CodeQL and how to interpret its results, refer to the GitHub documentation and the CodeQL documentation (https://codeql.github.com/ and https://codeql.github.com/docs/).
Signed-off-by: Brian <bayuan@purdue.edu>
Diffstat (limited to '.github/workflows/fail_on_error.py')
-rwxr-xr-x | .github/workflows/fail_on_error.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/.github/workflows/fail_on_error.py b/.github/workflows/fail_on_error.py new file mode 100755 index 0000000..2979174 --- /dev/null +++ b/.github/workflows/fail_on_error.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 + +import json +import sys + +# Return whether SARIF file contains error-level results +def codeql_sarif_contain_error(filename): + with open(filename, 'r') as f: + s = json.load(f) + + for run in s.get('runs', []): + rules_metadata = run['tool']['driver']['rules'] + if not rules_metadata: + rules_metadata = run['tool']['extensions'][0]['rules'] + + for res in run.get('results', []): + if 'ruleIndex' in res: + rule_index = res['ruleIndex'] + elif 'rule' in res and 'index' in res['rule']: + rule_index = res['rule']['index'] + else: + continue + try: + rule_level = rules_metadata[rule_index]['defaultConfiguration']['level'] + except IndexError as e: + print(e, rule_index, len(rules_metadata)) + else: + if rule_level == 'error': + return True + return False + +if __name__ == "__main__": + if codeql_sarif_contain_error(sys.argv[1]): + sys.exit(1) |