Mirror box-side title validation exactly in the workflow

Address security-review F1/F3: the workflow re-check used a POSIX
[[:cntrl:]] grep (missed the C1 range the box-side sanitizer strips) and
wc -m (byte count, not chars). Replace both with a single python3 check
whose accept condition is byte-for-byte identical to sanitize_pr_title —
rejects [\x00-\x1f\x7f-\x9f] and caps at 70 characters — so the
defense-in-depth re-validation genuinely matches the box path.
This commit is contained in:
Adam Moussa 2026-06-25 13:49:51 -04:00
parent c8a023fcd5
commit e7c5e66d74

View file

@ -1286,16 +1286,17 @@ jobs:
# smuggle newlines/control chars/over-long content into the PR metadata. # smuggle newlines/control chars/over-long content into the PR metadata.
title="$fallback_title" title="$fallback_title"
if [ -n "$PR_TITLE" ]; then if [ -n "$PR_TITLE" ]; then
# Reject any control char (incl. newline/tab/NUL/DEL) or > 70 chars. # Re-validate the box-supplied title as defense-in-depth (§4.6),
# POSIX [[:cntrl:]] under LC_ALL=C (no GNU-only `grep -P`): matches # BYTE-FOR-BYTE identical to agent_team.dispatcher.sanitize_pr_title's
# 0x00-0x1f + 0x7f. C1 (0x80-0x9f) is already stripped box-side by # acceptance test: reject any C0/C1 control char or DEL
# sanitize_pr_title; this is the defense-in-depth re-check (§4.6). # ([\x00-\x1f\x7f-\x9f] — note this DOES cover C1, which a POSIX
if printf '%s' "$PR_TITLE" | LC_ALL=C grep -q '[[:cntrl:]]'; then # [[:cntrl:]] grep misses) and cap at 70 *characters* (not bytes, so a
echo "::warning::pr_title rejected (control chars); using fallback" # multibyte title is not spuriously rejected). python3 is present on
elif [ "$(printf '%s' "$PR_TITLE" | wc -m)" -gt 70 ]; then # the runner; an undecodable/invalid title exits non-zero -> fallback.
echo "::warning::pr_title rejected (too long); using fallback" if printf '%s' "$PR_TITLE" | python3 -c 'import sys, re; t = sys.stdin.read(); sys.exit(0 if t and not re.search(r"[\x00-\x1f\x7f-\x9f]", t) and len(t) <= 70 else 1)'; then
else
title="$PR_TITLE" title="$PR_TITLE"
else
echo "::warning::pr_title rejected (control chars or >70 chars); using fallback"
fi fi
fi fi
# The provenance (task id, diff hash, head) lives in the BODY so the # The provenance (task id, diff hash, head) lives in the BODY so the