Repository navigation
95 lines (84 loc) · 3.07 KB
/
Copy pathmalicious-code-scan.yml
File metadata and controls
95 lines (84 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# Copyright 2026 Erst Users
# SPDX-License-Identifier: Apache-2.0
#
# Looks at what a pull request ADDS for the shapes malicious code takes:
# credentials, key material reaching a log or a socket, runtime evaluation,
# traffic to somewhere this project has no business talking to, and changes to
# CI itself.
#
# This project merges a lot of community contributions, which is exactly the
# path an attacker would use. The scan does not replace review — it decides
# which twenty lines of a nine-hundred-line diff a reviewer should read first.
name: Malicious Code Scan
on:
pull_request:
push:
branches: [main]
# Read-only, and deliberately `pull_request` rather than `pull_request_target`:
# this workflow reads code from forks, so it must never run with credentials
# that code could reach.
permissions:
contents: read
concurrency:
group: malicious-code-scan-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
scan-diff:
name: Scan added lines
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
# The scan compares against the base, so it needs the history that
# reaches it.
fetch-depth: 0
- name: Resolve the range to scan
id: range
shell: bash
run: |
set -euo pipefail
if [ "${{ github.event_name }}" = "pull_request" ]; then
echo "base=${{ github.event.pull_request.base.sha }}" >> "$GITHUB_OUTPUT"
echo "head=${{ github.event.pull_request.head.sha }}" >> "$GITHUB_OUTPUT"
else
# On a push, compare against the commit before it. A first commit
# has no parent, so fall back to the empty tree.
base=$(git rev-parse "${{ github.sha }}^" 2>/dev/null \
|| git hash-object -t tree /dev/null)
echo "base=${base}" >> "$GITHUB_OUTPUT"
echo "head=${{ github.sha }}" >> "$GITHUB_OUTPUT"
fi
- name: Scan
run: |
echo "## Malicious code scan" >> "$GITHUB_STEP_SUMMARY"
./scripts/security/scan-diff.sh \
"${{ steps.range.outputs.base }}" \
"${{ steps.range.outputs.head }}"
codeql:
name: CodeQL
runs-on: ubuntu-latest
permissions:
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
language: [go, javascript-typescript, actions]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Initialise CodeQL
uses: github/codeql-action/init@v3
with:
language: ${{ matrix.language }}
# security-extended reaches past the default set into the injection
# and data-flow queries that matter here: a path from contributor
# input to a command line, a file write, or an outbound request.
queries: security-extended
- name: Autobuild
uses: github/codeql-action/autobuild@v3
- name: Analyse
uses: github/codeql-action/analyze@v3
with:
category: /language:${{ matrix.language }}