Repository navigation
Preview actions: share change-detection script + harden regex/script-injection (#35) - #46
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR consolidates shared “changed lecture detection” logic between the preview-netlify and preview-cloudflare composite actions into a single script, and hardens both PR-comment github-script steps by removing direct interpolation of PR-controlled values into the JS script body.
Changes:
- Extracted shared change-detection into
scripts/detect-changed-lectures.shand wired both preview actions to call it. - Updated both PR-comment steps to pass PR-controlled values via
envand read them fromprocess.env. - Documented the behavior/security changes in
CHANGELOG.md.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| scripts/detect-changed-lectures.sh | New shared bash script for detecting changed lecture Markdown files and _toc.yml location. |
| preview-netlify/action.yml | Replaces inline change-detection with shared script; hardens PR-comment step by using env vars. |
| preview-cloudflare/action.yml | Same as Netlify: shared script + env-based values in PR-comment step. |
| CHANGELOG.md | Records the de-duplication and security hardening under Unreleased. |
mmcky
added a commit
that referenced
this pull request
Jun 16, 2026
The content-change check filtered diff lines with grep -vE '^[+-]{3}' to
drop ---/+++ headers, but that also dropped real content lines starting
with +/- combos (e.g. a markdown '---' front-matter delimiter shows up as
'+---'), so a file changing only such lines was wrongly excluded. Use
git diff --quiet to test for any diff instead. Pre-existing bug carried
over from the original inline logic.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pragmatic de-dup of the two near-identical preview actions: - M9: extract the change-detection logic into a shared scripts/detect-changed-lectures.sh, called by both preview-netlify and preview-cloudflare via "$GITHUB_ACTION_PATH/../scripts/...". The deploy and PR-comment steps stay per-action (netlify CLI vs wrangler, marker emoji). - H7: the shared script matches lectures-dir as a literal path (quoted-glob) instead of injecting it into a regex, so a dir name containing regex metacharacters (., +, ...) no longer misbehaves. - N2 (security): the github-script PR-comment step now receives PR-controlled values (changed file paths, deploy URL) via env and reads them from process.env, instead of interpolating them into the JS body — closing a script-injection vector. (Was gated by the trusted-actor check, but this removes the anti-pattern.) Closes #35 Co-Authored-By: Claude Opus 4.8 <[email protected]>
The content-change check filtered diff lines with grep -vE '^[+-]{3}' to
drop ---/+++ headers, but that also dropped real content lines starting
with +/- combos (e.g. a markdown '---' front-matter delimiter shows up as
'+---'), so a file changing only such lines was wrongly excluded. Use
git diff --quiet to test for any diff instead. Pre-existing bug carried
over from the original inline logic.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
mmcky
force-pushed
the
fix/preview-dedup-harden
branch
from
June 16, 2026 05:43
ccc2a55 to
52d3c81
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #35 (M9, H7, N2) — the pragmatic de-dup we agreed on: extract the genuinely-shared change-detection into one script (fixing H7 once), harden N2 in both comment steps, and leave the bits that legitimately differ (netlify CLI vs wrangler, marker emoji).
M9 — shared change-detection
The ~60 lines of identical change-detection are now
scripts/detect-changed-lectures.sh, called by both actions:Each action drops ~57 lines. The deploy + PR-comment steps stay per-action.
H7 —
lectures-dirtreated as a literal pathThe old check interpolated
lectures-dirinto a bash regex (^${lectures_dir}/.*\.md$). The shared script uses quoted-glob matching, so a dir name with regex metacharacters behaves correctly. Unit-tested:lectures/aiyagari.md,lectures/sub/nested.md→ includedlectures/_static/x.md,lectures/intro.md,lectures/notes.txt,other/foo.md→ skippedlectures-dir: "lec.tures",lecXtures/foo.md→ skipped (the old regex would have wrongly matched the.)N2 (security) — no untrusted data in the script body
The
github-scriptcomment step interpolated PR-controlled values (changed-files= file paths,deploy-url) directly into the JS template, a script-injection vector. They're now passed viaenvand read fromprocess.env:(It was already gated by the trusted-actor check, so exploitation needed repo push access — this removes the anti-pattern regardless.)
Notes / verification
set -e/pipefail, so agrepno-match still yields0like before), plus the H7 fix.bash -nclean; no${{ … }}interpolation remains inside eitherscript:body.github.action_path/requireadds the kind of path indirection we just got bitten by in build-jupyter-cache/publish-gh-pages: relative sibling paths + artifact/release guards #38). That was the "full consolidation" option we set aside.Closes #35
🤖 Generated with Claude Code