Skip to content

Commit d9d059c

Browse files
Add public boundary scan
1 parent 4c034c7 commit d9d059c

3 files changed

Lines changed: 118 additions & 0 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Public Boundary
2+
3+
on:
4+
pull_request:
5+
push:
6+
7+
permissions:
8+
contents: read
9+
10+
jobs:
11+
scan:
12+
name: Scan public boundary
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Scan files and commit metadata
21+
shell: bash
22+
run: |
23+
set -euo pipefail
24+
25+
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
26+
range="${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }}"
27+
elif [[ "${{ github.event.before }}" =~ ^0+$ ]]; then
28+
range="${{ github.sha }}^..${{ github.sha }}"
29+
else
30+
range="${{ github.event.before }}..${{ github.sha }}"
31+
fi
32+
33+
PUBLIC_BOUNDARY_GIT_RANGE="$range" scripts/check-public-boundary.sh

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,3 +519,7 @@ The API reference is published to [python.durable-workflow.com](https://python.d
519519
## License
520520

521521
MIT
522+
523+
## Public Boundary Checks
524+
525+
This is a public repository. Do not add private tracker names, workspace-only absolute paths, or internal automation metadata to files or new commit metadata. Run `scripts/check-public-boundary.sh` before publishing changes; CI runs the same scan on pushes and pull requests.

scripts/check-public-boundary.sh

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
root="${1:-.}"
5+
cd "$root"
6+
7+
status=0
8+
9+
pattern_from_hex() {
10+
local hex="$1"
11+
local output=""
12+
local byte
13+
14+
while [[ -n "$hex" ]]; do
15+
byte="${hex:0:2}"
16+
hex="${hex:2}"
17+
output+=$(printf '%b' "\\x$byte")
18+
done
19+
20+
printf '%s' "$output"
21+
}
22+
23+
file_patterns=(
24+
"$(pattern_from_hex 7a6f72706f726174696f6e2f)"
25+
"$(pattern_from_hex 2f686f6d652f7673636f6465)"
26+
"$(pattern_from_hex 2f686f6d652f6c61622f776f726b73706163652d6871)"
27+
)
28+
29+
metadata_patterns=(
30+
"${file_patterns[@]}"
31+
"$(pattern_from_hex 4c6f6f702d49443a)"
32+
"$(pattern_from_hex 2e746d702f6c6f6f70732f)"
33+
"$(pattern_from_hex 6c6f6f702d72756e6e6572)"
34+
)
35+
36+
pathspec=(
37+
.
38+
':!.git'
39+
':!vendor'
40+
':!node_modules'
41+
':!build'
42+
':!dist'
43+
':!coverage'
44+
':!storage'
45+
':!bootstrap/cache'
46+
':!public/build'
47+
':!var'
48+
)
49+
50+
for pattern in "${file_patterns[@]}"; do
51+
while IFS=: read -r file line _; do
52+
[[ -n "${file:-}" ]] || continue
53+
printf 'public-boundary: forbidden file content at %s:%s\n' "$file" "$line" >&2
54+
status=1
55+
done < <(git grep -n -I -e "$pattern" -- "${pathspec[@]}" || true)
56+
done
57+
58+
if [[ -n "${PUBLIC_BOUNDARY_GIT_RANGE:-}" ]]; then
59+
read -r -a rev_args <<< "$PUBLIC_BOUNDARY_GIT_RANGE"
60+
else
61+
rev_args=(-1 HEAD)
62+
fi
63+
64+
if mapfile -t commits < <(git rev-list "${rev_args[@]}" 2>/dev/null); then
65+
for commit in "${commits[@]}"; do
66+
metadata="$(git show -s --format='%an <%ae>%n%s%n%b' "$commit")"
67+
68+
for pattern in "${metadata_patterns[@]}"; do
69+
if grep -Fq -- "$pattern" <<< "$metadata"; then
70+
printf 'public-boundary: forbidden commit metadata at %s\n' "${commit:0:12}" >&2
71+
status=1
72+
break
73+
fi
74+
done
75+
done
76+
else
77+
printf 'public-boundary: unable to inspect commit metadata range: %s\n' "${PUBLIC_BOUNDARY_GIT_RANGE:-HEAD}" >&2
78+
status=1
79+
fi
80+
81+
exit "$status"

0 commit comments

Comments
 (0)