mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
A PR from a fork keeps a GitHub-hosted machine: pull_request_target starts for any PR without approval. The DOCS blob step wrote files by the paths a PR's tree names, which git does not check when it prints a diff; a crafted tree with '..' entries wrote outside the workspace. The step is now a script that refuses such a path before any write, and both jobs fetch the PR head with fetch.fsckObjects=true. spec trace sets up Go for sametokens.go, which a self-hosted runner does not have on its PATH. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
30 lines
1.1 KiB
Bash
30 lines
1.1 KiB
Bash
#!/usr/bin/env bash
|
|
# Writes the old and new blob of each changed non-test Go file between two
|
|
# commits under <out>/old/<path> and <out>/new/<path>, for the spec trace's
|
|
# kind DOCS (objects only; nothing from the PR is built or run).
|
|
#
|
|
# usage: changed-go-blobs.sh <merge-base> <head> <out>
|
|
#
|
|
# The paths come from the PR's tree objects, which git does not check when it
|
|
# prints a diff. A path that is absolute or has an empty, '.' or '..'
|
|
# component would write outside <out>, so it is refused before anything is
|
|
# written (exit 1).
|
|
set -euo pipefail
|
|
mb=$1 head=$2 out=$3
|
|
mkdir -p "$out"
|
|
git diff --name-only --no-renames -z "$mb" "$head" -- "*.go" ":(exclude)*_test.go" >"$out/.paths"
|
|
while IFS= read -r -d "" p; do
|
|
case "/$p/" in
|
|
*//* | */./* | */../*)
|
|
printf 'changed-go-blobs: refusing path %q\n' "$p" >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
done <"$out/.paths"
|
|
while IFS= read -r -d "" p; do
|
|
mkdir -p "$out/old/$(dirname "$p")" "$out/new/$(dirname "$p")"
|
|
git show "$mb:$p" >"$out/old/$p" 2>/dev/null || rm -f "$out/old/$p"
|
|
git show "$head:$p" >"$out/new/$p" 2>/dev/null || rm -f "$out/new/$p"
|
|
done <"$out/.paths"
|
|
rm -f "$out/.paths"
|