@bugb-technologies/bravos 1.2.1 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -10
- package/dist/ci.js +11 -3
- package/dist/cli.js +50 -8
- package/dist/doctor.js +4 -16
- package/dist/guide.js +5 -3
- package/dist/help.js +16 -16
- package/dist/hooks.js +21 -0
- package/dist/install-proof-tool.js +117 -0
- package/dist/proof-tools.js +29 -0
- package/dist/report/check.js +4 -1
- package/dist/report/data.js +81 -149
- package/dist/report/markdown.js +1 -1
- package/dist/report/redact.js +16 -0
- package/dist/report/runs.js +169 -0
- package/dist/resync.js +272 -0
- package/dist/setup.js +31 -16
- package/dist/start/answers.js +5 -3
- package/dist/start/index.js +28 -14
- package/dist/versions.js +4 -3
- package/docs/GUIDE.md +12 -2
- package/hooks/lib/autopilot.mjs +216 -77
- package/hooks/lib/briefing.mjs +36 -5
- package/hooks/lib/nightly-stage.mjs +66 -0
- package/hooks/lib/nightly-tools.sh +45 -0
- package/hooks/lib/pre-pr.mjs +88 -17
- package/hooks/lib/proof-tool-pins.json +12 -0
- package/hooks/lib/replay.mjs +579 -0
- package/hooks/lib/resync.mjs +78 -0
- package/hooks/lib/setup.mjs +15 -6
- package/hooks/lib/snapshot.mjs +189 -0
- package/hooks/session-start.mjs +7 -3
- package/package.json +1 -1
- package/skills/bravos/SKILL.md +2 -1
- package/skills/bravos-annotate/SKILL.md +6 -5
- package/skills/bravos-annotate/scripts/slice.mjs +15 -8
- package/skills/bravos-cicd/SKILL.md +1 -1
- package/skills/bravos-env/SKILL.md +3 -3
- package/skills/bravos-prove/SKILL.md +11 -15
- package/skills/bravos-recheck/SKILL.md +3 -3
- package/skills/bravos-report/SKILL.md +1 -1
- package/skills/bravos-resync/SKILL.md +52 -0
- package/skills/bravos-schedule/SKILL.md +1 -1
- package/skills/bravos-ship/SKILL.md +1 -1
- package/skills/bravos-templatize/SKILL.md +3 -3
- package/templates/workflows/bravos-nightly-claude.yml +131 -74
- package/templates/workflows/bravos-nightly-codex.yml +130 -73
- package/templates/workflows/bravos-pr-gate.yml +88 -14
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
# bravos:generated — written by `bravos init --ci`; `bravos sync --ci` refreshes it while this line stays.
|
|
2
2
|
# The nightly "bulk bee": Codex covers the next slice of unannotated files with the
|
|
3
3
|
# bravos-annotate skill, the lint gate checks what it wrote, and the job opens one small PR.
|
|
4
|
-
#
|
|
5
|
-
#
|
|
6
|
-
# file's human-written attestation the scan step skips and the job annotates only.
|
|
4
|
+
# A separate clean runner first replays reviewed kits under a current scheduled grant.
|
|
5
|
+
# The author can then draft new kits in the annotation PR. Review and merge before replay.
|
|
7
6
|
# The nightly is on the Team plan: add the repo secret BRAVOS_LICENCE (the token from
|
|
8
7
|
# account.bugb.io/dashboard/license) so the agent's paid skills run; without it they say so and stop.
|
|
9
8
|
# Needs the repo secret OPENAI_API_KEY, and Settings > Actions > General > "Allow GitHub
|
|
@@ -25,7 +24,98 @@ concurrency:
|
|
|
25
24
|
cancel-in-progress: false
|
|
26
25
|
|
|
27
26
|
jobs:
|
|
27
|
+
replay:
|
|
28
|
+
# Scheduled evidence comes only from reviewed default-branch code. This fresh runner never runs an authoring agent.
|
|
29
|
+
if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
|
|
30
|
+
runs-on: ubuntu-latest
|
|
31
|
+
timeout-minutes: 90
|
|
32
|
+
permissions:
|
|
33
|
+
contents: read
|
|
34
|
+
outputs:
|
|
35
|
+
drafts: ${{ steps.ready.outputs.drafts }}
|
|
36
|
+
ledger: ${{ steps.scan.outputs.ledger }}
|
|
37
|
+
summary: ${{ steps.scan.outputs.summary }}
|
|
38
|
+
env:
|
|
39
|
+
BRAVOS_DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
|
|
40
|
+
BRAVOS_SCAN_TARGET: ${{ vars.BRAVOS_SCAN_TARGET }}
|
|
41
|
+
steps:
|
|
42
|
+
- uses: actions/checkout@v4
|
|
43
|
+
- uses: actions/setup-node@v4
|
|
44
|
+
with:
|
|
45
|
+
node-version: 22
|
|
46
|
+
- name: Check current scheduled consent
|
|
47
|
+
id: ready
|
|
48
|
+
env:
|
|
49
|
+
BRAVOS_APP_START: ${{ vars.BRAVOS_APP_START }}
|
|
50
|
+
run: |
|
|
51
|
+
echo "drafts=$(node .bravos/hooks/lib/replay.mjs scheduled-drafts)" >> "$GITHUB_OUTPUT"
|
|
52
|
+
if [ -n "$BRAVOS_SCAN_TARGET" ]; then
|
|
53
|
+
python3 -m venv "$RUNNER_TEMP/bravos-python"
|
|
54
|
+
"$RUNNER_TEMP/bravos-python/bin/pip" install "PyYAML==6.0.2"
|
|
55
|
+
export CXG_PYTHON="$RUNNER_TEMP/bravos-python/bin/python"
|
|
56
|
+
echo "CXG_PYTHON=$CXG_PYTHON" >> "$GITHUB_ENV"
|
|
57
|
+
fi
|
|
58
|
+
mode=$(node .bravos/hooks/lib/replay.mjs scheduled-ready)
|
|
59
|
+
echo "mode=$mode" >> "$GITHUB_OUTPUT"
|
|
60
|
+
- uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
|
|
61
|
+
if: steps.ready.outputs.mode != 'disabled'
|
|
62
|
+
with:
|
|
63
|
+
path: ${{ runner.temp }}/bravos-cxg
|
|
64
|
+
# Only this job (no authoring agent) writes the replay key, so a binary another job touched never reaches it.
|
|
65
|
+
key: bravos-cxg-replay-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('.bravos/hooks/lib/proof-tool-pins.json') }}
|
|
66
|
+
- name: Install replay tools
|
|
67
|
+
if: steps.ready.outputs.mode != 'disabled'
|
|
68
|
+
run: bash .bravos/hooks/lib/nightly-tools.sh replay
|
|
69
|
+
- name: Start the reviewed loopback build
|
|
70
|
+
if: steps.ready.outputs.mode == 'loopback'
|
|
71
|
+
env:
|
|
72
|
+
BRAVOS_APP_START: ${{ vars.BRAVOS_APP_START }}
|
|
73
|
+
run: |
|
|
74
|
+
test "$(node .bravos/hooks/lib/replay.mjs scheduled-ready)" = loopback
|
|
75
|
+
node .bravos/hooks/lib/replay.mjs check-port "$BRAVOS_SCAN_TARGET"
|
|
76
|
+
env -i PATH="$PATH" HOME="$HOME" CI=true bash -c "$BRAVOS_APP_START" > "$RUNNER_TEMP/bravos-app.log" 2>&1 &
|
|
77
|
+
for _ in $(seq 1 60); do
|
|
78
|
+
if curl --silent --max-time 2 --output /dev/null "$BRAVOS_SCAN_TARGET"; then
|
|
79
|
+
# Witness the tree once the app is up, so files its start writes into the checkout match at replay.
|
|
80
|
+
node .bravos/hooks/lib/replay.mjs build "$BRAVOS_SCAN_TARGET" > "$RUNNER_TEMP/bravos-build.json"
|
|
81
|
+
exit 0
|
|
82
|
+
fi
|
|
83
|
+
sleep 2
|
|
84
|
+
done
|
|
85
|
+
exit 1
|
|
86
|
+
- name: Replay reviewed kits
|
|
87
|
+
id: scan
|
|
88
|
+
env:
|
|
89
|
+
MODE: ${{ steps.ready.outputs.mode }}
|
|
90
|
+
BRAVOS_SCAN_AUTH: ${{ vars.BRAVOS_SCAN_AUTH }}
|
|
91
|
+
BRAVOS_AUTH_STATE: ${{ secrets.BRAVOS_AUTH_STATE }}
|
|
92
|
+
BRAVOS_AUTH_STATES: ${{ secrets.BRAVOS_AUTH_STATES }}
|
|
93
|
+
run: |
|
|
94
|
+
if [ "$MODE" = disabled ]; then
|
|
95
|
+
echo "summary=Scheduled proof skipped. See the consent check." >> "$GITHUB_OUTPUT"
|
|
96
|
+
exit 0
|
|
97
|
+
fi
|
|
98
|
+
if [ "$MODE" = loopback ]; then
|
|
99
|
+
BRAVOS_REPLAY_BUILD=$(cat "$RUNNER_TEMP/bravos-build.json")
|
|
100
|
+
export BRAVOS_REPLAY_BUILD
|
|
101
|
+
fi
|
|
102
|
+
result=0
|
|
103
|
+
node .bravos/hooks/lib/replay.mjs scheduled || result=$?
|
|
104
|
+
if [ -f .guardlink/hypotheses.json ] && [ -n "$(git status --porcelain -- .guardlink/hypotheses.json)" ]; then
|
|
105
|
+
mkdir -p "$RUNNER_TEMP/bravos-verified-ledger"
|
|
106
|
+
cp .guardlink/hypotheses.json "$RUNNER_TEMP/bravos-verified-ledger/hypotheses.json"
|
|
107
|
+
echo "ledger=yes" >> "$GITHUB_OUTPUT"
|
|
108
|
+
fi
|
|
109
|
+
exit "$result"
|
|
110
|
+
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
|
111
|
+
if: always() && steps.scan.outputs.ledger == 'yes'
|
|
112
|
+
with:
|
|
113
|
+
name: bravos-replay-ledger
|
|
114
|
+
path: ${{ runner.temp }}/bravos-verified-ledger/hypotheses.json
|
|
115
|
+
retention-days: 1
|
|
28
116
|
annotate:
|
|
117
|
+
needs: replay
|
|
118
|
+
if: always() && !cancelled() && github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
|
|
29
119
|
runs-on: ubuntu-latest
|
|
30
120
|
env:
|
|
31
121
|
BRAVOS_LICENCE: ${{ secrets.BRAVOS_LICENCE }}
|
|
@@ -42,8 +132,18 @@ jobs:
|
|
|
42
132
|
with:
|
|
43
133
|
node-version: 22
|
|
44
134
|
|
|
45
|
-
- name: Install
|
|
46
|
-
|
|
135
|
+
- name: Install annotation tools
|
|
136
|
+
if: needs.replay.outputs.drafts != 'yes'
|
|
137
|
+
run: bash .bravos/hooks/lib/nightly-tools.sh annotate
|
|
138
|
+
- uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
|
|
139
|
+
if: needs.replay.outputs.drafts == 'yes'
|
|
140
|
+
with:
|
|
141
|
+
path: ${{ runner.temp }}/bravos-cxg
|
|
142
|
+
# The authoring job's own key: whatever its agent leaves here is never restored by the replay job.
|
|
143
|
+
key: bravos-cxg-author-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('.bravos/hooks/lib/proof-tool-pins.json') }}
|
|
144
|
+
- name: Install in-session translation and probe validation
|
|
145
|
+
if: needs.replay.outputs.drafts == 'yes'
|
|
146
|
+
run: bash .bravos/hooks/lib/nightly-tools.sh author
|
|
47
147
|
|
|
48
148
|
- name: Starting point
|
|
49
149
|
id: start
|
|
@@ -64,7 +164,12 @@ jobs:
|
|
|
64
164
|
the work in this session and never run guardlink annotate with an agent flag. Stop when
|
|
65
165
|
`guardlink lint . --since ${{ steps.start.outputs.sha }} --json` reports 0 errors and
|
|
66
166
|
`guardlink validate .` passes. Leave the changes uncommitted; a later step commits them
|
|
67
|
-
and opens the pull request.
|
|
167
|
+
and opens the pull request. Draft kits this run: ${{ needs.replay.outputs.drafts }}.
|
|
168
|
+
Only when yes, for each newly testable exposure use the GuardLink translate method
|
|
169
|
+
in this session to author or update one scoped JavaScript probe under .guardlink/cxg-replay/,
|
|
170
|
+
validate it with the installed CXG validator and run the Bravos replay bind helper on that kit.
|
|
171
|
+
Also repair existing kits with missing or stale bindings after verifying their behaviour and source.
|
|
172
|
+
Do not start a target or run a probe. The separate replay job uses reviewed kits after merge.
|
|
68
173
|
|
|
69
174
|
- name: Gate what the agent wrote
|
|
70
175
|
env:
|
|
@@ -79,71 +184,26 @@ jobs:
|
|
|
79
184
|
exit 1
|
|
80
185
|
fi
|
|
81
186
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
env:
|
|
89
|
-
TARGET: ${{ vars.BRAVOS_SCAN_TARGET }}
|
|
90
|
-
APP_START: ${{ vars.BRAVOS_APP_START }}
|
|
91
|
-
AUTH_PROFILE: ${{ vars.BRAVOS_SCAN_AUTH }}
|
|
92
|
-
AUTH_STATE: ${{ secrets.BRAVOS_AUTH_STATE }}
|
|
93
|
-
run: |
|
|
94
|
-
skip() { echo "::notice::nightly scan skipped: $1"; echo "ran=false" >> "$GITHUB_OUTPUT"; exit 0; }
|
|
95
|
-
scope=.guardlink/scope.yaml
|
|
96
|
-
[ -n "$TARGET" ] || skip "vars.BRAVOS_SCAN_TARGET is not set"
|
|
97
|
-
[ -f "$scope" ] || skip "$scope is not committed"
|
|
98
|
-
attest=$(sed -n 's/^authorization_attestation:[[:space:]]*//p' "$scope" | sed 's/^"\(.*\)"$/\1/')
|
|
99
|
-
[ -n "$attest" ] || skip "$scope has no authorization_attestation; a human must write it and get it reviewed"
|
|
100
|
-
ls .guardlink/cxg-replay/*.js >/dev/null 2>&1 || skip "no retest kits in .guardlink/cxg-replay/"
|
|
101
|
-
host=$(printf '%s' "$TARGET" | sed -E 's#^[a-z]+://##; s#[:/].*$##')
|
|
102
|
-
case "$host" in
|
|
103
|
-
127.0.0.1|localhost|::1|'[::1]') loopback=yes ;;
|
|
104
|
-
*) loopback=no ;;
|
|
105
|
-
esac
|
|
106
|
-
if [ "$loopback" = no ] && ! grep -qF "$host" <(sed -n '/^host_allowlist:/,/^[a-z_]*:/p' "$scope"); then
|
|
107
|
-
skip "$host is neither loopback nor in the scope's host_allowlist"
|
|
108
|
-
fi
|
|
109
|
-
if [ "$loopback" = yes ]; then
|
|
110
|
-
[ -n "$APP_START" ] || skip "a loopback target needs vars.BRAVOS_APP_START to start the app"
|
|
111
|
-
bash -c "$APP_START"
|
|
112
|
-
for i in $(seq 1 60); do curl -fsS -o /dev/null "$TARGET" && break; sleep 2; done
|
|
113
|
-
fi
|
|
114
|
-
cargo install --locked cert-x-gen
|
|
115
|
-
cxg pentest install
|
|
116
|
-
auth=()
|
|
117
|
-
if [ -n "$AUTH_PROFILE" ]; then
|
|
118
|
-
[ -n "$AUTH_STATE" ] || skip "vars.BRAVOS_SCAN_AUTH is set but secrets.BRAVOS_AUTH_STATE is empty"
|
|
119
|
-
printf '%s' "$AUTH_STATE" | base64 -d > "$RUNNER_TEMP/state.json"
|
|
120
|
-
cxg pentest auth import --storage-state "$RUNNER_TEMP/state.json" --profile "$AUTH_PROFILE" --target "$TARGET"
|
|
121
|
-
auth=(--auth "$AUTH_PROFILE")
|
|
122
|
-
fi
|
|
123
|
-
guardlink sarif . --profile pentest -o whitebox/findings.sarif
|
|
124
|
-
run=".guardlink/pentest-findings/nightly-$(date -u +%Y%m%d)"
|
|
125
|
-
set +e
|
|
126
|
-
cxg pentest run --codebase . --target "$TARGET" "${auth[@]}" --template-dir .guardlink/cxg-replay/ --scope-file "$scope" --attestation "$attest" --session-dir "$run" --ci
|
|
127
|
-
code=$?
|
|
128
|
-
set -e
|
|
129
|
-
echo "exit=$code" >> "$GITHUB_OUTPUT"
|
|
130
|
-
case "$code" in
|
|
131
|
-
0|2) guardlink hypothesis confirm --from-scan "$run/report.json" --write || true
|
|
132
|
-
echo "ran=true" >> "$GITHUB_OUTPUT" ;;
|
|
133
|
-
*) echo "::warning::cxg pentest run exited $code: nothing was proven"; echo "ran=false" >> "$GITHUB_OUTPUT" ;;
|
|
134
|
-
esac
|
|
187
|
+
- name: Collect verified replay ledger
|
|
188
|
+
if: needs.replay.outputs.ledger == 'yes'
|
|
189
|
+
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
|
|
190
|
+
with:
|
|
191
|
+
name: bravos-replay-ledger
|
|
192
|
+
path: ${{ runner.temp }}/bravos-verified-ledger
|
|
135
193
|
|
|
136
194
|
- name: Open the pull request
|
|
137
195
|
env:
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
SCAN_TARGET: ${{ vars.BRAVOS_SCAN_TARGET }}
|
|
196
|
+
LEDGER: ${{ needs.replay.outputs.ledger }}
|
|
197
|
+
PROOF_SUMMARY: ${{ needs.replay.outputs.summary || 'No completed replay summary. Check the replay job.' }}
|
|
141
198
|
GH_TOKEN: ${{ github.token }}
|
|
142
199
|
START: ${{ steps.start.outputs.sha }}
|
|
143
200
|
BEFORE: ${{ steps.start.outputs.coverage }}
|
|
144
201
|
run: |
|
|
145
|
-
|
|
146
|
-
|
|
202
|
+
# Load the staging helper and verified ledger from trusted inputs after the agent exits.
|
|
203
|
+
git show "$START:.bravos/hooks/lib/nightly-stage.mjs" > "$RUNNER_TEMP/nightly-stage.mjs"
|
|
204
|
+
node "$RUNNER_TEMP/nightly-stage.mjs"
|
|
205
|
+
if git diff --cached --quiet; then
|
|
206
|
+
echo "No reviewable changes."
|
|
147
207
|
exit 0
|
|
148
208
|
fi
|
|
149
209
|
guardlink ci -f json > "$RUNNER_TEMP/ci-after.json" || true
|
|
@@ -152,20 +212,17 @@ jobs:
|
|
|
152
212
|
branch="bravos/nightly-$(date -u +%Y%m%d-%H%M)"
|
|
153
213
|
git config user.name "bravos-nightly[bot]"
|
|
154
214
|
git config user.email "bravos-nightly@users.noreply.github.com"
|
|
155
|
-
git
|
|
156
|
-
git
|
|
157
|
-
git
|
|
158
|
-
git
|
|
215
|
+
test "$(git rev-parse HEAD)" = "$START"
|
|
216
|
+
test "$(git ls-remote --exit-code origin "refs/heads/$base" | cut -f1)" = "$START"
|
|
217
|
+
tree=$(git write-tree)
|
|
218
|
+
commit=$(git commit-tree "$tree" -p "$START" -m "annotate: nightly coverage slice (${BEFORE}% -> ${after}%)")
|
|
219
|
+
git -c core.hooksPath=/dev/null push origin "$commit:refs/heads/$branch"
|
|
159
220
|
{
|
|
160
221
|
echo "Nightly coverage slice by bravos-annotate: ${BEFORE}% -> ${after}%."
|
|
161
222
|
echo
|
|
162
223
|
echo "## Security gate"
|
|
163
224
|
echo "validate ✔ · lint 0 errors · exposures recorded by this slice are listed below and stay open"
|
|
164
|
-
|
|
165
|
-
echo "Tested: retest kits replayed against $SCAN_TARGET (exit code $SCAN_EXIT); outcomes recorded in .guardlink/hypotheses.json."
|
|
166
|
-
else
|
|
167
|
-
echo "Not tested: the gated scan did not run (see the job's notices)."
|
|
168
|
-
fi
|
|
225
|
+
echo "$PROOF_SUMMARY"
|
|
169
226
|
echo
|
|
170
227
|
guardlink diff "$START" --markdown || true
|
|
171
228
|
} > "$RUNNER_TEMP/body.md"
|
|
@@ -41,7 +41,7 @@ jobs:
|
|
|
41
41
|
BASE_REF: ${{ github.base_ref }}
|
|
42
42
|
run: echo "sha=$(git merge-base HEAD "origin/$BASE_REF")" >> "$GITHUB_OUTPUT"
|
|
43
43
|
|
|
44
|
-
# Whole-token id matching
|
|
44
|
+
# Whole-token id matching for PR-body disclosures: `#api` is not `#api-key`.
|
|
45
45
|
- name: jq helpers
|
|
46
46
|
run: |
|
|
47
47
|
cat > "$RUNNER_TEMP/named.jq" <<'EOF'
|
|
@@ -109,23 +109,97 @@ jobs:
|
|
|
109
109
|
echo "::error::unknown: guardlink ci -f json did not produce guardlink.ci JSON with confirmed[]"
|
|
110
110
|
exit 1
|
|
111
111
|
fi
|
|
112
|
-
git diff --name-only "$BASE_SHA"...HEAD > changed.
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
112
|
+
git diff --name-only -z "$BASE_SHA"...HEAD | jq -Rs 'split("\u0000")' > "$RUNNER_TEMP/bravos-changed.json"
|
|
113
|
+
ledger_claims="$RUNNER_TEMP/bravos-ledger-claims.json"
|
|
114
|
+
echo '[]' > "$ledger_claims"
|
|
115
|
+
if [[ -e .guardlink/hypotheses.json ]]; then
|
|
116
|
+
guardlink hypothesis list --json > "$RUNNER_TEMP/bravos-ledger.json"
|
|
117
|
+
jq -e '.ledger == "present" and (.records | type == "array")' "$RUNNER_TEMP/bravos-ledger.json" >/dev/null || {
|
|
118
|
+
echo "::error::unknown: GuardLink hypothesis ledger unreadable"; exit 1;
|
|
119
|
+
}
|
|
120
|
+
jq '[.records[] | select((.state == "confirmed" or .state == "retest") and .outcome.outcome == "confirmed")]' \
|
|
121
|
+
"$RUNNER_TEMP/bravos-ledger.json" > "$RUNNER_TEMP/bravos-tested.json"
|
|
122
|
+
if jq -e 'length>0' "$RUNNER_TEMP/bravos-tested.json" >/dev/null; then
|
|
123
|
+
guardlink parse . > "$RUNNER_TEMP/bravos-model.json"
|
|
124
|
+
jq --slurpfile tested "$RUNNER_TEMP/bravos-tested.json" '
|
|
125
|
+
.exposures as $model | [$tested[0][] as $r | [$model[] |
|
|
126
|
+
select(.asset == $r.asset and .threat == $r.threat and
|
|
127
|
+
(.location.origin_file // .location.file) == $r.file and (.location.origin_line // .location.line) == $r.line)] |
|
|
128
|
+
if length != 1 or ($r.key | type) != "string" then error("unresolved tested claim")
|
|
129
|
+
else .[0] + {status: (if $r.expired or $r.state == "retest" then "retest due on changed code"
|
|
130
|
+
elif $r.outcome.source.kind == "scan" and $r.outcome.source.joined_by != "claim-key" then "scan association needs review"
|
|
131
|
+
else "confirmed in ledger" end)} end]
|
|
132
|
+
' "$RUNNER_TEMP/bravos-model.json" > "$ledger_claims"
|
|
120
133
|
fi
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
134
|
+
fi
|
|
135
|
+
jq --slurpfile changed "$RUNNER_TEMP/bravos-changed.json" --slurpfile ledger "$ledger_claims" '
|
|
136
|
+
[(.confirmed + $ledger[0])[] | . as $c | select(any($changed[0][]; . != "" and (. == $c.location.file or . == $c.location.origin_file)))] as $rows |
|
|
137
|
+
[$rows[] | . as $c | select(.status != null or (any($rows[]; .status != null and
|
|
138
|
+
.location.file == $c.location.file and .asset == $c.asset and .threat == $c.threat and
|
|
139
|
+
(.location.line == $c.location.line or (.location.anchor.scope == "symbol" and $c.location.anchor.scope == "symbol" and
|
|
140
|
+
.location.anchor.start_line == $c.location.anchor.start_line and .location.anchor.hash == $c.location.anchor.hash))) | not))]
|
|
141
|
+
' ci.json > "$RUNNER_TEMP/bravos-affected.json"
|
|
142
|
+
if ! jq -e 'length > 0' "$RUNNER_TEMP/bravos-affected.json" > /dev/null; then exit 0; fi
|
|
143
|
+
if ! guardlink lookup tickets > "$RUNNER_TEMP/bravos-tickets.json" ||
|
|
144
|
+
! jq -e '.type == "tickets" and (.results | type == "array")' "$RUNNER_TEMP/bravos-tickets.json" > /dev/null; then
|
|
145
|
+
echo "::error::unknown: guardlink lookup tickets failed or returned no ticket list"
|
|
146
|
+
exit 1
|
|
147
|
+
fi
|
|
148
|
+
jq --slurpfile t "$RUNNER_TEMP/bravos-tickets.json" '
|
|
149
|
+
map(. as $c | . + {ticketed: any($t[0].results[];
|
|
150
|
+
.file == $c.location.file and .threat == $c.threat and .asset == $c.asset and
|
|
151
|
+
(.ref | strings | test("\\S")))})
|
|
152
|
+
' "$RUNNER_TEMP/bravos-affected.json" > "$RUNNER_TEMP/bravos-classified.json"
|
|
153
|
+
jq -r '.[] | select(.ticketed and .status) |
|
|
154
|
+
" " + ([.threat, .asset, .location.file, .location.line, .status, "tracked by @ticket"] | tojson)
|
|
155
|
+
' "$RUNNER_TEMP/bravos-classified.json" >> "$GITHUB_STEP_SUMMARY"
|
|
156
|
+
jq -r '.[] | select(.ticketed|not) |
|
|
157
|
+
"\(.severity // "unrated") \(.threat) on \(.asset) — \(.location.file):\(.location.line) [\(.status // "source @confirmed")]"
|
|
158
|
+
' "$RUNNER_TEMP/bravos-classified.json" > "$RUNNER_TEMP/bravos-unticketed.txt"
|
|
159
|
+
if [ -s "$RUNNER_TEMP/bravos-unticketed.txt" ]; then
|
|
160
|
+
echo "::error::Confirmed claims or unresolved retests on changed source have no matching @ticket:"
|
|
161
|
+
cat "$RUNNER_TEMP/bravos-unticketed.txt"
|
|
126
162
|
exit 1
|
|
127
163
|
fi
|
|
128
164
|
|
|
165
|
+
- name: Changed source to review
|
|
166
|
+
if: always() && steps.base.outcome == 'success'
|
|
167
|
+
continue-on-error: true
|
|
168
|
+
env:
|
|
169
|
+
BASE_SHA: ${{ steps.base.outputs.sha }}
|
|
170
|
+
run: |
|
|
171
|
+
# Read the PR as data. The advisory executes Git and GuardLink, never the branch's scripts.
|
|
172
|
+
scope="$RUNNER_TEMP/bravos-source-scope.json"
|
|
173
|
+
if ! guardlink unannotated --json > "$scope" || ! jq -e '(.annotated|type=="array") and (.worklist|type=="array")' "$scope" >/dev/null; then
|
|
174
|
+
echo 'Changed-source review unavailable: GuardLink did not return its source worklist.' >> "$GITHUB_STEP_SUMMARY"; exit 0
|
|
175
|
+
fi
|
|
176
|
+
git diff --no-renames --name-only --diff-filter=AMT -z "$BASE_SHA" HEAD > "$RUNNER_TEMP/bravos-pr-paths"
|
|
177
|
+
summary="$RUNNER_TEMP/bravos-source-review"
|
|
178
|
+
: > "$summary"
|
|
179
|
+
count=0
|
|
180
|
+
jq -Rs --slurpfile scope "$scope" '
|
|
181
|
+
($scope[0].annotated | INDEX(.)) as $known | ($scope[0].worklist | INDEX(.path)) as $missing |
|
|
182
|
+
[split("\u0000")[] | select(length>0) | . as $f |
|
|
183
|
+
if $known[$f] then [$f,"file already has annotations"]
|
|
184
|
+
elif $missing[$f] then [$f,"no file annotations"] else empty end]
|
|
185
|
+
' "$RUNNER_TEMP/bravos-pr-paths" > "$RUNNER_TEMP/bravos-in-scope.json"
|
|
186
|
+
count=$(jq length "$RUNNER_TEMP/bravos-in-scope.json")
|
|
187
|
+
while IFS= read -r -d '' file && IFS= read -r -d '' status; do
|
|
188
|
+
ranges=$(git --literal-pathspecs diff --no-ext-diff --no-textconv --no-renames --no-color --unified=0 "$BASE_SHA" HEAD -- "$file" |
|
|
189
|
+
awk '/^@@ / {split($3,x,","); s=substr(x[1],2)+0; if(s<1)s=1; n=x[2]+0; if(++h<=8) printf "%s%s", (h==1 ? "" : ","), (n>1 ? s "-" (s+n-1) : s)} END{if(h>8)printf ",…"; if(!h) printf "whole file"}')
|
|
190
|
+
# Indented code in the summary keeps filenames inert, even when they contain Markdown or newlines.
|
|
191
|
+
jq -nr --arg f "$file" --arg r "$ranges" --arg s "$status" '" " + ($f|tojson) + ":" + $r + " — " + $s' >> "$summary"
|
|
192
|
+
done < <(jq -j '.[:24][] | .[] + "\u0000"' "$RUNNER_TEMP/bravos-in-scope.json")
|
|
193
|
+
removed=$(git diff --no-renames --name-only --diff-filter=D -z "$BASE_SHA" HEAD | jq -Rs 'split("\u0000")|map(select(length>0))|length')
|
|
194
|
+
{
|
|
195
|
+
echo "Changed source to review ($count in-scope files). Inspect the ranges for new or changed entry points, controls and sinks."
|
|
196
|
+
echo
|
|
197
|
+
cat "$summary"
|
|
198
|
+
if ((removed>0)); then echo "$removed deleted path(s) are outside the current-file worklist; review their prior controls and callers."; fi
|
|
199
|
+
if ((count>24)); then echo "$((count-24)) further changed files omitted."; fi
|
|
200
|
+
if ((count>0)); then echo "For graph-derived annotation gaps on the review checkout, run \`bravos graph annotation-gaps --base $BASE_SHA --json\`."; fi
|
|
201
|
+
} >> "$GITHUB_STEP_SUMMARY"
|
|
202
|
+
|
|
129
203
|
- name: Undefended paths (informational)
|
|
130
204
|
continue-on-error: true
|
|
131
205
|
run: guardlink paths --json > paths.json
|