Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- Fix the `Privacy Guard` denylist check: validate patterns with the same `git grep -iE` engine that scans them, reject PCRE-only escapes, normalize CRLF and blank private lines, and report an invalid pattern by source and line only. Mirrors vllnt/skills.

- Accept the reviewed Skills update from `352eaf7b167a6761161415711ef9d55db26d91d6` to `7483dd4dfd8502fd2db376c13e44fa0cbc464161` as `0.1.0-canary.8` through a separate protected PR, because the range changes sensitive paths. Adds the `@vllnt/convex-api-keys`, `@vllnt/logger` and `@vllnt/analytics` defaults, marks `@vllnt/ui-core` and `@vllnt/ui-native` experimental opt-in, and moves `@vllnt/dig` to not yet default. The automatic sensitivity policy is unchanged.

- Accept the reviewed Skills update from `472c216f2f043f0add1f83540cc46ea53d20a7cd` to `352eaf7b167a6761161415711ef9d55db26d91d6` as `0.1.0-canary.7` through a separate protected PR, because the range changes sensitive paths. Includes the published `@vllnt/*` package defaults annex and new direct improvement, session-refocusing, and full-environment PR testing workflows. The automatic sensitivity policy is unchanged.
Expand Down
54 changes: 38 additions & 16 deletions scripts/privacy-denylist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,56 @@ SELF=scripts/privacy-denylist.sh

tracked="$(mktemp)"
extra="$(mktemp)"
local_raw="$(mktemp)"
extra_raw="$(mktemp)"
patterns="$(mktemp)"
allow_patterns="$(mktemp)"
hits="$(mktemp)"
kept="$(mktemp)"
trap 'rm -f "$tracked" "$extra" "$patterns" "$allow_patterns" "$hits" "$kept"' EXIT
probe="$(mktemp -d)"
trap 'rm -f "$tracked" "$extra" "$local_raw" "$extra_raw" "$patterns" "$allow_patterns" "$hits" "$kept"; rm -rf "$probe"' EXIT
printf '\n' > "$probe/empty"
printf 'a b\n' > "$probe/text"

strip() { sed -E '/^[[:space:]]*(#|$)/d'; }
strip() { tr -d '\r' | sed -E '/^[[:space:]]*(#|$)/d'; }
# lines <file>: the file with a guaranteed final newline.
lines() { cat "$1"; printf '\n'; }

# valid_regexes <file> <label>: every line must compile and must not match the empty string.
# Probes run a pattern with the engine and flags that later use it: git grep -iE for
# the denylist scan, grep -E for the allowlist filter. The two dialects differ.
# deny_probe/allow_probe <flag> <pattern> <probe file>
deny_probe() { (cd "$probe" && git grep --no-index -h -iE "$1" -e "$2" -- "$3" 2> /dev/null); }
allow_probe() { grep -E "$1" -e "$2" -- "$probe/$3" 2> /dev/null; }

# A backslash before a letter or 0, other than \b \B \s \S \w \W, is a PCRE-style
# escape (\d, \x41, \Q, \p{L}) that extended regex silently misreads.
UNSUPPORTED_ESCAPE='(^|[^\])(\\\\)*\\[AC-RT-VX-Zac-rt-vx-z0]'

# valid_regexes <file> <source> <probe>: every pattern line must compile with its
# engine and must not match the empty string. Errors name the source and line only.
valid_regexes() {
local file="$1" label="$2" n=0 line status probe
local file="$1" source="$2" probe_with="$3" n=0 line status
while IFS= read -r line || [[ -n "$line" ]]; do
n=$((n + 1))
printf '\n' | grep -qE -e "$line" 2> /dev/null
line="${line//$'\r'/}"
[[ "$line" =~ ^[[:space:]]*(#|$) ]] && continue
if [[ "$line" =~ $UNSUPPORTED_ESCAPE ]]; then
echo "error: $source pattern line $n uses an escape extended regex does not support" >&2
return 1
fi
"$probe_with" -q "$line" empty
status=$?
if (( status > 1 )); then
echo "error: $label pattern #$n is not a valid regex" >&2
echo "error: $source pattern line $n is not a valid regex" >&2
return 1
fi
if (( status == 0 )); then
echo "error: $label pattern #$n matches the empty string" >&2
echo "error: $source pattern line $n matches the empty string" >&2
return 1
fi
# Zero-width patterns (\b, ^, $) match inside real text but report nothing.
probe="$(printf 'a b\n' | grep -oE -e "$line" 2> /dev/null)"
if [[ -z "$probe" ]] && printf 'a b\n' | grep -qE -e "$line" 2> /dev/null; then
echo "error: $label pattern #$n is zero-width" >&2
if [[ -z "$("$probe_with" -o "$line" text)" ]] && "$probe_with" -q "$line" text; then
echo "error: $source pattern line $n is zero-width" >&2
return 1
fi
done < "$file"
Expand All @@ -67,20 +88,21 @@ if [[ ! -f "$DENY" ]]; then
echo "error: $DENY is required" >&2
exit 2
fi
[[ -f "$DENY.local" ]] && cat "$DENY.local" > "$local_raw"
[[ -n "${PRIVACY_DENYLIST_EXTRA:-}" ]] && printf '%s\n' "$PRIVACY_DENYLIST_EXTRA" > "$extra_raw"
lines "$DENY" | strip > "$tracked"
{
[[ -f "$DENY.local" ]] && lines "$DENY.local"
[[ -n "${PRIVACY_DENYLIST_EXTRA:-}" ]] && printf '%s\n' "$PRIVACY_DENYLIST_EXTRA"
} | strip > "$extra"
{ lines "$local_raw"; lines "$extra_raw"; } | strip > "$extra"
cat "$tracked" "$extra" > "$patterns"
[[ -f "$ALLOW" ]] && lines "$ALLOW" | strip > "$allow_patterns"

if [[ ! -s "$tracked" ]]; then
echo "error: $DENY has no patterns" >&2
exit 2
fi
valid_regexes "$patterns" "denylist" || exit 2
valid_regexes "$allow_patterns" "allowlist" || exit 2
valid_regexes "$DENY" "tracked" deny_probe || exit 2
valid_regexes "$local_raw" "local" deny_probe || exit 2
valid_regexes "$extra_raw" "extra" deny_probe || exit 2
[[ -f "$ALLOW" ]] && { valid_regexes "$ALLOW" "allowlist" allow_probe || exit 2; }
if [[ -s "$allow_patterns" ]] && [[ -z "$(printf '%s\n' 'zz/canary.md:1:canary.ts''.net' | grep -avEf "$allow_patterns")" ]]; then
echo "error: allowlist is too broad; it would hide an obvious match" >&2
exit 2
Expand Down
15 changes: 15 additions & 0 deletions scripts/test-privacy-denylist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,21 @@ check "invalid private pattern is an error" 2 'PRIVACY_DENYLIST_EXTRA=Acme[Corp'
refute "invalid pattern text leaked to output" "Acme"
check "private pattern matching empty string is an error" 2 'PRIVACY_DENYLIST_EXTRA=acme|'

# Constructs that grep -E accepts but git grep -E rejects or silently misreads.
for construct in '(?i)acme' 'acme(?=x)' 'acme(?!x)' '\p{L}acme' 'a{32768}' '\d{3}acme' '\x41acme' '\Qacme\E'; do
check "unsupported construct $construct is an error" 2 "PRIVACY_DENYLIST_EXTRA=$construct"
refute "unsupported construct $construct leaked to output" "acme"
refute "unsupported construct $construct passed validation" "git grep failed"
done
check "invalid private pattern reports its source and line" 2 "PRIVACY_DENYLIST_EXTRA=$(printf 'foo\n\n(?i)acme')"
grep -q 'extra pattern line 3' <<< "$LAST_OUTPUT" || { echo "FAIL invalid pattern source or line not reported" >&2; failures=$((failures + 1)); }
check "escaped backslash before a letter is a literal" 0 'PRIVACY_DENYLIST_EXTRA=acme\\d'
check "supported escapes and alternation pass" 0 'PRIVACY_DENYLIST_EXTRA=\bacme\s+(widget|gadget)\b'

printf 'acme-widget appears here\n' >> "$REPO/doc.md"
check "crlf and blank private lines are normalized" 1 "PRIVACY_DENYLIST_EXTRA=$(printf 'foo\r\n\r\n\nacme-widget\r\n')"
plant "Plain documentation."

cp "$REPO/.privacy-allowlist" "$REPO/allow.bak"
plant "host: $TAILNET"
printf '[unclosed\n' > "$REPO/.privacy-allowlist"
Expand Down
Loading