fix(scripts): refuse a dependency URL with a port in the allow-sync gate

How apm 0.39 writes a port into a package identity is unverified, so a
key derived from a git: URL with a port could be wrong while looking
right. The gate now fails clearly on one, naming `apm approve --list` as
the way to read the real identity. The script and gates.md record that
only an https URL on a lowercase host was checked against apm.

The test drops its GNU-only `sed -i` for a python3 rewrite, and covers
ssh:// and https URLs with a port under both readers.

Refs: #271

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
This commit is contained in:
Defame1297andClaude Opus 5.5 committed 2026-12-02 09:47:38 +00:00
1 parent 615d3dd881
commit dca0b5823b
3 files changed
+81 -14

No files matched your search

+28 -1
View File
@@ -316,7 +316,13 @@ grep -qF "full package identity" <<< "$OUT" && pass "says why a bare key no long
# No git+path dependency entry for the plugin means no identity to derive.
F="$(make_fixture "version: 1.5.0" "$MATCHING_BLOCK")"
sed -i '/path: plugins\/kyberforge/d' "$F/apm.yml"
# python3, not `sed -i`, whose in-place syntax differs between GNU and BSD sed.
python3 - "$F/apm.yml" << 'PY2'
import sys
path = sys.argv[1]
lines = open(path).read().splitlines(keepends=True)
open(path, "w").write("".join(l for l in lines if "path: plugins/kyberforge" not in l))
PY2
run_gate "$F"
[[ $GATE_RC -ne 0 ]] && pass "fails when root apm.yml has no git+path entry for the plugin" \
|| fail "with no dependency entry the identity cannot be derived; must fail"
@@ -416,6 +422,27 @@ F="$(make_fixture "version: 1.5.0" "$BARE_BLOCK")"
run_fallback "$F"
[[ $GATE_RC -ne 0 ]] && pass "fallback fails a bare key" || fail "fallback missed a bare key"
# A URL with a port: where apm puts the port in the identity is unverified, so
# the gate refuses to derive a key rather than derive a plausible wrong one.
for port_url in "ssh://[email protected]:2222/Owner/Repo.git" "https://git.example.invalid:8443/Owner/Repo.git"; do
F="$(make_fixture "version: 1.5.0" "$MATCHING_BLOCK")"
python3 - "$F/apm.yml" "$port_url" << 'PY2'
import sys
path, url = sys.argv[1], sys.argv[2]
text = open(path).read()
old = " - git: https://git.example.invalid/Owner/Repo.git\n path: plugins/kyberforge\n"
assert old in text
open(path, "w").write(text.replace(old, " - git: %s\n path: plugins/kyberforge\n" % url))
PY2
OUT="$(bash "$SCRIPT" "$F" 2>&1)" && rc=0 || rc=$?
[[ $rc -ne 0 ]] && grep -qF "URL with a port" <<< "$OUT" \
&& pass "refuses a git: URL with a port: $port_url" \
|| fail "a URL with a port must fail clearly ($port_url), got rc=$rc: $OUT"
run_fallback "$F"
[[ $GATE_RC -ne 0 ]] && pass "fallback refuses a git: URL with a port: $port_url" \
|| fail "fallback must refuse a URL with a port ($port_url)"
done
# ---------------------------------------------------------------------------
echo ""
echo "--- wired into the pre-push gate ---"