forked from FWS/FWS-TEMPLATE-Website-OnePage
ci(security): add secret, dependency, shell and injection scans
This commit is contained in:
1 file changed
+131
@@ -0,0 +1,131 @@
|
||||
name: security
|
||||
|
||||
# Shared security gate for FWS repositories: leaked credentials, known
|
||||
# vulnerabilities in the dependencies, shell injection patterns and, through
|
||||
# opengrep, the language level injection rules (SQL, command, template, XSS).
|
||||
# Every tool is a static binary downloaded at run time so the job does not
|
||||
# depend on what the runner image happens to ship.
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
schedule:
|
||||
- cron: '0 4 * * 1'
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
env:
|
||||
GITLEAKS_VERSION: '8.28.0'
|
||||
OSV_SCANNER_VERSION: '2.7.1'
|
||||
SHELLCHECK_VERSION: '0.10.0'
|
||||
OPENGREP_VERSION: '2.1.0'
|
||||
|
||||
jobs:
|
||||
secrets:
|
||||
name: secrets
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
# `dir` scans the checkout rather than the history: a credential that was
|
||||
# removed from the tree must not keep the gate red forever, and the tree
|
||||
# is what a pull request introduces. A repository that needs to allowlist
|
||||
# fixtures ships a .gitleaks.toml next to this file.
|
||||
- name: Scan the tree for credentials
|
||||
run: |
|
||||
set -euo pipefail
|
||||
curl -fsSL -o "$RUNNER_TEMP/gitleaks.tgz" \
|
||||
"https://github.com/gitleaks/gitleaks/releases/download/v${GITLEAKS_VERSION}/gitleaks_${GITLEAKS_VERSION}_linux_x64.tar.gz"
|
||||
tar -xzf "$RUNNER_TEMP/gitleaks.tgz" -C "$RUNNER_TEMP" gitleaks
|
||||
config=()
|
||||
[ -f .gitleaks.toml ] && config=(--config .gitleaks.toml)
|
||||
"$RUNNER_TEMP/gitleaks" dir . --no-banner --redact --verbose --exit-code 1 "${config[@]}"
|
||||
|
||||
dependencies:
|
||||
name: dependencies
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
# OSV reads the lockfiles it recognises (npm, pip, Go, Cargo, Composer…)
|
||||
# and answers from osv.dev. A repository without a lockfile passes instead
|
||||
# of failing, so the same workflow fits every stack in the organisation.
|
||||
- name: Scan dependencies for known vulnerabilities
|
||||
run: |
|
||||
set -euo pipefail
|
||||
curl -fsSL -o "$RUNNER_TEMP/osv-scanner" \
|
||||
"https://github.com/google/osv-scanner/releases/download/v${OSV_SCANNER_VERSION}/osv-scanner_linux_amd64"
|
||||
chmod +x "$RUNNER_TEMP/osv-scanner"
|
||||
"$RUNNER_TEMP/osv-scanner" scan source --recursive --allow-no-lockfiles --format table .
|
||||
|
||||
shell:
|
||||
name: shell
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Install shellcheck
|
||||
run: |
|
||||
set -euo pipefail
|
||||
curl -fsSL -o "$RUNNER_TEMP/shellcheck.tar.xz" \
|
||||
"https://github.com/koalaman/shellcheck/releases/download/v${SHELLCHECK_VERSION}/shellcheck-v${SHELLCHECK_VERSION}.linux.x86_64.tar.xz"
|
||||
tar -xJf "$RUNNER_TEMP/shellcheck.tar.xz" -C "$RUNNER_TEMP"
|
||||
|
||||
- name: Collect the shell scripts
|
||||
run: |
|
||||
set -euo pipefail
|
||||
git ls-files -z '*.sh' '*.bash' 'PKGBUILD' > "$RUNNER_TEMP/scripts"
|
||||
printf '%s shell files to check\n' "$(tr -cd '\0' < "$RUNNER_TEMP/scripts" | wc -c)"
|
||||
|
||||
# SC2086/SC2046 and friends are the shapes an injection takes in shell.
|
||||
# They stay advisory for now: existing scripts would turn the gate red on
|
||||
# their first run, so warnings are reported and errors block.
|
||||
- name: Shellcheck warnings (advisory)
|
||||
continue-on-error: true
|
||||
run: |
|
||||
set -o pipefail
|
||||
[ -s "$RUNNER_TEMP/scripts" ] || { echo "No shell scripts in this repository."; exit 0; }
|
||||
xargs -0 -a "$RUNNER_TEMP/scripts" -r \
|
||||
"$RUNNER_TEMP/shellcheck-v${SHELLCHECK_VERSION}/shellcheck" -x --format=gcc --severity=warning
|
||||
|
||||
- name: Shellcheck errors
|
||||
run: |
|
||||
set -euo pipefail
|
||||
[ -s "$RUNNER_TEMP/scripts" ] || { echo "No shell scripts in this repository."; exit 0; }
|
||||
xargs -0 -a "$RUNNER_TEMP/scripts" -r \
|
||||
"$RUNNER_TEMP/shellcheck-v${SHELLCHECK_VERSION}/shellcheck" -x --severity=error
|
||||
|
||||
sast:
|
||||
name: sast
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 15
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Install opengrep
|
||||
run: |
|
||||
set -euo pipefail
|
||||
curl -fsSL -o "$RUNNER_TEMP/opengrep" \
|
||||
"https://github.com/opengrep/opengrep/releases/download/v${OPENGREP_VERSION}/opengrep_linux_x86"
|
||||
chmod +x "$RUNNER_TEMP/opengrep"
|
||||
|
||||
# Advisory on purpose: the rules flag real injection shapes (SQL, command,
|
||||
# template, XSS) but also patterns that a codebase already reviewed. Run
|
||||
# it blocking once the reported findings have been triaged and the false
|
||||
# positives allowlisted in .semgrepignore.
|
||||
- name: Injection and unsafe-pattern scan (advisory)
|
||||
continue-on-error: true
|
||||
run: |
|
||||
set -uo pipefail
|
||||
args=()
|
||||
git ls-files '*.php' | grep -q . && args+=(--config p/php) || true
|
||||
git ls-files '*.js' '*.mjs' '*.cjs' '*.ts' | grep -q . && args+=(--config p/javascript) || true
|
||||
git ls-files '*.py' | grep -q . && args+=(--config p/python) || true
|
||||
git ls-files '*.go' | grep -q . && args+=(--config p/golang) || true
|
||||
if [ "${#args[@]}" -eq 0 ]; then
|
||||
echo "No supported source files in this repository."
|
||||
exit 0
|
||||
fi
|
||||
"$RUNNER_TEMP/opengrep" scan "${args[@]}" --severity ERROR \
|
||||
--exclude 3rdparty --exclude node_modules --exclude vendor --exclude external .
|
||||
Reference in new issue
Block a user