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

+49 -12
View File
@@ -331,25 +331,51 @@ norm_path() {
printf '%s' "${path%/}"
}
# identity <plugin dir> — <host>/<owner>/<repo>/<path> from root apm.yml's
# git+path dependency entry for plugins/<plugin dir>; empty when it has none.
identity() {
# dep_url <plugin dir> — the git: URL of root apm.yml's git+path dependency
# entry for plugins/<plugin dir>; empty when it has none.
dep_url() {
local want="plugins/$1" tag path url
while IFS=$'\t' read -r tag path url; do
[[ "$tag" == d && "$(norm_path "$path")" == "$want" ]] || continue
if [[ "$url" == *://* ]]; then
url="${url#*://}"
elif [[ "$url" == *:* ]]; then
url="${url/://}" # scp-like user@host:owner/repo
fi
url="${url#*@}"
url="${url%/}"
url="${url%.git}"
printf '%s/%s' "$url" "$want"
printf '%s' "$url"
return
done <<< "$FACTS"
}
# url_has_port <url> — true when a scheme URL names a port (host:port).
url_has_port() {
local rest
[[ "$1" == *://* ]] || return 1
rest="${1#*://}"
rest="${rest%%/*}"
rest="${rest#*@}"
[[ "$rest" == *:* ]]
}
# identity <plugin dir> — <host>/<owner>/<repo>/<path> from that entry; empty
# when there is none.
#
# Verified against apm 0.39.3 (`apm approve --list`) for an https URL on a
# lowercase host only. The scp-like (user@host:owner/repo) and ssh:// forms are
# derived by the same rule but were not checked against apm, and the host's
# case is kept as written, also unchecked. A URL with a port is refused before
# this runs (see the per-package checks): where apm puts a port in the
# identity is unknown, so a derived key could be wrong while looking right.
identity() {
local want="plugins/$1" url
url="$(dep_url "$1")"
[[ -n "$url" ]] || return 0
if [[ "$url" == *://* ]]; then
url="${url#*://}"
elif [[ "$url" == *:* ]]; then
url="${url/://}" # scp-like user@host:owner/repo
fi
url="${url#*@}"
url="${url%/}"
url="${url%.git}"
printf '%s/%s' "$url" "$want"
}
# expected_key <plugin dir> — '<identity>#<version>'.
expected_key() {
printf '%s#%s' "$(identity "$1")" "$(fact v "$1")"
@@ -404,6 +430,17 @@ for plugin in ${READABLE[@]+"${READABLE[@]}"}; do
continue
fi
if url_has_port "$(dep_url "$plugin")"; then
echo "FAIL: root apm.yml's dependency entry for plugins/$plugin uses a git: URL with a port," >&2
echo " '$(dep_url "$plugin")', so its executables.allow key cannot be derived reliably." >&2
echo " Why: this gate derives the full package identity apm 0.39 approves under from that URL," >&2
echo " and how apm writes a port into the identity was never verified." >&2
echo " Fix: use the URL without a port if the host allows it; otherwise read the identity from" >&2
echo " 'uv run --frozen apm approve --list' and extend this check to match it." >&2
FAILED=1
continue
fi
EXPECTED+=("$plugin")
done