Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
Checks: 'clang-diagnostic-*,clang-analyzer-*,read*,modern*,hicpp*,performance*,-readability-magic-numbers,-clang-diagnostic-gnu-statement-expression,-hicpp-use-auto,-modernize-use-equals-default,-modernize-deprecated-headers,-readability-uppercase-literal-suffix'
# Enhanced security-focused clang-tidy configuration for enterprise-grade analysis
Checks: 'clang-diagnostic-*,clang-analyzer-*,clang-analyzer-security*,cert-*,bugprone-*,concurrency-*,cppcoreguidelines-*,read*,modern*,hicpp*,performance*,misc-*,-readability-magic-numbers,-clang-diagnostic-gnu-statement-expression,-hicpp-use-auto,-modernize-use-equals-default,-modernize-deprecated-headers,-readability-uppercase-literal-suffix,-cert-err33-c'
WarningsAsErrors: ''
HeaderFilterRegex: ''
AnalyzeTemporaryDtors: false
FormatStyle: file
User: fabio
CheckOptions:
Expand Down
47 changes: 47 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
version: 2
updates:
# GitHub Actions security updates
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
commit-message:
prefix: "security"
prefix-development: "security"
labels:
- "security"
- "dependencies"
reviewers:
- "Fabio3rs"

# CMake/C++ dependency scanning via ecosystem detection
- package-ecosystem: "cmake"
directory: "/"
schedule:
interval: "weekly"
commit-message:
prefix: "security"
prefix-development: "security"
labels:
- "security"
- "dependencies"
- "c++"
reviewers:
- "Fabio3rs"
# Security-focused update strategy
target-branch: "develop"
open-pull-requests-limit: 10

# Docker dependencies if Dockerfile exists
- package-ecosystem: "docker"
directory: "/"
schedule:
interval: "weekly"
commit-message:
prefix: "security"
labels:
- "security"
- "dependencies"
- "docker"
reviewers:
- "Fabio3rs"
34 changes: 33 additions & 1 deletion .github/workflows/Test, Build and Test-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ jobs:
sudo apt-get update && sudo apt-get install build-essential
sudo apt install cmake -y
sudo apt install clang-18 clang-tidy-18 clang-format ninja-build -y
# Add security analysis tools for enterprise-grade scanning
sudo apt install cppcheck valgrind -y
sudo add-apt-repository ppa:pistache+team/unstable && sudo apt update && sudo apt install libpistache-dev
sudo apt-get update && sudo apt-get install libcurl4 libcurl4-openssl-dev libpoco-dev libmysqlcppconn-dev -y
sudo apt install libgtest-dev googletest -y
Expand Down Expand Up @@ -54,9 +56,39 @@ jobs:
export CURRENT_SOURCE_DIR=$(pwd)
mkdir -p build && cd build
export CURRENT_BUILD_DIR=$(pwd)
cmake .. -G Ninja
# Enhanced security build flags for enterprise-grade security
cmake .. -G Ninja \
-DCMAKE_CXX_FLAGS="-Wall -Wextra -fstack-protector-strong -D_FORTIFY_SOURCE=3 -fPIE" \
-DCMAKE_EXE_LINKER_FLAGS="-pie -Wl,-z,relro,-z,now"
cmake --build . --config Debug --target all -j $(nproc) --

- name: Security Analysis - cppcheck
run: |
cd build
# Run cppcheck with security-focused analysis
cppcheck --enable=all --error-exitcode=1 --xml --xml-version=2 \
--suppress=missingIncludeSystem --suppress=unmatchedSuppression \
--suppress=unusedFunction --check-config \
--std=c++20 --platform=unix64 \
../src/ 2> cppcheck-results.xml || true

# Parse and display critical security findings
if [ -f cppcheck-results.xml ]; then
echo "=== Security Analysis Results (cppcheck) ==="
grep -E "(error|warning)" cppcheck-results.xml | head -20 || echo "No critical issues found"
echo "============================================="
fi

- name: Security Analysis - Enhanced clang-tidy
run: |
cd build
# Run enhanced clang-tidy with security focus
echo "=== Running enhanced security-focused clang-tidy ==="
find ../src -name "*.cpp" -o -name "*.hpp" | head -10 | \
xargs clang-tidy-18 --config-file=../.clang-tidy \
-p . --format-style=file || true
echo "===================================================="

- name: Test project
run: |
export CC=$(which clang-18)
Expand Down
67 changes: 67 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: "CodeQL Security Analysis"

on:
push:
branches: [ "main", "develop" ]
pull_request:
branches: [ "main" ]
schedule:
- cron: '30 2 * * 1' # Run weekly on Mondays at 2:30 AM

jobs:
analyze:
name: CodeQL Analysis
runs-on: ubuntu-latest
timeout-minutes: 360
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'cpp' ]

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive

- name: Install Dependencies
run: |
sudo apt-get update && sudo apt-get install -y build-essential
sudo apt install cmake ninja-build clang-18 clang-tidy-18 clang-format -y
sudo add-apt-repository ppa:pistache+team/unstable && sudo apt update && sudo apt install libpistache-dev
sudo apt-get install -y libcurl4 libcurl4-openssl-dev libpoco-dev libmysqlcppconn-dev
sudo apt install -y libgtest-dev googletest

- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# Enhanced security queries for enterprise-grade scanning
queries: +security-extended,security-and-quality

- name: Setup Build Environment
run: |
export CC=$(which clang-18)
export CXX=$(which clang++-18)
mkdir -p build && cd build
cmake .. -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_FLAGS="-Wall -Wextra -fstack-protector-strong -D_FORTIFY_SOURCE=3" \
-DCompileTestsApiFramework=OFF

- name: Build Project
run: |
cd build
export CC=$(which clang-18)
export CXX=$(which clang++-18)
cmake --build . --config Release --target cppapiframework -j $(nproc)

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
177 changes: 177 additions & 0 deletions .github/workflows/security-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
name: "Security Analysis & SBOM"

on:
push:
branches: [ "main", "develop" ]
pull_request:
branches: [ "main" ]
schedule:
- cron: '15 3 * * 2' # Run weekly on Tuesdays at 3:15 AM

env:
BUILD_TYPE: Release

permissions:
contents: read
security-events: write
actions: read

jobs:
security-analysis:
name: Security Analysis & SBOM Generation
runs-on: ubuntu-latest
timeout-minutes: 60

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Full history for better analysis

- name: Install Security Analysis Tools
run: |
sudo apt-get update
sudo apt-get install -y build-essential cmake ninja-build
sudo apt install libgtest-dev googletest -y
sudo apt-get install -y clang-18 clang-tidy-18 clang-format cppcheck valgrind
sudo add-apt-repository ppa:pistache+team/unstable && sudo apt update && sudo apt install libpistache-dev
sudo apt-get install -y libpoco-dev libmysqlcppconn-dev
# Install SBOM generation tools using official installation script
curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sudo sh -s -- -b /usr/local/bin
# Install security scanner using official installation script
curl -sSfL https://raw.githubusercontent.com/anchore/grype/main/install.sh | sudo sh -s -- -b /usr/local/bin

- name: Configure Build with Security Flags
run: |
export CC=$(which clang-18)
export CXX=$(which clang++-18)
mkdir -p build && cd build
cmake .. -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_FLAGS="-Wall -Wextra -fstack-protector-strong -D_FORTIFY_SOURCE=3 -fPIE -Wformat -Wformat-security" \
-DCMAKE_EXE_LINKER_FLAGS="-pie -Wl,-z,relro,-z,now -Wl,-z,noexecstack" \
-DCompileTestsApiFramework=OFF

- name: Build Project
run: |
cd build
export CC=$(which clang-18)
export CXX=$(which clang++-18)
cmake --build . --config Release --target cppapiframework -j $(nproc)

- name: Advanced Static Analysis - cppcheck
run: |
echo "::group::Running cppcheck security analysis"
cppcheck --enable=all --error-exitcode=0 --xml --xml-version=2 \
--platform=unix64 --std=c++20 \
--suppress=missingIncludeSystem --suppress=unmatchedSuppression \
--suppress=unusedFunction --check-config \
--inconclusive --force \
src/ 2> cppcheck-security-report.xml

echo "=== cppcheck Security Analysis Results ==="
if [ -f cppcheck-security-report.xml ]; then
grep -E "(error|warning)" cppcheck-security-report.xml || echo "No issues found"
fi
echo "=========================================="
echo "::endgroup::"

- name: Enhanced Security-Focused clang-tidy
run: |
echo "::group::Running enhanced clang-tidy security analysis"
cd build
echo "=== Security-focused clang-tidy Analysis ==="

# Run clang-tidy on key security-sensitive files
SECURITY_FILES="../src/Database/CSql.cpp ../src/WebInterface/CController.cpp ../src/Authorization/"

for file in $SECURITY_FILES; do
if [ -f "$file" ] || [ -d "$file" ]; then
echo "Analyzing: $file"
find "$file" -name "*.cpp" -o -name "*.hpp" 2>/dev/null | head -5 | \
xargs clang-tidy-18 --config-file=../.clang-tidy -p . --format-style=file \
--checks='-*,cert-*,bugprone-*,clang-analyzer-security*,cppcoreguidelines-*' || true
fi
done
echo "=============================================="
echo "::endgroup::"

- name: Generate Software Bill of Materials (SBOM)
run: |
echo "::group::Generating SBOM"
echo "=== Generating Software Bill of Materials ==="

# Create SBOM for the entire project
syft . -o json=sbom.json -o spdx-json=sbom.spdx.json -o table=sbom.txt || true

if [ -f sbom.txt ]; then
echo "Generated SBOM summary:"
head -20 sbom.txt
echo "Full SBOM saved to artifacts."
fi
echo "============================================="
echo "::endgroup::"

- name: Vulnerability Scanning with Grype
run: |
echo "::group::Running vulnerability scanning"
echo "=== Vulnerability Scanning ==="

# Scan for vulnerabilities in dependencies
if [ -f sbom.json ]; then
grype sbom:sbom.json -o table -o json=vulnerabilities.json || true

echo "Vulnerability scan results:"
if [ -f vulnerabilities.json ]; then
jq -r '.matches[] | select(.vulnerability.severity == "High" or .vulnerability.severity == "Critical") | "HIGH/CRITICAL: " + .vulnerability.id + " in " + .artifact.name' vulnerabilities.json 2>/dev/null || echo "No high/critical vulnerabilities found"
fi
else
grype . -o table -o json=vulnerabilities.json || true
fi
echo "==============================="
echo "::endgroup::"

- name: Security Summary Report
run: |
echo "::group::Security Analysis Summary"
echo "# πŸ›‘οΈ Security Analysis Summary" > security-summary.md
echo "" >> security-summary.md
echo "## Analysis Results" >> security-summary.md
echo "" >> security-summary.md

# Add cppcheck results
if [ -f cppcheck-security-report.xml ]; then
echo "### cppcheck Analysis" >> security-summary.md
CPPCHECK_ISSUES=$(grep -c "error\|warning" cppcheck-security-report.xml || echo "0")
echo "- Issues found: $CPPCHECK_ISSUES" >> security-summary.md
fi

# Add vulnerability scan results
if [ -f vulnerabilities.json ]; then
echo "### Vulnerability Scan" >> security-summary.md
HIGH_VULNS=$(jq -r '[.matches[] | select(.vulnerability.severity == "High" or .vulnerability.severity == "Critical")] | length' vulnerabilities.json 2>/dev/null || echo "0")
echo "- High/Critical vulnerabilities: $HIGH_VULNS" >> security-summary.md
fi

echo "### SBOM Generated" >> security-summary.md
if [ -f sbom.json ]; then
COMPONENTS=$(jq -r '.artifacts | length' sbom.json 2>/dev/null || echo "Unknown")
echo "- Components tracked: $COMPONENTS" >> security-summary.md
fi

cat security-summary.md
echo "::endgroup::"

- name: Upload Security Reports as Artifacts
uses: actions/upload-artifact@v4
if: always()
with:
name: security-analysis-reports
retention-days: 30
path: |
cppcheck-security-report.xml
sbom.json
sbom.spdx.json
sbom.txt
vulnerabilities.json
security-summary.md
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,6 @@ CTestTestfile.cmake
Makefile
cmake_install.cmake

# Security analysis reports (generated by security-scan.sh)
security-reports/

12 changes: 8 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

if(NOT DEFINED DISABLE_MANUAL_FIND_PACKAGES)
find_package(GTest REQUIRED)
include(GoogleTest)
if ("${CompileTestsApiFramework}" STREQUAL "ON")
find_package(GTest REQUIRED)
include(GoogleTest)
endif()
find_package(Git)
find_package(OpenSSL REQUIRED)
find_package(PkgConfig)
Expand Down Expand Up @@ -91,17 +93,19 @@ target_compile_definitions(${projectname} PRIVATE "PROJECT_NAME=\"cppapiframewor

# Compiler-specific compile flags
if (NOT DEFINED USING_COMPILER_FLAGS)
add_compile_definitions(_FORTIFY_SOURCE=3)

if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
message(STATUS "Setting G++ flags")
# G++
target_compile_options(${projectname} PRIVATE -Wall -Werror -Wextra -std=gnu++20 -Wformat-security -Wconversion -Wsign-conversion -Wno-gnu -Wno-gnu-statement-expression)
target_compile_options(${projectname} PRIVATE -Wall -Werror -Wextra -Wformat-security -Wconversion -Wsign-conversion -Wno-gnu -Wno-gnu-statement-expression)
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC")
message(STATUS "Setting MSVC flags")
# MSVC
target_compile_options(${projectname} PRIVATE /EHsc /W2 /c)
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
message(STATUS "Setting Clang flags")
set(USING_COMPILER_FLAGS -Weverything -Werror -Wno-unused-macros -std=gnu++20 -Wno-unsafe-buffer-usage -Wno-disabled-macro-expansion -Wpedantic -Wno-padded -Wno-constant-conversion -Wno-c++98-compat -Wno-padded -Wno-date-time -Wno-c++98-compat-pedantic -Wno-exit-time-destructors -Wno-global-constructors -Wno-gnu -Wno-gnu-statement-expression)
set(USING_COMPILER_FLAGS -Weverything -Werror -Wno-unused-macros -Wno-unsafe-buffer-usage -Wno-disabled-macro-expansion -Wpedantic -Wno-padded -Wno-constant-conversion -Wno-c++98-compat -Wno-padded -Wno-date-time -Wno-c++98-compat-pedantic -Wno-exit-time-destructors -Wno-global-constructors -Wno-gnu -Wno-gnu-statement-expression)
target_compile_options(${PROJECT_NAME} PRIVATE ${USING_COMPILER_FLAGS})
# Clang-tidy
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
Expand Down
Loading