From 523287e6b5e2432859b10766051da0c6d45557c0 Mon Sep 17 00:00:00 2001 From: codesecuredev-01 Date: Mon, 23 Mar 2026 16:15:34 +0400 Subject: [PATCH 1/7] Create codesecure.yml --- .github/workflows/codesecure.yml | 71 ++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 .github/workflows/codesecure.yml diff --git a/.github/workflows/codesecure.yml b/.github/workflows/codesecure.yml new file mode 100644 index 0000000..83a7d20 --- /dev/null +++ b/.github/workflows/codesecure.yml @@ -0,0 +1,71 @@ +name: CodeSecure Security Scan (Private) + +on: [push, pull_request] + +permissions: + contents: read + security-events: write + +jobs: + scan: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.12" + + - name: Install CodeSecure + run: | + if ! command -v codesecure &> /dev/null; then + pip install codesecure-core codesecure-mcp codesecure-cli + fi + + - name: Run Security Scan + id: scanner + continue-on-error: true + run: | + printf "y\nn\n" | codesecure scan . --fail-on critical,high --format sarif --output results.sarif + + - name: Process and Patch SARIF + if: always() + run: | + REPORT_PATH=$(find . -name "*.sarif" -type f | head -n 1) + if [ -n "$REPORT_PATH" ]; then + cp "$REPORT_PATH" fixed_results.sarif + echo "Successfully found and patched $REPORT_PATH" + else + echo "No SARIF report found!" + exit 1 + fi + # Fix timestamps and null GUIDs for GitHub compatibility + sed -i 's/+00:00Z/Z/g' fixed_results.sarif + sed -i 's/"guid": null/"guid": "cea0f146-248d-44a8-a320-94943960e6e2"/g' fixed_results.sarif + + # This step will likely still fail with a 404 on a Free Private repo, + # but we keep it here for future-proofing. + - name: Upload Results to GitHub Security Tab + if: always() + continue-on-error: true + uses: github/codeql-action/upload-sarif@v4 + with: + sarif_file: fixed_results.sarif + token: ${{ secrets.SCAN_TOKEN }} + + # THIS IS THE WORKAROUND: Save the file for local viewing in VS Code + - name: Save Scan Results for Local Viewing + if: always() + uses: actions/upload-artifact@v4 + with: + name: codesecure-report + path: fixed_results.sarif + retention-days: 14 + + - name: Check Quality Gate + if: always() && steps.scanner.outcome == 'failure' + run: | + echo "Security scan failed quality gate (Critical/High issues found)." + exit 1 From e3d939fd47387e080dce9b935c20229904d02846 Mon Sep 17 00:00:00 2001 From: codesecuredev-01 Date: Mon, 23 Mar 2026 16:37:42 +0400 Subject: [PATCH 2/7] Create codeql.yml --- .github/workflows/codeql.yml | 99 ++++++++++++++++++++++++++++++++++++ 1 file changed, 99 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 0000000..47fea6b --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,99 @@ +# 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: [ "main" ] + pull_request: + branches: [ "main" ] + schedule: + - cron: '29 19 * * 3' + +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: actions + build-mode: none + # CodeQL supports the following values keywords for 'language': 'actions', 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'rust', '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 + + # Add any setup steps before running the `github/codeql-action/init` action. + # This includes steps like installing compilers or runtimes (`actions/setup-node` + # or others). This is typically only required for manual builds. + # - name: Setup runtime (example) + # uses: actions/setup-example@v1 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v4 + 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 + - name: Run manual build steps + 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@v4 + with: + category: "/language:${{matrix.language}}" From 87299136b6339ffef158a09a6fd5319d5d35461e Mon Sep 17 00:00:00 2001 From: codesecuredev-01 Date: Tue, 24 Mar 2026 21:34:40 +0400 Subject: [PATCH 3/7] Update codesecure.yml --- .github/workflows/codesecure.yml | 63 ++++++++++++++------------------ 1 file changed, 27 insertions(+), 36 deletions(-) diff --git a/.github/workflows/codesecure.yml b/.github/workflows/codesecure.yml index 83a7d20..6e7a5d8 100644 --- a/.github/workflows/codesecure.yml +++ b/.github/workflows/codesecure.yml @@ -1,10 +1,11 @@ +# github public repo name: CodeSecure Security Scan (Private) - on: [push, pull_request] permissions: contents: read security-events: write + actions: read jobs: scan: @@ -13,59 +14,49 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - - name: Set up Python - uses: actions/setup-python@v5 + - name: Google Auth + uses: google-github-actions/auth@v2 with: - python-version: "3.12" - - - name: Install CodeSecure - run: | - if ! command -v codesecure &> /dev/null; then - pip install codesecure-core codesecure-mcp codesecure-cli - fi + credentials_json: ${{ secrets.GCP_SA_KEY }} + + - name: Setup GCR + run: gcloud auth configure-docker gcr.io --quiet - name: Run Security Scan id: scanner continue-on-error: true + # We use -u root to ensure permissions on the mounted workspace. + # We set CODESECURE_TOKEN="" as it is optional during the Beta period. run: | - printf "y\nn\n" | codesecure scan . --fail-on critical,high --format sarif --output results.sarif + docker run --rm \ + -u root \ + -v ${{ github.workspace }}:/workspace \ + -e GOOGLE_API_KEY=${{ secrets.GOOGLE_API_KEY }} \ + -e CODESECURE_TOKEN="" \ + gcr.io/codesecure-479807/codesecure:1.0.21 \ + scan /workspace \ + --format sarif \ + --output /workspace/codesecure_scan_reports \ + --fail-on critical,high - - name: Process and Patch SARIF - if: always() - run: | - REPORT_PATH=$(find . -name "*.sarif" -type f | head -n 1) - if [ -n "$REPORT_PATH" ]; then - cp "$REPORT_PATH" fixed_results.sarif - echo "Successfully found and patched $REPORT_PATH" - else - echo "No SARIF report found!" - exit 1 - fi - # Fix timestamps and null GUIDs for GitHub compatibility - sed -i 's/+00:00Z/Z/g' fixed_results.sarif - sed -i 's/"guid": null/"guid": "cea0f146-248d-44a8-a320-94943960e6e2"/g' fixed_results.sarif - - # This step will likely still fail with a 404 on a Free Private repo, - # but we keep it here for future-proofing. - name: Upload Results to GitHub Security Tab if: always() - continue-on-error: true - uses: github/codeql-action/upload-sarif@v4 + uses: github/codeql-action/upload-sarif@v3 with: - sarif_file: fixed_results.sarif - token: ${{ secrets.SCAN_TOKEN }} + # Automatically detects and uploads the .sarif file created in the folder + sarif_file: codesecure_scan_reports + token: ${{ secrets.GITHUB_TOKEN }} - # THIS IS THE WORKAROUND: Save the file for local viewing in VS Code - - name: Save Scan Results for Local Viewing + - name: Save Scan Results as Artifact if: always() uses: actions/upload-artifact@v4 with: name: codesecure-report - path: fixed_results.sarif + path: codesecure_scan_reports retention-days: 14 - name: Check Quality Gate if: always() && steps.scanner.outcome == 'failure' run: | - echo "Security scan failed quality gate (Critical/High issues found)." + echo "❌ Security scan failed quality gate (Critical/High issues found)." exit 1 From d939e24b1ad732d3181a3f4402ed605333ba1642 Mon Sep 17 00:00:00 2001 From: codesecuredev-01 Date: Tue, 24 Mar 2026 21:40:04 +0400 Subject: [PATCH 4/7] Update codesecure.yml --- .github/workflows/codesecure.yml | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/.github/workflows/codesecure.yml b/.github/workflows/codesecure.yml index 6e7a5d8..f21d3f3 100644 --- a/.github/workflows/codesecure.yml +++ b/.github/workflows/codesecure.yml @@ -1,5 +1,5 @@ # github public repo -name: CodeSecure Security Scan (Private) +name: CodeSecure Security Scan (Public) on: [push, pull_request] permissions: @@ -14,20 +14,14 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - - name: Google Auth - uses: google-github-actions/auth@v2 - with: - credentials_json: ${{ secrets.GCP_SA_KEY }} - - - name: Setup GCR - run: gcloud auth configure-docker gcr.io --quiet + # NO GOOGLE AUTH REQUIRED IF IMAGE IS PUBLIC + # NO SETUP GCR REQUIRED IF IMAGE IS PUBLIC - name: Run Security Scan id: scanner continue-on-error: true - # We use -u root to ensure permissions on the mounted workspace. - # We set CODESECURE_TOKEN="" as it is optional during the Beta period. run: | + # The image will be pulled automatically without auth if it's public docker run --rm \ -u root \ -v ${{ github.workspace }}:/workspace \ @@ -43,7 +37,6 @@ jobs: if: always() uses: github/codeql-action/upload-sarif@v3 with: - # Automatically detects and uploads the .sarif file created in the folder sarif_file: codesecure_scan_reports token: ${{ secrets.GITHUB_TOKEN }} From ab46d151cc427d0f39443ac37675f0a684ab92c2 Mon Sep 17 00:00:00 2001 From: codesecuredev-01 Date: Wed, 25 Mar 2026 12:30:30 +0400 Subject: [PATCH 5/7] Create codesecure-test.yml --- .github/workflows/codesecure-test.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .github/workflows/codesecure-test.yml diff --git a/.github/workflows/codesecure-test.yml b/.github/workflows/codesecure-test.yml new file mode 100644 index 0000000..e3e6a3a --- /dev/null +++ b/.github/workflows/codesecure-test.yml @@ -0,0 +1,24 @@ +name: Test PR Decoration +on: + pull_request: # Trigger on PRs to test the decorator + branches: [ main ] + +jobs: + security-scan: + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: write # CRITICAL for PR decoration + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 # Needed for Baseline Comparison (Fixed vs New) + + - name: Run CodeSecure Scan + uses: docker://gcr.io/codesecure-479807/codesecure:1.0.21 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GOOGLE_API_KEY: ${{ secrets.GOOGLE_API_KEY }} # Optional: for AI Grade + with: + args: scan . --decorate-pr auto --fail-on critical,high --format markdown From 31a1d336719e7ed3f864e17e11230fb2982703b4 Mon Sep 17 00:00:00 2001 From: codesecuredev-01 Date: Wed, 25 Mar 2026 12:38:15 +0400 Subject: [PATCH 6/7] Create test.py --- test.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 test.py diff --git a/test.py b/test.py new file mode 100644 index 0000000..bb8e349 --- /dev/null +++ b/test.py @@ -0,0 +1,16 @@ +import sqlite3 +import subprocess +import os + +def find_user(username): + # CRITICAL: SQL Injection vulnerability (B608) + conn = sqlite3.connect('users.db') + cursor = conn.cursor() + query = f"SELECT * FROM users WHERE username = '{username}'" + cursor.execute(query) + return cursor.fetchall() + +def run_system_command(user_input): + # CRITICAL: Command Injection vulnerability (B602/B605) + os.system(f"echo {user_input}") + subprocess.Popen(user_input, shell=True) From a98b1856624694fcae0aea683f3ff860e4fee418 Mon Sep 17 00:00:00 2001 From: codesecuredev-01 Date: Wed, 25 Mar 2026 13:12:08 +0400 Subject: [PATCH 7/7] Update test.py --- test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test.py b/test.py index bb8e349..c7a4b3c 100644 --- a/test.py +++ b/test.py @@ -1,4 +1,4 @@ -import sqlite3 +# import sqlite3 import subprocess import os