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
16 changes: 16 additions & 0 deletions .cppcheck-suppressions
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// cppcheck suppressions for ngx_http_security_headers_module.
// Keep this list tight: suppress noise, never a real bug. If cppcheck flags a
// genuine issue, fix the code rather than adding a line here.

// nginx headers are pulled in via -I system paths; we don't want cppcheck
// reporting on or descending into them.
missingIncludeSystem

// Module entry points (handlers, directive setters, init/exit callbacks) are
// referenced only through nginx's static command/module tables, so cppcheck
// cannot see the call sites and reports them as unused.
unusedFunction

// Avoid failing the build when a suppression above stops matching after a
// refactor; surfaced as information, reviewed when tuning this file.
unmatchedSuppression
6 changes: 6 additions & 0 deletions .github/codeql/codeql-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: "CodeQL config for ngx_http_security_headers_module"

# CodeQL builds the whole nginx tree to analyze our module, but we only care
# about findings in code we own. Restrict reported paths to the module sources.
paths:
- "src/"
49 changes: 49 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,52 @@ jobs:
- name: Test the module
run: |
PATH=$(pwd)/nginx/objs:$PATH PERL5LIB=$HOME/perl5/lib/perl5 TEST_NGINX_VERBOSE=true prove -v

test-asan:
runs-on: ubuntu-latest
env:
NGINX_VERSION: release-1.27.2

steps:
- uses: actions/checkout@v3

- name: Install build and test dependencies
run: |
sudo apt-get --yes update
sudo apt-get install --yes libpcre3-dev libssl-dev zlib1g-dev perl cpanminus git

- name: Install Test::Nginx
run: |
cpanm --notest --local-lib=$HOME/perl5 Test::Nginx Test::Nginx::Socket

- name: Build nginx with the module statically under AddressSanitizer
run: |
git clone --depth 1 --branch "${NGINX_VERSION}" \
https://github.com/nginx/nginx.git /tmp/nginx-src
cd /tmp/nginx-src
./auto/configure --with-debug --with-compat \
--add-module="${GITHUB_WORKSPACE}" \
--with-cc-opt="-fsanitize=address -fno-omit-frame-pointer -g" \
--with-ld-opt="-fsanitize=address"
make -j"$(nproc)"

- name: Run test suite under AddressSanitizer
# detect_leaks=0 — nginx leaves benign allocations live at the point
# Test::Nginx kills it. The post-run grep below catches real ASan
# reports written to /tmp/asan/asan.* even when prove returns 0.
env:
TEST_NGINX_BINARY: /tmp/nginx-src/objs/nginx
ASAN_OPTIONS: detect_leaks=0:abort_on_error=1:log_path=/tmp/asan/asan
run: |
mkdir -p /tmp/asan
export PATH=/tmp/nginx-src/objs:$PATH PERL5LIB=$HOME/perl5/lib/perl5
set +e
prove -v t/*.t
rc=$?
set -e
if grep -q "AddressSanitizer\|runtime error" /tmp/asan/asan.* 2>/dev/null; then
echo "::error::AddressSanitizer / UBSan reports detected"
cat /tmp/asan/asan.* >&2
exit 1
fi
exit $rc
77 changes: 77 additions & 0 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Static Analysis

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
cppcheck:
runs-on: ubuntu-latest
env:
NGINX_VERSION: release-1.27.2

steps:
- uses: actions/checkout@v4

- name: Install cppcheck and nginx build deps
run: |
sudo apt-get update
sudo apt-get install -y cppcheck \
build-essential libpcre3-dev libssl-dev zlib1g-dev git

- name: Fetch nginx headers
run: |
git clone --depth 1 --branch "${NGINX_VERSION}" \
https://github.com/nginx/nginx.git /tmp/nginx-src
cd /tmp/nginx-src
./auto/configure --with-debug --with-compat

- name: Run cppcheck
run: |
cppcheck --enable=warning,portability,performance \
--check-level=exhaustive \
--error-exitcode=1 \
--suppressions-list=.cppcheck-suppressions \
--suppress=missingIncludeSystem \
--std=c11 \
-I /tmp/nginx-src/src/core -I /tmp/nginx-src/src/event \
-I /tmp/nginx-src/src/http -I /tmp/nginx-src/src/http/modules \
-I /tmp/nginx-src/src/os/unix -I /tmp/nginx-src/objs \
src/ngx_http_security_headers_module.c

codeql:
runs-on: ubuntu-latest
# Public repo: real upload to the Security tab; permissions: security-events
# needs write.
permissions:
actions: read
contents: read
security-events: write
env:
NGINX_VERSION: release-1.27.2

steps:
- uses: actions/checkout@v4

- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: c-cpp
config-file: ./.github/codeql/codeql-config.yml

- name: Build nginx with the module (static)
run: |
sudo apt-get update
sudo apt-get install -y build-essential \
libpcre3-dev libssl-dev zlib1g-dev git
git clone --depth 1 --branch "${NGINX_VERSION}" \
https://github.com/nginx/nginx.git /tmp/nginx-src
cd /tmp/nginx-src
./auto/configure --with-compat \
--add-module="${GITHUB_WORKSPACE}"
make -j"$(nproc)"

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
/nbproject
/t/servroot
/t/servroot
CLAUDE.md
.cursor/
test-error.log
Loading