appstore-precheck 1.16.0 → 1.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -32,12 +32,61 @@ rule_slug() {
32
32
  47) echo ai-provider-consent ;; 48) echo paywall-urgency ;;
33
33
  49) echo rating-sentiment-gate ;; 50) echo forced-login ;;
34
34
  51) echo push-marketing-optout ;; 52) echo xcode-sdk-requirement ;;
35
+ 53) echo subscription-eula-metadata ;; 54) echo saturated-category ;;
35
36
  *) echo "" ;;
36
37
  esac
37
38
  }
38
39
 
39
40
  _CURRENT_RULE=""
40
- set_rule() { _CURRENT_RULE="$1"; }
41
+ _EVIDENCE_OVERRIDE=""
42
+ _CONFIDENCE_OVERRIDE=""
43
+ # set_rule also clears any per-finding overrides, so a refinement made for one
44
+ # branch can never leak into the next rule.
45
+ set_rule() { _CURRENT_RULE="$1"; _EVIDENCE_OVERRIDE=""; _CONFIDENCE_OVERRIDE=""; }
46
+
47
+ # set_evidence <class> / set_confidence <level> — refine the labels for the NEXT
48
+ # finding(s) of the current rule. A rule-level label is the honest default for the
49
+ # rule as a whole, but individual branches differ: §2 concludes its empty-purpose-
50
+ # string FAIL from Info.plist rather than a source grep (stronger evidence), while
51
+ # its "Info.plist not found" branch is an advisory, not the upload blocker the rule
52
+ # is otherwise about (weaker confidence). Without these, a degraded-read branch
53
+ # would inherit "validator-blocking" and overstate exactly what this layer exists
54
+ # to stop. Both are cleared by the next set_rule; inside a `| while read` subshell
55
+ # they scope themselves automatically.
56
+ set_evidence() { _EVIDENCE_OVERRIDE="$1"; }
57
+ set_confidence() { _CONFIDENCE_OVERRIDE="$1"; }
58
+
59
+ # Resolvers degrade to empty when evidence.sh is not sourced (findings.sh is used
60
+ # standalone in tests), so an unclassified finding is reported as such, never guessed.
61
+ # A SKIP reached no conclusion, so it has no evidence class and no confidence: the
62
+ # rule it sits under (e.g. screenshots-per-locale) would otherwise leak
63
+ # "validator-blocking" onto a line that established nothing. Both resolvers take the
64
+ # severity so they can blank themselves for SKIP.
65
+ _evidence_of() {
66
+ [[ "${1:-}" == "SKIP" ]] && { printf ''; return; }
67
+ [[ -n "$_EVIDENCE_OVERRIDE" ]] && { printf '%s' "$_EVIDENCE_OVERRIDE"; return; }
68
+ command -v rule_evidence >/dev/null 2>&1 && rule_evidence "$_CURRENT_RULE" || printf ''
69
+ }
70
+ _confidence_of() {
71
+ [[ "${1:-}" == "SKIP" ]] && { printf ''; return; }
72
+ [[ -n "$_CONFIDENCE_OVERRIDE" ]] && { printf '%s' "$_CONFIDENCE_OVERRIDE"; return; }
73
+ command -v rule_confidence >/dev/null 2>&1 && rule_confidence "$_CURRENT_RULE" || printf ''
74
+ }
75
+ # _needs_build_of <severity> — the qualifier is a statement about an UNESTABLISHED
76
+ # violation ("this blocks the upload if it ships as-is"), so it is meaningless on a
77
+ # PASS: nothing is being claimed against the build. Evidence and confidence stay on
78
+ # a PASS — they still say how the rule reached its conclusion — but the qualifier
79
+ # does not.
80
+ _needs_build_of() {
81
+ # PASS asserts no violation; SKIP asserts nothing at all. Neither can need a build
82
+ # to confirm a claim it never made.
83
+ case "${1:-}" in PASS|SKIP) printf 'false'; return ;; esac
84
+ command -v needs_build_verification >/dev/null 2>&1 \
85
+ && needs_build_verification "$(_evidence_of)" "$(_confidence_of)" || printf 'false'
86
+ }
87
+ _guideline_url_of() {
88
+ command -v guideline_url >/dev/null 2>&1 && guideline_url "$1" || printf ''
89
+ }
41
90
 
42
91
  : "${FINDINGS_TMP:=}"
43
92
 
@@ -48,9 +97,15 @@ _record() {
48
97
  guideline="$(printf '%s' "$msg" | awk '{print $1}')"
49
98
  jq -nc --arg r "$_CURRENT_RULE" --arg s "$sev" --arg g "$guideline" \
50
99
  --arg m "$msg" --arg f "$file" --arg l "$line" \
100
+ --arg ev "$(_evidence_of "$sev")" --arg cf "$(_confidence_of "$sev")" \
101
+ --arg nb "$(_needs_build_of "$sev")" --arg gu "$(_guideline_url_of "$guideline")" \
51
102
  '{rule_id:$r, severity:$s, guideline:$g, message:$m,
52
103
  file:(if $f=="" then null else $f end),
53
104
  line:(if $l=="" then null else ($l|tonumber) end),
105
+ evidence:(if $ev=="" then null else $ev end),
106
+ confidence:(if $cf=="" then null else $cf end),
107
+ needs_build_verification:($nb=="true"),
108
+ guideline_url:(if $gu=="" then null else $gu end),
54
109
  suppressed:false}' >> "$FINDINGS_TMP"
55
110
  }
56
111
 
@@ -64,9 +119,15 @@ _record_suppressed() {
64
119
  guideline="$(printf '%s' "$msg" | awk '{print $1}')"
65
120
  jq -nc --arg r "$_CURRENT_RULE" --arg s "$sev" --arg g "$guideline" \
66
121
  --arg m "$msg" --arg f "$file" --arg l "$line" \
122
+ --arg ev "$(_evidence_of "$sev")" --arg cf "$(_confidence_of "$sev")" \
123
+ --arg nb "$(_needs_build_of "$sev")" --arg gu "$(_guideline_url_of "$guideline")" \
67
124
  '{rule_id:$r, severity:$s, guideline:$g, message:$m,
68
125
  file:(if $f=="" then null else $f end),
69
126
  line:(if $l=="" then null else ($l|tonumber) end),
127
+ evidence:(if $ev=="" then null else $ev end),
128
+ confidence:(if $cf=="" then null else $cf end),
129
+ needs_build_verification:($nb=="true"),
130
+ guideline_url:(if $gu=="" then null else $gu end),
70
131
  suppressed:true}' >> "$FINDINGS_TMP"
71
132
  _SUPPRESSED_COUNT=$((_SUPPRESSED_COUNT + 1))
72
133
  }
@@ -81,16 +142,34 @@ render_json() {
81
142
  # shellcheck source=thresholds.sh
82
143
  . "$(dirname "${BASH_SOURCE[0]}")/thresholds.sh"
83
144
  [[ -s "$buf" ]] || { printf '%s\n' '{"findings":[]}' | jq \
84
- --arg v "$PRECHECK_VERSION" '{tool:"appstore-precheck",version:$v,verdict:"GREEN",summary:{fail:0,warn:0,pass:0,suppressed:0},findings:[]}'; return 0; }
145
+ --arg v "$PRECHECK_VERSION" '{tool:"appstore-precheck",version:$v,verdict:"GREEN",
146
+ summary:{fail:0,warn:0,pass:0,suppressed:0,
147
+ by_confidence:{"validator-blocking":0,"review-risk":0,"judgment-call":0,unclassified:0},
148
+ needs_build_verification:0, not_audited:0},
149
+ findings:[]}'; return 0; }
85
150
  jq -s --arg v "$PRECHECK_VERSION" \
86
151
  --argjson fmin "$RED_FAIL_MIN" --argjson wmin "$YELLOW_WARN_MIN" '
87
152
  (map(select(.suppressed==false))) as $live
88
153
  | ($live|map(select(.severity=="FAIL"))|length) as $f
89
154
  | ($live|map(select(.severity=="WARN"))|length) as $w
90
155
  | ($live|map(select(.severity=="PASS"))|length) as $p
156
+ # not_audited counts EVERY SKIP, suppressed ones included: acknowledging a gap
157
+ # in .precheck-ignore signs it, it does not close it. (suppressed counts it too —
158
+ # two different questions: "was it examined?" and "who took responsibility?")
159
+ | (map(select(.severity=="SKIP"))|length) as $na
91
160
  | (map(select(.suppressed==true))|length) as $s
92
161
  | (if $f>=$fmin then "RED" elif $w>=$wmin then "YELLOW" else "GREEN" end) as $verdict
162
+ # by_confidence counts live ISSUES (FAIL + WARN) only. A PASS carries the same
163
+ # labels, but rolling passes into the confidence mix would misread as risk.
164
+ | ($live|map(select(.severity=="FAIL" or .severity=="WARN"))) as $issues
165
+ | ($issues|map(select(.needs_build_verification==true))|length) as $nb
93
166
  | {tool:"appstore-precheck", version:$v, verdict:$verdict,
94
- summary:{fail:$f, warn:$w, pass:$p, suppressed:$s},
167
+ summary:{fail:$f, warn:$w, pass:$p, suppressed:$s,
168
+ by_confidence:{
169
+ "validator-blocking":($issues|map(select(.confidence=="validator-blocking"))|length),
170
+ "review-risk":($issues|map(select(.confidence=="review-risk"))|length),
171
+ "judgment-call":($issues|map(select(.confidence=="judgment-call"))|length),
172
+ unclassified:($issues|map(select(.confidence==null))|length)},
173
+ needs_build_verification:$nb, not_audited:$na},
95
174
  findings: .}' "$buf"
96
175
  }
@@ -0,0 +1,196 @@
1
+ #!/usr/bin/env bash
2
+ # guideline-cite.sh — offline lookup of a PINNED App Store Review Guideline quote.
3
+ #
4
+ # WHY THIS EXISTS
5
+ # ---------------
6
+ # Pierre explains every FAIL and WARN, and an explanation is only worth reading if
7
+ # the guideline wording behind it is Apple's, not the model's recollection of it.
8
+ # Two ways to get that wording, and they trade off differently:
9
+ #
10
+ # fetch the page every run — always current, but needs the network, truncates
11
+ # past ~5.4, and gives a different answer each run
12
+ # quote a pinned snapshot — offline, deterministic, reviewable in git, and can
13
+ # be checked for staleness by the drift job
14
+ #
15
+ # This tool is the second. The pinned quotes live in guidelines-fingerprints.json
16
+ # beside the fingerprints that already detect when Apple changes a section, so a
17
+ # quote that has gone out of date is a detectable condition rather than a silent
18
+ # lie. When there is no pinned quote, this exits non-zero and says NO PINNED
19
+ # CITATION — the caller must then say the wording could not be verified. It must
20
+ # never reconstruct guideline text from memory.
21
+ #
22
+ # Usage:
23
+ # guideline-cite.sh <guideline> # e.g. 5.1.1, 5.1.1(v), 3.1.1(a)
24
+ # guideline-cite.sh --json <guideline>
25
+ # guideline-cite.sh --verify-live <guideline> # network: has Apple changed this section?
26
+ # guideline-cite.sh --list
27
+ # guideline-cite.sh --fingerprints <file> <guideline>
28
+ #
29
+ # Exit codes: 0 cited | 3 no pinned citation | 4 pinned quote is out of date | 64 bad
30
+ # usage | 66 store unreadable
31
+ set -u
32
+
33
+ GC_BASE_URL="https://developer.apple.com/app-store/review/guidelines/"
34
+ # A pinned quote older than this is reported STALE. Not a hard error: an unchanged
35
+ # section stays correct indefinitely, but the reader deserves to know its age.
36
+ GC_STALE_DAYS="${GUIDELINE_CITE_STALE_DAYS:-120}"
37
+ GC_URL="${GUIDELINE_CITE_URL:-https://developer.apple.com/app-store/review/guidelines/}"
38
+ # --verify-live caches the fetched page for the day, so checking every finding in a
39
+ # run costs one request, not one per finding. The cache lives under the USER'S cache
40
+ # dir, never a shared /tmp: a predictable path in a world-writable directory would let
41
+ # any local user pre-place a crafted page and have this tool "verify" a citation
42
+ # against it. Override with GUIDELINE_CITE_CACHE (tests point it at a fixture).
43
+ GC_CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/appstore-precheck"
44
+ GC_CACHE="${GUIDELINE_CITE_CACHE:-$GC_CACHE_DIR/guidelines-$(date +%Y%m%d).html}"
45
+
46
+ HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
47
+ FINGERPRINTS="$HERE/../guidelines-fingerprints.json"
48
+ LIB="$HERE/lib/guideline-text.sh"
49
+ MODE="text"; ARG=""; VERIFY_LIVE=0
50
+
51
+ while [[ $# -gt 0 ]]; do
52
+ case "$1" in
53
+ --json) MODE="json"; shift ;;
54
+ --list) MODE="list"; shift ;;
55
+ --verify-live) VERIFY_LIVE=1; shift ;;
56
+ --fingerprints)
57
+ [[ $# -lt 2 ]] && { echo "guideline-cite.sh: --fingerprints needs a path" >&2; exit 64; }
58
+ FINGERPRINTS="$2"; shift 2 ;;
59
+ --fingerprints=*) FINGERPRINTS="${1#*=}"; shift ;;
60
+ -h|--help) sed -n '2,30p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//'; exit 0 ;;
61
+ -*) echo "guideline-cite.sh: unknown option '$1'" >&2; exit 64 ;;
62
+ *) ARG="$1"; shift ;;
63
+ esac
64
+ done
65
+
66
+ command -v jq >/dev/null 2>&1 || { echo "guideline-cite.sh: jq is required" >&2; exit 66; }
67
+ [[ -r "$FINGERPRINTS" ]] || { echo "guideline-cite.sh: cannot read $FINGERPRINTS" >&2; exit 66; }
68
+
69
+ if [[ "$MODE" == "list" ]]; then
70
+ jq -r '.sections | to_entries
71
+ | map(select(.value.quote != null and .value.quote != ""))
72
+ | sort_by(.key)[]
73
+ | "\(.key)\t\(.value.quote_verified_on // "undated")"' "$FINGERPRINTS"
74
+ exit 0
75
+ fi
76
+
77
+ [[ -n "$ARG" ]] || { echo "guideline-cite.sh: needs a guideline number (e.g. 5.1.1)" >&2; exit 64; }
78
+
79
+ # Apple anchors sections by their bare number; 5.1.1(v) and 3.1.1(a) are prose
80
+ # sub-items of 5.1.1 and 3.1.1, not separate anchors. Resolve to the stem.
81
+ SECTION="${ARG%%(*}"
82
+ [[ "$SECTION" =~ ^[1-5](\.[0-9]+)+$ ]] || {
83
+ echo "guideline-cite.sh: '$ARG' is not a guideline number" >&2; exit 64; }
84
+ URL="${GC_BASE_URL}#${SECTION}"
85
+
86
+ QUOTE="$(jq -r --arg s "$SECTION" '.sections[$s].quote // ""' "$FINGERPRINTS")"
87
+ VERIFIED="$(jq -r --arg s "$SECTION" '.sections[$s].quote_verified_on // ""' "$FINGERPRINTS")"
88
+
89
+ # _days <YYYY-MM-DD> -> days since the civil epoch (Howard Hinnant's algorithm).
90
+ # Pure arithmetic on purpose: `date -d` (GNU) and `date -j -f` (BSD) disagree, and
91
+ # this script runs on both a developer laptop and CI.
92
+ _days() {
93
+ local y m d era yoe doy doe
94
+ y=${1%%-*}; m=${1:5:2}; d=${1:8:2}
95
+ y=$((10#$y)); m=$((10#$m)); d=$((10#$d))
96
+ (( m <= 2 )) && y=$((y - 1))
97
+ (( y >= 0 )) && era=$((y / 400)) || era=$(( (y - 399) / 400 ))
98
+ yoe=$((y - era * 400))
99
+ if (( m > 2 )); then doy=$(( (153 * (m - 3) + 2) / 5 + d - 1 ))
100
+ else doy=$(( (153 * (m + 9) + 2) / 5 + d - 1 )); fi
101
+ doe=$(( yoe * 365 + yoe / 4 - yoe / 100 + doy ))
102
+ echo $(( era * 146097 + doe - 719468 ))
103
+ }
104
+
105
+ STALE="false"; AGE=""
106
+ if [[ -n "$VERIFIED" && "$VERIFIED" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then
107
+ AGE=$(( $(_days "$(date +%F)") - $(_days "$VERIFIED") ))
108
+ (( AGE > GC_STALE_DAYS )) && STALE="true"
109
+ fi
110
+
111
+ # --- Optional live verification ------------------------------------------------
112
+ # Age-based staleness is a proxy: an untouched section stays correct for years, and a
113
+ # section Apple edited yesterday is wrong while still looking fresh. This resolves it
114
+ # for real by re-hashing the live section and comparing it to the pinned fingerprint —
115
+ # the same comparison the scheduled drift job makes, available at explain time.
116
+ CHANGED="false"; LIVE_NOTE=""
117
+ if [[ "$VERIFY_LIVE" == 1 ]]; then
118
+ if [[ ! -r "$LIB" ]]; then
119
+ LIVE_NOTE="live check unavailable (parser not found)"
120
+ elif ! command -v curl >/dev/null 2>&1; then
121
+ LIVE_NOTE="live check unavailable (curl not found)"
122
+ else
123
+ # shellcheck source=lib/guideline-text.sh
124
+ . "$LIB"
125
+ _fetched=0
126
+ if [[ -e "$GC_CACHE" && ! -f "$GC_CACHE" ]]; then
127
+ # A directory, device, or socket at the cache path is never something to read
128
+ # from or delete (`rm -f /dev/null` as root would be catastrophic).
129
+ LIVE_NOTE="live check unavailable (cache path is not a regular file)"
130
+ elif [[ -L "$GC_CACHE" ]]; then
131
+ LIVE_NOTE="live check unavailable (cache path is a symlink)"
132
+ else
133
+ if [[ ! -s "$GC_CACHE" ]]; then
134
+ [[ "$GC_CACHE" == "$GC_CACHE_DIR"/* ]] && { mkdir -p "$GC_CACHE_DIR" 2>/dev/null; chmod 700 "$GC_CACHE_DIR" 2>/dev/null; }
135
+ curl -sL --max-time 30 "$GC_URL" -o "$GC_CACHE" 2>/dev/null && _fetched=1
136
+ fi
137
+ fi
138
+ if [[ -n "$LIVE_NOTE" ]]; then
139
+ :
140
+ elif [[ ! -s "$GC_CACHE" ]]; then
141
+ LIVE_NOTE="live check failed (could not fetch the guidelines page)"
142
+ # Only remove what THIS run created, so a user-supplied path is never deleted.
143
+ [[ "$_fetched" == 1 ]] && rm -f "$GC_CACHE"
144
+ else
145
+ _pinned="$(jq -r --arg s "$SECTION" '.sections[$s].fingerprint // ""' "$FINGERPRINTS")"
146
+ _livetxt="$(gd_section_text "$GC_CACHE" "$SECTION")"
147
+ if [[ -z "$_livetxt" ]]; then
148
+ LIVE_NOTE="live check inconclusive ($SECTION not found on the live page)"
149
+ elif [[ -z "$_pinned" ]]; then
150
+ LIVE_NOTE="live check inconclusive (no pinned fingerprint for $SECTION)"
151
+ elif [[ "$(printf '%s' "$_livetxt" | gd_hash)" != "$_pinned" ]]; then
152
+ CHANGED="true"; STALE="true"
153
+ else
154
+ LIVE_NOTE="verified against the live page just now"
155
+ # A section confirmed unchanged is current no matter how old the pin is.
156
+ STALE="false"
157
+ fi
158
+ fi
159
+ fi
160
+ fi
161
+
162
+ if [[ -z "$QUOTE" ]]; then
163
+ if [[ "$MODE" == "json" ]]; then
164
+ jq -nc --arg g "$SECTION" --arg u "$URL" \
165
+ '{guideline:$g, url:$u, cited:false, quote:null, verified_on:null, stale:false,
166
+ reason:"no pinned citation for this section"}'
167
+ else
168
+ echo "NO PINNED CITATION for $SECTION"
169
+ echo " source: $URL"
170
+ echo " Say the wording could not be verified this run. Do NOT quote guideline text from memory."
171
+ fi
172
+ exit 3
173
+ fi
174
+
175
+ if [[ "$MODE" == "json" ]]; then
176
+ jq -nc --arg g "$SECTION" --arg u "$URL" --arg q "$QUOTE" --arg v "$VERIFIED" \
177
+ --argjson st "$STALE" --arg a "$AGE" --argjson ch "$CHANGED" --arg ln "$LIVE_NOTE" \
178
+ '{guideline:$g, url:$u, cited:true, quote:$q,
179
+ verified_on:(if $v=="" then null else $v end),
180
+ stale:$st, changed:$ch, age_days:(if $a=="" then null else ($a|tonumber) end),
181
+ live_note:(if $ln=="" then null else $ln end)}'
182
+ [[ "$CHANGED" == "true" ]] && exit 4
183
+ exit 0
184
+ fi
185
+
186
+ echo "$SECTION — $URL"
187
+ echo "\"$QUOTE\""
188
+ if [[ "$CHANGED" == "true" ]]; then
189
+ # The strongest signal available: not "this pin is old" but "Apple's text moved".
190
+ echo " CHANGED: Apple's text for $SECTION differs from the pinned quote. Treat the wording above as OUT OF DATE — read the live section and say so rather than quoting it as current."
191
+ exit 4
192
+ elif [[ "$STALE" == "true" ]]; then
193
+ echo " pinned quote verified ${VERIFIED} (${AGE} days ago) — STALE: re-verify against the live page before relying on the exact wording."
194
+ else
195
+ echo " pinned quote, verified ${VERIFIED:-undated}${LIVE_NOTE:+ — $LIVE_NOTE}"
196
+ fi
@@ -0,0 +1,86 @@
1
+ #!/usr/bin/env bash
2
+ # scripts/lib/guideline-text.sh — shared Apple App Store Review Guidelines HTML
3
+ # parsing helpers. Source this; do not execute directly. Used by
4
+ # scripts/guideline-drift.sh (drift detection) and eval/rag/ingest.sh (RAG corpus
5
+ # ingestion) so the extraction logic has exactly one implementation.
6
+
7
+ # gd_section_ids <html> -> numeric guideline anchor ids, document order, deduped.
8
+ # Requires at least one dotted component so bare top-level category anchors
9
+ # (id="1".."5") aren't tracked as drift-able sections — those are just the
10
+ # five category headers, not sub-sections with their own prose.
11
+ gd_section_ids() {
12
+ grep -oE 'id="[1-5](\.[0-9]+)+"' "$1" 2>/dev/null \
13
+ | sed -E 's/^id="//; s/"$//' \
14
+ | awk '!seen[$0]++'
15
+ }
16
+
17
+ # _gd_section_raw <html> <id> -> normalized prose for exactly that section, in the
18
+ # ORIGINAL case. Shared by gd_section_text (which lowercases it for fingerprinting)
19
+ # and gd_section_quote (which keeps the case, because a citation has to read like
20
+ # Apple wrote it). Lowercasing moved to the caller: tr and the whitespace squeeze
21
+ # commute, so gd_section_text is byte-identical to before this split.
22
+ _gd_section_raw() {
23
+ local html="$1" want="$2"
24
+ # Replace each opening guideline-anchor tag (e.g. <span id="2.3.3"> or <li id="2.3.3" ...>)
25
+ # with a whole-tag sentinel @@SEC:<id>@@ on its own line, so no partial tag leaks.
26
+ sed -E 's#<[a-zA-Z]+[^>]*id="([1-5](\.[0-9]+)*)"[^>]*>#\'$'\n''@@SEC:\1@@#g' "$html" \
27
+ | awk -v want="$want" '
28
+ {
29
+ if ($0 ~ /^@@SEC:/) {
30
+ id=$0; sub(/^@@SEC:/,"",id); sub(/@@.*/,"",id)
31
+ insec = (id == want)
32
+ sub(/^@@SEC:[^@]*@@/,"") # drop the sentinel, keep any trailing content on the line
33
+ }
34
+ if (insec) buf = buf $0 " "
35
+ }
36
+ END { printf "%s", buf }
37
+ ' \
38
+ | sed -E 's/<[^>]+>/ /g' \
39
+ | sed -E 's/&amp;/\&/g; s/&lt;/</g; s/&gt;/>/g; s/&#39;/'\''/g; s/&quot;/"/g; s/&nbsp;/ /g' \
40
+ | tr -s ' \t\n' ' ' \
41
+ | sed -E 's/^ +//; s/ +$//'
42
+ }
43
+
44
+ # gd_section_text <html> <id> -> normalized, LOWERCASED prose for exactly that
45
+ # section. This is the fingerprint input; its bytes must stay stable.
46
+ gd_section_text() {
47
+ _gd_section_raw "$1" "$2" \
48
+ | tr 'A-Z' 'a-z' \
49
+ | sed -E 's/ after you submit once .*$//; s/ last updated: .*$//'
50
+ }
51
+ # That final sed guards the LAST numbered section (currently 5.6.4): it has no
52
+ # following section anchor, so the raw extraction runs to end-of-page and would
53
+ # glue the "After You Submit" info block, the "last updated" date, and the whole
54
+ # site footer (program lists etc.) onto its prose — making its fingerprint churn
55
+ # on every footer edit. Both markers are page chrome, never guideline prose.
56
+
57
+ # gd_section_quote <html> <id> [max-chars] -> a citable, original-case excerpt of
58
+ # that section, cut at a sentence boundary. Default 600 chars.
59
+ #
60
+ # The page-chrome tail (the "After You Submit" block and the footer) is stripped by
61
+ # gd_section_text case-sensitively on lowercased text. Rather than duplicate those
62
+ # patterns for mixed case, take the raw prose and keep exactly as many characters as
63
+ # the trimmed lowercase form has: lowercasing preserves length, and the tail strip
64
+ # only ever removes a suffix, so the prefix lengths line up exactly.
65
+ gd_section_quote() {
66
+ local html="$1" want="$2" max="${3:-600}" raw norm n quote
67
+ raw="$(_gd_section_raw "$html" "$want")"
68
+ [[ -z "$raw" ]] && { printf ''; return; }
69
+ norm="$(gd_section_text "$html" "$want")"
70
+ n=${#norm}
71
+ quote="${raw:0:$n}"
72
+ (( ${#quote} <= max )) && { printf '%s' "$quote"; return; }
73
+ # Prefer the last sentence end inside the budget; fall back to a word boundary,
74
+ # then to a hard cut. A citation that stops mid-word reads like a bug.
75
+ local head="${quote:0:$max}" cut
76
+ cut="$(printf '%s' "$head" | awk '{ n=0; for(i=length($0); i>1; i--) { c=substr($0,i,1); d=substr($0,i+1,1); if (c=="." && d==" ") { n=i; break } } print n }')"
77
+ if (( cut > max / 3 )); then printf '%s' "${head:0:$cut}"; return; fi
78
+ cut="${head% *}"
79
+ printf '%s…' "$cut"
80
+ }
81
+
82
+ # gd_hash -> sha256 hex of stdin (portable across macOS/Linux).
83
+ gd_hash() {
84
+ if command -v sha256sum >/dev/null 2>&1; then sha256sum | cut -d' ' -f1
85
+ else shasum -a 256 | cut -d' ' -f1; fi
86
+ }
@@ -28,6 +28,15 @@ render_sarif() {
28
28
  ( (if (.rule_id // "") == "" then {} else {ruleId:.rule_id} end)
29
29
  + {level:(if .severity=="FAIL" then "error" else "warning" end),
30
30
  message:{text:.message}}
31
+ # Evidence strength travels with the result so a code-scanning UI can
32
+ # separate an established validator block from one inferred off a source
33
+ # grep. Omitted entirely when the rule is unclassified — never guessed.
34
+ + (if .confidence != null
35
+ then {properties:({confidence:.confidence,
36
+ needsBuildVerification:.needs_build_verification}
37
+ + (if .evidence != null then {evidence:.evidence} else {} end)
38
+ + (if .guideline_url != null then {guidelineUrl:.guideline_url} else {} end))}
39
+ else {} end)
31
40
  + (if .file != null
32
41
  then {locations:[{physicalLocation:(
33
42
  {artifactLocation:{uri:.file}}