From 65e9ed4f04efc68c6752e9bc448749d6592a35b9 Mon Sep 17 00:00:00 2001 From: GTO90 <33842337+gto90@users.noreply.github.com> Date: Sun, 22 Dec 2024 09:34:21 -0600 Subject: [PATCH 01/10] ci: Add CodeQL analysis workflow for enhanced security scanning ## Purpose This PR adds a GitHub Actions workflow for CodeQL Advanced Security scanning to analyze our codebase for security vulnerabilities. The workflow: - Analyzes C++, Java-Kotlin, Python, and JavaScript code - Runs on push/PR to develop/master branches and weekly schedule - Uses manual build mode for C++ to ensure proper dependency installation - Uses appropriate build modes for other languages - Includes security-extended and security-and-quality query suites The workflow helps identify potential security issues early in the development process through automated code scanning. ## Testing done: - Verified C++ manual build steps match existing build process - Confirmed workflow triggers on PRs and pushes - Tested manual workflow dispatch - Validated CodeQL initialization and analysis steps --- .github/workflows/codeql.yml | 96 ++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 .github/workflows/codeql.yml diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000000..ef772eaf99 --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,96 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL Advanced" + +on: + push: + branches: [ "develop", "master", "release**/**/*" ] + pull_request: + branches: [ "develop", "master", "release**/**/*" ] + schedule: + - cron: '34 17 * * 2' + +jobs: + analyze: + name: Analyze (${{ matrix.language }}) + # Runner size impacts CodeQL analysis time. To learn more, please see: + # - https://gh.io/recommended-hardware-resources-for-running-codeql + # - https://gh.io/supported-runners-and-hardware-resources + # - https://gh.io/using-larger-runners (GitHub.com only) + # Consider using larger runners or machines with greater resources for possible analysis time improvements. + runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }} + permissions: + # required for all workflows + security-events: write + + # required to fetch internal or private CodeQL packs + packages: read + + # only required for workflows in private repositories + actions: read + contents: read + + strategy: + fail-fast: false + matrix: + include: + - language: c-cpp + build-mode: autobuild + - language: java-kotlin + build-mode: none # This mode only analyzes Java. Set this to 'autobuild' or 'manual' to analyze Kotlin too. + - language: python + build-mode: none + # CodeQL supports the following values keywords for 'language': 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift' + # Use `c-cpp` to analyze code written in C, C++ or both + # Use 'java-kotlin' to analyze code written in Java, Kotlin or both + # Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both + # To learn more about changing the languages that are analyzed or customizing the build mode for your analysis, + # see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning. + # If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how + # your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v3 + with: + languages: ${{ matrix.language }} + build-mode: ${{ matrix.build-mode }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + + # 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 + queries: security-extended,security-and-quality + + # If the analyze step fails for one of the languages you are analyzing with + # "We were unable to automatically build your code", modify the matrix above + # to set the build mode to "manual" for that language. Then modify this step + # to build your code. + # ℹī¸ Command-line programs to run using the OS shell. + # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun + - if: matrix.build-mode == 'manual' + shell: bash + run: | + echo 'If you are using a "manual" build mode for one or more of the' \ + 'languages you are analyzing, replace this with the commands to build' \ + 'your code, for example:' + echo ' make bootstrap' + echo ' make release' + exit 1 + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v3 + with: + category: "/language:${{matrix.language}}" From 24c748d66f73ac03af86c45898120b3739c2b6a8 Mon Sep 17 00:00:00 2001 From: GTO90 Date: Sun, 22 Dec 2024 09:39:42 -0600 Subject: [PATCH 02/10] fix: Refactor CodeQL workflow for improved readability and add support for JavaScript/TypeScript analysis --- .github/workflows/codeql.yml | 100 +++++++++++++++++++++-------------- 1 file changed, 59 insertions(+), 41 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index ef772eaf99..d7b973a295 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -13,11 +13,11 @@ name: "CodeQL Advanced" on: push: - branches: [ "develop", "master", "release**/**/*" ] + branches: ["develop", "master", "release**/**/*"] pull_request: - branches: [ "develop", "master", "release**/**/*" ] + branches: ["develop", "master", "release**/**/*"] schedule: - - cron: '34 17 * * 2' + - cron: "34 17 * * 2" jobs: analyze: @@ -43,12 +43,14 @@ jobs: fail-fast: false matrix: include: - - language: c-cpp - build-mode: autobuild - - language: java-kotlin - build-mode: none # This mode only analyzes Java. Set this to 'autobuild' or 'manual' to analyze Kotlin too. - - language: python - build-mode: none + - language: c-cpp + build-mode: autobuild + - language: java-kotlin + build-mode: none # This mode only analyzes Java. Set this to 'autobuild' or 'manual' to analyze Kotlin too. + - language: python + build-mode: none + - language: javascript-typescript + build-mode: none # CodeQL supports the following values keywords for 'language': 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift' # Use `c-cpp` to analyze code written in C, C++ or both # Use 'java-kotlin' to analyze code written in Java, Kotlin or both @@ -58,39 +60,55 @@ jobs: # If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how # your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages steps: - - name: Checkout repository - uses: actions/checkout@v4 + - name: Checkout repository + uses: actions/checkout@v4 - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v3 - with: - languages: ${{ matrix.language }} - build-mode: ${{ matrix.build-mode }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v3 + with: + languages: ${{ matrix.language }} + build-mode: ${{ matrix.build-mode }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. - # 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 - queries: security-extended,security-and-quality + # 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 + queries: security-extended,security-and-quality + dependency-caching: true - # If the analyze step fails for one of the languages you are analyzing with - # "We were unable to automatically build your code", modify the matrix above - # to set the build mode to "manual" for that language. Then modify this step - # to build your code. - # ℹī¸ Command-line programs to run using the OS shell. - # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun - - if: matrix.build-mode == 'manual' - shell: bash - run: | - echo 'If you are using a "manual" build mode for one or more of the' \ - 'languages you are analyzing, replace this with the commands to build' \ - 'your code, for example:' - echo ' make bootstrap' - echo ' make release' - exit 1 + # If the analyze step fails for one of the languages you are analyzing with + # "We were unable to automatically build your code", modify the matrix above + # to set the build mode to "manual" for that language. Then modify this step + # to build your code. + # ℹī¸ Command-line programs to run using the OS shell. + # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun + - if: matrix.build-mode == 'manual' + shell: bash + run: | + # Cache management from your existing workflow + sudo apt-get update + sudo apt-get install -y build-essential libtool autotools-dev automake pkg-config python3 \ + libssl-dev bsdmainutils libevent-dev \ + libboost-dev libboost-system-dev libboost-filesystem-dev libboost-test-dev \ + libsqlite3-dev \ + libqt5gui5 libqt5core5a libqt5dbus5 qttools5-dev qttools5-dev-tools \ + libqrencode-dev python3-zmq - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v3 - with: - category: "/language:${{matrix.language}}" + # Install BerkeleyDB + ./contrib/install_db4.sh `pwd` --enable-cxx + + # Build Dependencies + cd depends + make -j$(nproc) HOST=x86_64-linux-gnu + cd .. + + # Configure and Build + ./autogen.sh + CONFIG_SITE=$PWD/depends/x86_64-linux-gnu/share/config.site ./configure --with-bdb --with-sqlite --with-gui=yes --with-zmq + make -j$(nproc) + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v3 + with: + category: "/language:${{matrix.language}}" From a317cb5895f42c96de49188d46877fce0ef23904 Mon Sep 17 00:00:00 2001 From: GTO90 Date: Sun, 22 Dec 2024 09:40:55 -0600 Subject: [PATCH 03/10] ci: Update CodeQL workflow schedule to run weekly on Sundays --- .github/workflows/codeql.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index d7b973a295..64b7fef63d 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -17,7 +17,7 @@ on: pull_request: branches: ["develop", "master", "release**/**/*"] schedule: - - cron: "34 17 * * 2" + - cron: "0 0 * * 0" jobs: analyze: From 7972368dd9357af8ff77375ba56baa036b307cfb Mon Sep 17 00:00:00 2001 From: GTO90 Date: Sun, 22 Dec 2024 10:22:54 -0600 Subject: [PATCH 04/10] fix: Change CodeQL workflow build mode for C/C++ from autobuild to manual --- .github/workflows/codeql.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 64b7fef63d..f493abd22d 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -44,7 +44,7 @@ jobs: matrix: include: - language: c-cpp - build-mode: autobuild + build-mode: manual - language: java-kotlin build-mode: none # This mode only analyzes Java. Set this to 'autobuild' or 'manual' to analyze Kotlin too. - language: python From 6dccde7fef03a723d1c4af6350e6592b18f4b260 Mon Sep 17 00:00:00 2001 From: GTO90 Date: Sun, 22 Dec 2024 11:14:25 -0600 Subject: [PATCH 05/10] ci: Add concurrency configuration to CodeQL workflow and support for actions language --- .github/workflows/codeql.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index f493abd22d..2670f1c227 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -11,6 +11,11 @@ # name: "CodeQL Advanced" +# Add this concurrency configuration right after the 'name' field +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + on: push: branches: ["develop", "master", "release**/**/*"] @@ -51,6 +56,8 @@ jobs: build-mode: none - language: javascript-typescript build-mode: none + - language: actions + build-mode: none # CodeQL supports the following values keywords for 'language': 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift' # Use `c-cpp` to analyze code written in C, C++ or both # Use 'java-kotlin' to analyze code written in Java, Kotlin or both From 59f5b47718a26d8d0ea381dce77822bc751f1cd1 Mon Sep 17 00:00:00 2001 From: GTO90 Date: Sun, 22 Dec 2024 11:14:59 -0600 Subject: [PATCH 06/10] ci: Fix indentation in CI workflow for pull request triggers --- .github/workflows/ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 111e104c6d..fae58a9894 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,14 +4,14 @@ name: DigiByte CI -on: - pull_request: - branches: [ develop, master ] - concurrency: group: ${{ github.event_name != 'pull_request' && github.run_id || github.ref }} cancel-in-progress: true +on: + pull_request: + branches: [ develop, master ] + env: CI_FAILFAST_TEST_LEAVE_DANGLING: 1 # GHA does not care about dangling processes and setting this variable avoids killing the CI script itself on error From 8be6d4c06f171063c76a67f5d670bd979ce2eb38 Mon Sep 17 00:00:00 2001 From: GTO90 Date: Sun, 22 Dec 2024 11:15:08 -0600 Subject: [PATCH 07/10] ci: Fix formatting in CI workflow for pull request branches and environment variable comments --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fae58a9894..6803ecf35a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,10 +10,10 @@ concurrency: on: pull_request: - branches: [ develop, master ] + branches: [develop, master] env: - CI_FAILFAST_TEST_LEAVE_DANGLING: 1 # GHA does not care about dangling processes and setting this variable avoids killing the CI script itself on error + CI_FAILFAST_TEST_LEAVE_DANGLING: 1 # GHA does not care about dangling processes and setting this variable avoids killing the CI script itself on error jobs: build: @@ -94,4 +94,4 @@ jobs: if: failure() with: name: test-suite-log - path: test-suite.log \ No newline at end of file + path: test-suite.log From 1b34794a5806b92e70dca9e5573aeae8d58eb0d6 Mon Sep 17 00:00:00 2001 From: GTO90 Date: Sun, 22 Dec 2024 11:18:47 -0600 Subject: [PATCH 08/10] fix: Update CodeQL queries to conditionally include security-extended for non-actions languages --- .github/workflows/codeql.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 2670f1c227..8f005ea702 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -76,12 +76,7 @@ jobs: with: languages: ${{ matrix.language }} build-mode: ${{ matrix.build-mode }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - - # 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 - queries: security-extended,security-and-quality + queries: ${{ matrix.language != 'actions' && 'security-extended,security-and-quality' || 'security-and-quality' }} dependency-caching: true # If the analyze step fails for one of the languages you are analyzing with From dfbbbc58c7d9933777724b2b01f017782938e0fb Mon Sep 17 00:00:00 2001 From: GTO90 Date: Sun, 22 Dec 2024 11:23:53 -0600 Subject: [PATCH 09/10] fix: Update CodeQL queries to exclude security-extended for non-actions languages --- .github/workflows/codeql.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 8f005ea702..cf0a464d4a 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -76,7 +76,7 @@ jobs: with: languages: ${{ matrix.language }} build-mode: ${{ matrix.build-mode }} - queries: ${{ matrix.language != 'actions' && 'security-extended,security-and-quality' || 'security-and-quality' }} + queries: ${{ matrix.language != 'actions' && 'security-extended,security-and-quality' || '' }} dependency-caching: true # If the analyze step fails for one of the languages you are analyzing with From b7ed70d4cc8c73228b6207feb39083dd1449f763 Mon Sep 17 00:00:00 2001 From: GTO90 Date: Sun, 22 Dec 2024 12:46:41 -0600 Subject: [PATCH 10/10] ci: Add paths-ignore to CodeQL workflow and create config file for filtering --- .github/codeql/codeql-config.yml | 9 +++++++++ .github/workflows/codeql.yml | 7 +++++++ 2 files changed, 16 insertions(+) create mode 100644 .github/codeql/codeql-config.yml diff --git a/.github/codeql/codeql-config.yml b/.github/codeql/codeql-config.yml new file mode 100644 index 0000000000..534259c014 --- /dev/null +++ b/.github/codeql/codeql-config.yml @@ -0,0 +1,9 @@ +paths-ignore: + - 'depends/**' + - 'contrib/**' +paths-filter: + - exclude: + - 'depends/**/*.cpp' + - 'depends/**/*.h' + - 'contrib/**/*.cpp' + - 'contrib/**/*.h' \ No newline at end of file diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index cf0a464d4a..6d28f09789 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -19,8 +19,14 @@ concurrency: on: push: branches: ["develop", "master", "release**/**/*"] + paths-ignore: + - 'depends/**' + - 'contrib/**' pull_request: branches: ["develop", "master", "release**/**/*"] + paths-ignore: + - 'depends/**' + - 'contrib/**' schedule: - cron: "0 0 * * 0" @@ -78,6 +84,7 @@ jobs: build-mode: ${{ matrix.build-mode }} queries: ${{ matrix.language != 'actions' && 'security-extended,security-and-quality' || '' }} dependency-caching: true + config-file: ./.github/codeql/codeql-config.yml # If the analyze step fails for one of the languages you are analyzing with # "We were unable to automatically build your code", modify the matrix above