Skip to content

Commit 5c82de9

Browse files
author
Brian
committed
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 push and pull request to the main branch. - Excludes queries with a high false positive rate or low-severity findings. - Does not display results for third-party code, 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. Signed-off-by: Brian <[email protected]>
1 parent 59c8bba commit 5c82de9

File tree

2 files changed

+126
-0
lines changed

2 files changed

+126
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
3+
./build.sh

.github/workflows/codeql.yml

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
#
7+
# ******** NOTE ********
8+
# We have attempted to detect the languages in your repository. Please check
9+
# the `language` matrix defined below to confirm you have the correct set of
10+
# supported CodeQL languages.
11+
#
12+
name: "CodeQL"
13+
14+
on:
15+
push:
16+
branches: [ "main", "master" ]
17+
pull_request:
18+
# The branches below must be a subset of the branches above
19+
branches: [ "main", "master" ]
20+
schedule:
21+
- cron: '28 21 * * 0'
22+
23+
jobs:
24+
analyze:
25+
name: Analyze
26+
# Runner size impacts CodeQL analysis time. To learn more, please see:
27+
# - https://gh.io/recommended-hardware-resources-for-running-codeql
28+
# - https://gh.io/supported-runners-and-hardware-resources
29+
# - https://gh.io/using-larger-runners
30+
# Consider using larger runners for possible analysis time improvements.
31+
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-20.04' }}
32+
timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }}
33+
permissions:
34+
actions: read
35+
contents: read
36+
security-events: write
37+
38+
strategy:
39+
fail-fast: false
40+
matrix:
41+
language: [ 'cpp' ]
42+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby', 'swift' ]
43+
# Use only 'java' to analyze code written in Java, Kotlin or both
44+
# Use only 'javascript' to analyze code written in JavaScript, TypeScript or both
45+
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
46+
47+
steps:
48+
- name: Checkout repository
49+
uses: actions/checkout@v3
50+
with:
51+
submodules: recursive
52+
53+
# Initializes the CodeQL tools for scanning.
54+
- name: Initialize CodeQL
55+
uses: github/codeql-action/init@v2
56+
with:
57+
languages: ${{ matrix.language }}
58+
# If you wish to specify custom queries, you can do so here or in a config file.
59+
# By default, queries listed here will override any specified in a config file.
60+
# Prefix the list here with "+" to use these queries and those in the config file.
61+
62+
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
63+
# queries: security-extended,security-and-quality
64+
queries: security-and-quality
65+
66+
67+
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
68+
# If this step fails, then you should remove it and run the build manually (see below)
69+
#- name: Autobuild
70+
# uses: github/codeql-action/autobuild@v2
71+
72+
# ℹ️ Command-line programs to run using the OS shell.
73+
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
74+
75+
# If the Autobuild fails above, remove it and uncomment the following three lines.
76+
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
77+
78+
- run: |
79+
./.github/workflows/codeql-buildscript.sh
80+
81+
- name: Perform CodeQL Analysis
82+
uses: github/codeql-action/analyze@v2
83+
with:
84+
category: "/language:${{matrix.language}}"
85+
upload: false
86+
id: step1
87+
88+
# Filter out rules with low severity or high false positve rate
89+
# Also filter out warnings in third-party code
90+
- name: Filter out unwanted errors and warnings
91+
uses: advanced-security/filter-sarif@v1
92+
with:
93+
patterns: |
94+
-**:cpp/path-injection
95+
-**:cpp/world-writable-file-creation
96+
-**:cpp/poorly-documented-function
97+
-**:cpp/potentially-dangerous-function
98+
-**:cpp/use-of-goto
99+
-**:cpp/integer-multiplication-cast-to-long
100+
-**:cpp/comparison-with-wider-type
101+
-**:cpp/leap-year/*
102+
-**:cpp/ambiguously-signed-bit-field
103+
-**:cpp/suspicious-pointer-scaling
104+
-**:cpp/suspicious-pointer-scaling-void
105+
-**:cpp/unsigned-comparison-zero
106+
-**/third*party/**
107+
-**/3rd*party/**
108+
-**/external/**
109+
input: ${{ steps.step1.outputs.sarif-output }}/cpp.sarif
110+
output: ${{ steps.step1.outputs.sarif-output }}/cpp.sarif
111+
112+
- name: Upload SARIF
113+
uses: github/codeql-action/upload-sarif@v2
114+
with:
115+
sarif_file: ${{ steps.step1.outputs.sarif-output }}
116+
category: "/language:${{matrix.language}}"
117+
118+
- name: Archive CodeQL results
119+
uses: actions/upload-artifact@v3
120+
with:
121+
name: codeql-results
122+
path: ${{ steps.step1.outputs.sarif-output }}
123+
retention-days: 5

0 commit comments

Comments
 (0)