appstore-precheck 1.18.0 → 1.20.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.
Files changed (70) hide show
  1. package/CHANGELOG.md +256 -0
  2. package/README.md +108 -39
  3. package/bin/cli.js +8 -0
  4. package/package.json +2 -2
  5. package/skills/appstore-precheck/SKILL.md +99 -157
  6. package/skills/appstore-precheck/guidelines-baseline.json +285 -36
  7. package/skills/appstore-precheck/guidelines-fingerprints.json +319 -93
  8. package/skills/appstore-precheck/references/finding-commentary.md +93 -0
  9. package/skills/appstore-precheck/references/methodology.md +81 -26
  10. package/skills/appstore-precheck/references/optional-review.md +56 -0
  11. package/skills/appstore-precheck/references/pierre-deep-review.md +323 -44
  12. package/skills/appstore-precheck/references/review-catalog.json +740 -0
  13. package/skills/appstore-precheck/references/screenshot-vision-review.md +8 -8
  14. package/skills/appstore-precheck/references/simulator-dynamic-review.md +398 -54
  15. package/skills/appstore-precheck/references/typesafe-example.json +239 -0
  16. package/skills/appstore-precheck/references/typesafe.md +216 -0
  17. package/skills/appstore-precheck/scripts/app-discover.sh +138 -0
  18. package/skills/appstore-precheck/scripts/artifact-review.sh +10 -0
  19. package/skills/appstore-precheck/scripts/augment-json.py +29 -0
  20. package/skills/appstore-precheck/scripts/build-run.sh +5 -0
  21. package/skills/appstore-precheck/scripts/coverage-sections.sh +6 -0
  22. package/skills/appstore-precheck/scripts/dynamic-run.sh +400 -0
  23. package/skills/appstore-precheck/scripts/dynamic.sh +329 -0
  24. package/skills/appstore-precheck/scripts/evidence.sh +49 -15
  25. package/skills/appstore-precheck/scripts/findings.sh +76 -26
  26. package/skills/appstore-precheck/scripts/framework-detect.sh +101 -0
  27. package/skills/appstore-precheck/scripts/guideline-cite.sh +4 -1
  28. package/skills/appstore-precheck/scripts/lib/artifact-review.py +518 -0
  29. package/skills/appstore-precheck/scripts/lib/asc-client.py +293 -0
  30. package/skills/appstore-precheck/scripts/lib/build-evidence.py +50 -0
  31. package/skills/appstore-precheck/scripts/lib/build-exec.py +50 -0
  32. package/skills/appstore-precheck/scripts/lib/build-plan.py +106 -0
  33. package/skills/appstore-precheck/scripts/lib/build-plan.sh +15 -0
  34. package/skills/appstore-precheck/scripts/lib/build-run.py +177 -0
  35. package/skills/appstore-precheck/scripts/lib/coverage-run.sh +23 -0
  36. package/skills/appstore-precheck/scripts/lib/coverage-sections.py +244 -0
  37. package/skills/appstore-precheck/scripts/lib/dyn-bundle.sh +185 -0
  38. package/skills/appstore-precheck/scripts/lib/dyn-demo-login.py +111 -0
  39. package/skills/appstore-precheck/scripts/lib/dyn-device.sh +123 -0
  40. package/skills/appstore-precheck/scripts/lib/dyn-explore.py +312 -0
  41. package/skills/appstore-precheck/scripts/lib/dyn-geometry.sh +75 -0
  42. package/skills/appstore-precheck/scripts/lib/dyn-guideline-capture.py +301 -0
  43. package/skills/appstore-precheck/scripts/lib/dyn-guidelines.py +112 -0
  44. package/skills/appstore-precheck/scripts/lib/dyn-guidelines.sh +23 -0
  45. package/skills/appstore-precheck/scripts/lib/dyn-hosts.sh +134 -0
  46. package/skills/appstore-precheck/scripts/lib/dyn-process.py +75 -0
  47. package/skills/appstore-precheck/scripts/lib/dyn-quorum.sh +90 -0
  48. package/skills/appstore-precheck/scripts/lib/dyn-scrub.py +79 -0
  49. package/skills/appstore-precheck/scripts/lib/dyn-signals.sh +120 -0
  50. package/skills/appstore-precheck/scripts/lib/guideline-text.sh +23 -5
  51. package/skills/appstore-precheck/scripts/lib/metadata-review.py +369 -0
  52. package/skills/appstore-precheck/scripts/lib/optin-scan.sh +73 -0
  53. package/skills/appstore-precheck/scripts/lib/optional-records.py +60 -0
  54. package/skills/appstore-precheck/scripts/lib/png-uniform.py +115 -0
  55. package/skills/appstore-precheck/scripts/lib/runtime-blocking.py +26 -0
  56. package/skills/appstore-precheck/scripts/lib/safe_write.py +61 -0
  57. package/skills/appstore-precheck/scripts/lib/scan-guidelines.sh +199 -0
  58. package/skills/appstore-precheck/scripts/lib/static-guidelines.py +341 -0
  59. package/skills/appstore-precheck/scripts/lib/static-reader.py +39 -0
  60. package/skills/appstore-precheck/scripts/metadata-review.sh +4 -0
  61. package/skills/appstore-precheck/scripts/opt-in-review.py +160 -0
  62. package/skills/appstore-precheck/scripts/runtime-review.sh +5 -0
  63. package/skills/appstore-precheck/scripts/scan.sh +132 -21
  64. package/skills/appstore-precheck/scripts/semantic/__init__.py +1 -0
  65. package/skills/appstore-precheck/scripts/semantic/client.py +95 -0
  66. package/skills/appstore-precheck/scripts/semantic/collect.py +165 -0
  67. package/skills/appstore-precheck/scripts/semantic/engine.py +320 -0
  68. package/skills/appstore-precheck/scripts/semantic/questions.py +167 -0
  69. package/skills/appstore-precheck/scripts/semantic/review_v4.py +81 -0
  70. package/skills/appstore-precheck/scripts/semantic-review.py +61 -0
@@ -0,0 +1,160 @@
1
+ """Coordinate explicitly requested tiers; default scan never invokes this runner."""
2
+ import argparse
3
+ import importlib.util
4
+ import json
5
+ import os
6
+ from pathlib import Path
7
+ import re
8
+ import stat
9
+ import subprocess
10
+ import sys
11
+ import tempfile
12
+
13
+ HERE = Path(__file__).resolve().parent
14
+ OWN_OUTPUTS = ('summary.json', 'run-results.json', 'artifact-review.json', 'metadata-review.json')
15
+
16
+
17
+ def module(name):
18
+ spec = importlib.util.spec_from_file_location(name.replace('-', '_'), HERE / 'lib' / (name + '.py'))
19
+ value = importlib.util.module_from_spec(spec); spec.loader.exec_module(value)
20
+ return value
21
+
22
+
23
+ PROCESS, SAFE, RECORDS = module('dyn-process'), module('safe_write'), module('optional-records')
24
+ merge_status = RECORDS.merge_status
25
+
26
+
27
+ def remove_stale_outputs(out):
28
+ paths = [out / name for name in OWN_OUTPUTS]
29
+ if not (out / 'runtime').is_symlink():
30
+ paths.append(out / 'runtime/screen-inventory.json')
31
+ if not (out / 'runtime/explore').is_symlink():
32
+ paths.append(out / 'runtime/explore/screen-inventory.json')
33
+ for path in paths:
34
+ try:
35
+ mode = path.lstat().st_mode
36
+ except (FileNotFoundError, NotADirectoryError):
37
+ continue
38
+ if not stat.S_ISDIR(mode):
39
+ path.unlink()
40
+
41
+
42
+ def run(command, timeout):
43
+ try:
44
+ return PROCESS.run(command, timeout, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
45
+ except (OSError, subprocess.TimeoutExpired):
46
+ return None
47
+
48
+
49
+ def arguments():
50
+ parser = argparse.ArgumentParser(description=__doc__)
51
+ parser.add_argument('--repo', type=Path, required=True)
52
+ parser.add_argument('--out-dir', type=Path)
53
+ parser.add_argument('--app', type=Path)
54
+ for name in ('build', 'metadata', 'no-runtime', 'demo-login', 'dynamic-blocking', 'dry-run', 'check-urls'):
55
+ parser.add_argument('--' + name, action='store_true')
56
+ for name in ('asc-version-id', 'asc-info-id', 'asc-app-id'):
57
+ parser.add_argument('--' + name)
58
+ args = parser.parse_args(); repo = args.repo.resolve()
59
+ if not repo.is_dir() or (args.build and args.app):
60
+ parser.error('existing --repo and at most one of --build/--app required')
61
+ if (args.dynamic_blocking or args.demo_login) and not (args.build or args.app):
62
+ parser.error('runtime flags require --app or --build')
63
+ if args.no_runtime and (args.demo_login or args.dynamic_blocking):
64
+ parser.error('--no-runtime conflicts with runtime flags')
65
+ if (args.check_urls or args.asc_app_id or args.asc_info_id or args.asc_version_id) and not args.metadata:
66
+ parser.error('metadata options require --metadata')
67
+ if args.out_dir:
68
+ out = args.out_dir.resolve()
69
+ if out == repo or repo in out.parents:
70
+ parser.error('--out-dir must be outside the user project')
71
+ out.mkdir(parents=True, exist_ok=True)
72
+ else:
73
+ out = Path(tempfile.mkdtemp(prefix='precheck-review-'))
74
+ args.repo, args.out_dir = repo, out
75
+ return args
76
+
77
+
78
+ def json_tier(command, tier, args, checks, tiers, errors):
79
+ result = run(command, 120)
80
+ if result is None or result.returncode:
81
+ tiers[tier] = 'SKIP: tool, input or deadline unavailable'; return
82
+ try:
83
+ payload = json.loads(result.stdout)
84
+ path = args.out_dir / (tier + '-review.json')
85
+ SAFE.write_text(path, json.dumps(payload, indent=2) + '\n')
86
+ errors.extend(RECORDS.import_records(checks, payload.get('checks', payload.get('results', [])), str(path)))
87
+ tiers[tier] = 'RAN'
88
+ except (ValueError, TypeError, AttributeError):
89
+ tiers[tier] = 'SKIP: unreadable tier results'
90
+
91
+
92
+ def build_tier(args, tiers):
93
+ app = args.app.resolve() if args.app else None
94
+ if args.build:
95
+ command = ['bash', str(HERE / 'build-run.sh'), '--repo', str(args.repo), '--out', str(args.out_dir / 'artifact')]
96
+ if args.dry_run:
97
+ command.append('--dry-run')
98
+ result = run(command, 2700)
99
+ tiers['build'] = ('PLAN' if args.dry_run else 'RAN') if result and result.returncode == 0 else 'SKIP: build unavailable'
100
+ if result and result.returncode == 0 and not args.dry_run:
101
+ for line in result.stdout.splitlines():
102
+ if line.startswith('app_path='):
103
+ app = Path(line.split('=', 1)[1])
104
+ return app
105
+
106
+
107
+ def runtime_tier(args, app, checks, tiers):
108
+ if not app or args.no_runtime or args.dry_run:
109
+ return []
110
+ command = ['bash', str(HERE / 'runtime-review.sh'), '--app', str(app), '--repo', str(args.repo), '--out', str(args.out_dir / 'runtime')]
111
+ if args.demo_login:
112
+ command.append('--demo-login')
113
+ result = run(command, 1380)
114
+ if not result or result.returncode:
115
+ tiers['runtime'] = 'SKIP: simulator driver or deadline unavailable'; return []
116
+ tiers['runtime'] = 'RAN'
117
+ for line in result.stdout.splitlines():
118
+ match = re.match(r'^DYNAMIC-(PASS|FINDING|SKIP): \S+ \[([^]]+)\] — (.*)$', line)
119
+ if match:
120
+ status, check_id, detail = match.groups()
121
+ if status == 'FINDING' and not re.search(r'quorum 3/3(?:\D|$)', detail):
122
+ status = 'SKIP'
123
+ RECORDS.merge_result(checks, check_id.split(':')[0], status, detail, 'runtime/transcript.txt#' + check_id)
124
+ # Only the structured allowlisted blocking validator can authorize escalation.
125
+ validator = module('runtime-blocking')
126
+ return validator.blocking(args.out_dir / 'runtime') if args.dynamic_blocking else []
127
+
128
+
129
+ def main():
130
+ args = arguments(); remove_stale_outputs(args.out_dir)
131
+ checks, errors = {}, []
132
+ tiers = dict.fromkeys(('build', 'artifact', 'runtime', 'metadata'), 'NOT_RUN')
133
+ app = build_tier(args, tiers)
134
+ if app and not args.dry_run:
135
+ json_tier(['bash', str(HERE / 'artifact-review.sh'), '--app', str(app), '--format', 'json'], 'artifact', args, checks, tiers, errors)
136
+ blocking = runtime_tier(args, app, checks, tiers)
137
+ if args.metadata:
138
+ command = ['bash', str(HERE / 'metadata-review.sh'), '--repo', str(args.repo)]
139
+ for name in ('asc_app_id', 'asc_info_id', 'asc_version_id'):
140
+ if getattr(args, name):
141
+ command += ['--' + name.replace('_', '-'), getattr(args, name)]
142
+ if args.check_urls:
143
+ command.append('--check-urls')
144
+ json_tier(command, 'metadata', args, checks, tiers, errors)
145
+ result_path = args.out_dir / 'run-results.json'
146
+ SAFE.write_text(result_path, json.dumps({'checks': checks}, indent=2) + '\n')
147
+ summary = {'schema_version': 1, 'tiers': tiers, 'blocking': blocking, 'input_errors': errors,
148
+ 'run_results': str(result_path), 'output_dir': str(args.out_dir)}
149
+ SAFE.write_text(args.out_dir / 'summary.json', json.dumps(summary, indent=2) + '\n')
150
+ print(json.dumps(summary)); return 0
151
+
152
+
153
+ if __name__ == '__main__':
154
+ try:
155
+ raise SystemExit(main())
156
+ except InterruptedError:
157
+ raise SystemExit(143)
158
+ except OSError as exc:
159
+ print('opt-in-review: cannot write reports safely: ' + str(exc), file=sys.stderr)
160
+ raise SystemExit(2)
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env bash
2
+ # Explicit runtime tier. The caller supplies an existing simulator app; no builds.
3
+ set -eu
4
+ HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5
+ exec bash "$HERE/dynamic-run.sh" "$@"
@@ -15,6 +15,8 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
15
15
 
16
16
  FORMAT="text"
17
17
  SCAN_DIR=""
18
+ OPT_NO_RUNTIME=0 OPT_DEMO=0 OPT_ASC_VERSION="" OPT_ASC_INFO=""
19
+ OPT_BUILD=0 OPT_APP="" OPT_METADATA=0 OPT_ASC="" OPT_URLS=0 OPT_DYN_BLOCK=0 OPT_DRY=0 OPT_OUT="" OPT_TEMP="" OPT_RAN_OK=0
18
20
  while [[ $# -gt 0 ]]; do
19
21
  case "$1" in
20
22
  --format)
@@ -25,6 +27,26 @@ while [[ $# -gt 0 ]]; do
25
27
  if [[ $# -lt 2 ]]; then echo "scan.sh: --dir needs a path" >&2; exit 64; fi
26
28
  SCAN_DIR="$2"; shift 2 ;;
27
29
  --dir=*) SCAN_DIR="${1#*=}"; shift ;;
30
+ --build) OPT_BUILD=1; shift ;;
31
+ --app)
32
+ if [[ $# -lt 2 ]]; then echo "scan.sh: --app needs a path" >&2; exit 64; fi
33
+ OPT_APP="$2"; shift 2 ;;
34
+ --metadata) OPT_METADATA=1; shift ;;
35
+ --no-runtime) OPT_NO_RUNTIME=1; shift ;;
36
+ --demo-login) OPT_DEMO=1; shift ;;
37
+ --asc-version-id|--asc-info-id)
38
+ if [[ $# -lt 2 ]]; then echo "scan.sh: $1 needs an ID" >&2; exit 64; fi
39
+ if [[ "$1" == --asc-version-id ]]; then OPT_ASC_VERSION="$2"; else OPT_ASC_INFO="$2"; fi
40
+ shift 2 ;;
41
+ --asc-app-id)
42
+ if [[ $# -lt 2 ]]; then echo "scan.sh: --asc-app-id needs an ID" >&2; exit 64; fi
43
+ OPT_ASC="$2"; OPT_METADATA=1; shift 2 ;;
44
+ --check-urls) OPT_URLS=1; OPT_METADATA=1; shift ;;
45
+ --dynamic-blocking) OPT_DYN_BLOCK=1; shift ;;
46
+ --dry-run) OPT_DRY=1; shift ;;
47
+ --out)
48
+ if [[ $# -lt 2 ]]; then echo "scan.sh: --out needs a path" >&2; exit 64; fi
49
+ OPT_OUT="$2"; shift 2 ;;
28
50
  *) shift ;;
29
51
  esac
30
52
  done
@@ -45,8 +67,13 @@ source "$SCRIPT_DIR/suppress.sh"
45
67
  source "$SCRIPT_DIR/project-model.sh"
46
68
  source "$SCRIPT_DIR/image-dims.sh"
47
69
  source "$SCRIPT_DIR/sarif.sh"
70
+ source "$SCRIPT_DIR/framework-detect.sh"
71
+ # shellcheck source=skills/appstore-precheck/scripts/lib/coverage-run.sh
72
+ source "$SCRIPT_DIR/lib/coverage-run.sh"
48
73
  FINDINGS_TMP="$(mktemp)"; export FINDINGS_TMP
49
- trap 'rm -f "$FINDINGS_TMP"' EXIT
74
+ # shellcheck source=skills/appstore-precheck/scripts/lib/optin-scan.sh
75
+ source "$SCRIPT_DIR/lib/optin-scan.sh"
76
+ trap optin_cleanup EXIT
50
77
  # The envelope `version` is the appstore-precheck TOOL's own version (from this
51
78
  # skill's SKILL.md), never the scanned repo's — $ROOT above is the SCANNED app's
52
79
  # git root, so reading its package.json here would leak the wrong version.
@@ -73,6 +100,9 @@ cfg_bool() { # cfg_bool <json-path> — echoes "true"/"false"
73
100
  echo "false"
74
101
  }
75
102
 
103
+ optin_trust
104
+ optin_validate || exit $?
105
+
76
106
  _LAST_SUPPRESSED=0
77
107
 
78
108
  # _tag — print the evidence/confidence line under the finding just emitted, at the
@@ -253,7 +283,7 @@ echo "PASS: layout — ios='${IOS_DIR:-?}' metadata='${META_DIR:-?}' xcstrings='
253
283
  # The store listing is a real rejection surface. Without a fastlane metadata dir the
254
284
  # listing checks simply never run, and reporting only the ones that DID run would let
255
285
  # a repo look clean on ground nobody examined. Name the cost, derived from the
256
- # evidence catalogue so the number cannot rot as rules are added.
286
+ # evidence catalogue. New modular gaps are reported in coverage_sections instead.
257
287
  if [[ -z "$META_DIR" || ! -d "$META_DIR" ]]; then
258
288
  # A gap record, not a check (see evidence.sh is_gap_record): the id exists so the
259
289
  # gap can be acknowledged by name in .precheck-ignore. Acknowledging it removes the
@@ -268,6 +298,22 @@ if [[ -z "$META_DIR" || ! -d "$META_DIR" ]]; then
268
298
  set_rule ""
269
299
  fi
270
300
 
301
+ # The code-level checks grep Swift / ObjC only (SRC_INC). On React Native, Flutter
302
+ # and Kotlin Multiplatform the app logic is JS / Dart / Kotlin, so every `source`
303
+ # rule under-detects there rather than false-firing — and a clean-looking result
304
+ # would rest on ground nobody read. Detection is file presence only
305
+ # (framework-detect.sh); the count is derived from the evidence catalogue, like the
306
+ # original §1–§55 store-listing gap above; modular checks report separate gaps.
307
+ FRAMEWORK="$(detect_framework .)"
308
+ if [[ "$FRAMEWORK" != native ]]; then
309
+ set_rule "framework-not-audited"
310
+ _src_list="$(rules_with_evidence source 55)"
311
+ _src_rules="$(printf '%s\n' "$_src_list" | grep -c .)"
312
+ skip "framework — ${_src_rules} code-level checks under-detect on ${FRAMEWORK} (source greps read Swift/ObjC only): the metadata, manifest, resource and build-setting checks apply in full, but a ${FRAMEWORK} app's logic lives outside the files those checks read, so a clean result from them is partial. Review the listed guidelines against the ${FRAMEWORK} code by hand, or run the Phase 6 dynamic tier on a built simulator app."
313
+ detail "$(printf '%s\n' "$_src_list" | tr '\n' ' ' | sed 's/ $//')"
314
+ set_rule ""
315
+ fi
316
+
271
317
  # ===================================================================
272
318
  # §1 — 5.1.1 Privacy Manifest / Required Reason API parity
273
319
  # Apple documents the Required Reason API rules under 5.1.1 (Data Collection and
@@ -414,7 +460,7 @@ check_len() {
414
460
  len=$(wc -m < "$file" | tr -d ' ')
415
461
  fi
416
462
  [[ -z "$len" ]] && return
417
- (( len > limit )) && fail "2.3.1 $label — $file ${len} chars (limit ${limit})" "$file"
463
+ (( len > limit )) && fail "2.3.7 $label — $file ${len} chars (limit ${limit})" "$file"
418
464
  }
419
465
  for loc in "${LOCALES[@]+"${LOCALES[@]}"}"; do
420
466
  d="$META_DIR/$loc"; [[ -d "$d" ]] || continue
@@ -426,7 +472,7 @@ for loc in "${LOCALES[@]+"${LOCALES[@]}"}"; do
426
472
  done
427
473
 
428
474
  # ===================================================================
429
- # §6 — 2.3.7 Localized metadata parity across all detected locales
475
+ # §6 — 2.3 Localized metadata parity across all detected locales
430
476
  # ===================================================================
431
477
  set_rule "locale-metadata-parity"
432
478
  if (( ${#LOCALES[@]} > 0 )); then
@@ -439,9 +485,9 @@ if (( ${#LOCALES[@]} > 0 )); then
439
485
  # submitted. Warn (don't block) so an approved set isn't falsely RED.
440
486
  # Auto-detected locales always exist, so this only fires in config mode.
441
487
  if [[ -n "$LOCALES_FROM_CONFIG" ]]; then
442
- warn "2.3.7 Locale '$loc' is in .appstore-precheck.json but has no metadata folder ($d) — add it or remove '$loc' from the config 'locales' list"
488
+ warn "2.3 Locale '$loc' is in .appstore-precheck.json but has no metadata folder ($d) — add it or remove '$loc' from the config 'locales' list"
443
489
  else
444
- fail "2.3.7 Locale missing — $d does not exist"
490
+ fail "2.3 Locale missing — $d does not exist"
445
491
  fi
446
492
  continue
447
493
  fi
@@ -450,18 +496,18 @@ if (( ${#LOCALES[@]} > 0 )); then
450
496
  case "$f" in
451
497
  name.txt|description.txt)
452
498
  # App Store Connect will not accept a localization without these.
453
- fail "2.3.7 Metadata missing — $d/$f is empty or absent" ;;
499
+ fail "2.3 Metadata missing — $d/$f is empty or absent" ;;
454
500
  *)
455
501
  # Subtitle and keywords are OPTIONAL in App Store Connect (verified
456
502
  # 2026-09-01). An empty one is a discovery/parity gap, not a blocker —
457
503
  # reporting it as a validator FAIL was an overstatement.
458
504
  set_confidence "judgment-call"
459
- warn "2.3.7 Metadata gap — $d/$f is empty or absent (optional in App Store Connect, but every other locale should not be the only place it exists)"
505
+ warn "2.3 Metadata gap — $d/$f is empty or absent (optional in App Store Connect, but every other locale should not be the only place it exists)"
460
506
  set_confidence "" ;;
461
507
  esac
462
508
  done
463
509
  done
464
- pass "2.3.7 Localized metadata — checked ${#LOCALES[@]} locales"
510
+ pass "2.3 Localized metadata — checked ${#LOCALES[@]} locales"
465
511
  fi
466
512
 
467
513
  # ===================================================================
@@ -667,14 +713,14 @@ else
667
713
  fi
668
714
 
669
715
  # ===================================================================
670
- # §13 — 5.1.5 Screen Time / sensitive-API justification (optional, opt-in)
716
+ # §13 — review-preparation Screen Time / sensitive-API justification (optional, opt-in)
671
717
  # ===================================================================
672
718
  set_rule "screentime-justification"
673
719
  if [[ "$CHECK_FAMILY" == "true" ]] && grep -q "NSFamilyControlsUsageDescription" "$INFO_PLIST" 2>/dev/null; then
674
720
  if [[ -n "$REVIEW_PREP" && -f "$REVIEW_PREP" ]] && grep -qiE 'family|screen[[:space:]]?time' "$REVIEW_PREP" 2>/dev/null; then
675
- pass "5.1.5 Screen Time API — reviewer-prep justification note present"
721
+ pass "review-preparation Screen Time API — reviewer-prep justification note present"
676
722
  else
677
- warn "5.1.5 Screen Time API in use — add a justification in your ASC App Review notes (point .reviewPrepNotes at the file). Otherwise 5.1.1 rejection risk is high."
723
+ warn "review-preparation Screen Time API in use — add a justification in your ASC App Review notes (point .reviewPrepNotes at the file). This is preparation advice; it is not a Location Services requirement."
678
724
  fi
679
725
  fi
680
726
 
@@ -701,7 +747,7 @@ ext_purchase=""
701
747
  grep -rqE 'ExternalPurchase|ExternalPurchaseLink|ExternalPurchaseCustomLink' "${IOS_DIR:-.}" "${GREP_PRUNE[@]}" "${SRC_INC[@]}" 2>/dev/null && ext_purchase=1
702
748
  grep -rqE 'external-purchase' "${IOS_DIR:-.}" "${GREP_PRUNE[@]}" --include='*.entitlements' 2>/dev/null && ext_purchase=1
703
749
  if [[ -n "$ext_purchase" ]]; then
704
- warn "3.1.1(a) External purchase link detected — ensure the External Purchase entitlement, eligible storefronts, the required disclosure sheet, and App Store Connect reporting are in place (3.1.1(a))."
750
+ warn "3.1.1(a) External purchase link detected — review the offering, storefront, distribution and applicable agreement before checking entitlement, disclosure and reporting duties. United States storefront links do not require these entitlements under 3.1.1(a); SDK presence alone is not a violation."
705
751
  fi
706
752
 
707
753
  # ===================================================================
@@ -818,7 +864,7 @@ set_rule "thirdparty-payment-sdk"
818
864
  if [[ -n "$IOS_DIR" ]]; then
819
865
  payment_sdk=$(grep -rlE 'import Stripe|StripePaymentSheet|StripeApplePay|import Braintree|BTPaymentFlow|import PayPal|PayPalCheckout|PayPalNativeCheckout|import Square|SquareInAppPayments|import Adyen|AdyenComponents|RazorpaySDK|import Paddle' "$IOS_DIR" "${GREP_PRUNE[@]}" "${SRC_INC[@]}" 2>/dev/null | head -1)
820
866
  if [[ -n "$payment_sdk" ]]; then
821
- warn "3.1.1 Third-party payment SDK — '$(basename "$payment_sdk")' detected; selling digital content/functionality must use in-app purchase, not an external processor (3.1.1). Allowed only for physical goods/services — verify your offering."
867
+ warn "3.1.1 Third-party payment SDK — '$(basename "$payment_sdk")' detected; verify the actual digital/physical offering, storefront, distribution and 3.1.1/3.1.3 exception before deciding which payment methods are allowed. SDK presence alone establishes no violation."
822
868
  fi
823
869
  fi
824
870
 
@@ -1036,18 +1082,18 @@ if [[ -f "$INFO_PLIST" && -n "$IOS_DIR" ]]; then
1036
1082
  fi
1037
1083
 
1038
1084
  # ===================================================================
1039
- # §34 — 3.1.5(a) Cryptocurrency wallet / exchange / mining
1085
+ # §34 — 3.1.5 Cryptocurrency wallet / exchange / mining
1040
1086
  # ===================================================================
1041
1087
  set_rule "crypto-wallet-mining"
1042
1088
  if [[ -n "$IOS_DIR" ]]; then
1043
1089
  crypto_sdk=$(grep -rlE 'import Web3|web3swift|Web3Swift|WalletConnect|TrustWalletCore|CoinbaseWalletSDK|SolanaSwift|CryptoMining|coinhive|MoneroMiner' "$IOS_DIR" "${GREP_PRUNE[@]}" "${SRC_INC[@]}" 2>/dev/null | head -1)
1044
1090
  if [[ -n "$crypto_sdk" ]]; then
1045
- warn "3.1.5(a) Cryptocurrency — a crypto wallet/exchange/mining signal was detected (e.g. $(basename "$crypto_sdk")); wallets & exchanges have entity and licensing requirements, and on-device mining is not permitted (3.1.5(a)). Verify eligibility."
1091
+ warn "3.1.5 Cryptocurrency — a crypto wallet/exchange/mining signal was detected (e.g. $(basename "$crypto_sdk")); wallets & exchanges have entity and licensing requirements, and on-device mining is not permitted (3.1.5). Verify eligibility."
1046
1092
  fi
1047
1093
  fi
1048
1094
 
1049
1095
  # ===================================================================
1050
- # §35 — 4.2.3 Web-wrapper / thin app
1096
+ # §35 — 4.2 Web-wrapper / thin app
1051
1097
  # ===================================================================
1052
1098
  # A thin WKWebView wrapper around a website is rejected under minimum
1053
1099
  # functionality. Heuristic: WKWebView present in a project with very few Swift
@@ -1057,7 +1103,7 @@ if [[ -n "$IOS_DIR" ]]; then
1057
1103
  if grep -rqE 'WKWebView' "$IOS_DIR" "${GREP_PRUNE[@]}" "${SRC_INC[@]}" 2>/dev/null; then
1058
1104
  swift_n=$(find "$IOS_DIR" "${PRUNE[@]}" -name '*.swift' 2>/dev/null | wc -l | tr -d ' ')
1059
1105
  if (( swift_n > 0 && swift_n <= 4 )); then
1060
- warn "4.2.3 Minimum functionality — the app appears to be a WKWebView wrapper with only $swift_n Swift file(s); a thin wrapper around a website is rejected under 4.2.3. Add native value, or verify this is a real app rather than a repackaged site."
1106
+ warn "4.2 Minimum functionality — the app appears to be a WKWebView wrapper with only $swift_n Swift file(s); a thin wrapper around a website is reviewed under 4.2. Add native value, or verify this is a real app rather than a repackaged site."
1061
1107
  fi
1062
1108
  fi
1063
1109
  fi
@@ -1293,10 +1339,10 @@ if [[ -d "$META_DIR" ]]; then
1293
1339
  price_hits="$(printf '%s' "$price_hits" | grep -v '^$' | head -10)"
1294
1340
  if [[ -n "$price_hits" ]]; then
1295
1341
  price_first="$(printf '%s\n' "$price_hits" | head -1)"
1296
- warn "2.3.1 Pricing language in app name/subtitle — price or promo wording (\"Free\", \"% off\", a currency amount) in the name or subtitle is a common metadata rejection (2.3.1/2.3.7); prices belong in the price field, not the title:" "${price_first%%:*}"
1342
+ warn "2.3.7 Pricing language in app name/subtitle — price or promo wording (\"Free\", \"% off\", a currency amount) in the name or subtitle is a common metadata rejection (2.3.7); prices belong in the price field, not the title:" "${price_first%%:*}"
1297
1343
  detail "$price_hits"
1298
1344
  else
1299
- pass "2.3.1 App name/subtitle — no pricing/promo language detected"
1345
+ pass "2.3.7 App name/subtitle — no pricing/promo language detected"
1300
1346
  fi
1301
1347
  fi
1302
1348
 
@@ -1554,9 +1600,74 @@ if [[ -d "$META_DIR" ]]; then
1554
1600
  fi
1555
1601
  fi
1556
1602
 
1603
+ # ===================================================================
1604
+ # §55 — 2.5.5 IPv6-only networks: IPv4-only socket APIs + hardcoded IPv4 literals
1605
+ # ===================================================================
1606
+ # App Review runs on an IPv6-only NAT64 network (2.5.5: "Apps must be fully
1607
+ # functional on IPv6-only networks"). DNS64 synthesizes AAAA records for HOSTNAMES,
1608
+ # so URLSession/NWConnection code keeps working; an IPv4 LITERAL has no name to
1609
+ # synthesize from, and the legacy BSD IPv4 API (inet_addr, inet_aton, gethostbyname,
1610
+ # sockaddr_in, AF_INET) cannot address an IPv6 network at all. Both are greppable;
1611
+ # the NAT64 run itself is GUI-only (System Settings > Internet Sharing) and stays on
1612
+ # the manual checklist. WARN + review-risk: no upload validator looks at this — the
1613
+ # app simply fails to connect in front of a human reviewer. Heuristic exclusions
1614
+ # (loopback, 0.0.0.0, 255.x masks, CIDR ranges, version-looking values, comments)
1615
+ # are chosen to keep a false WARN rarer than a missed one.
1616
+ set_rule "ipv4-literal"
1617
+ if [[ -n "$IOS_DIR" ]]; then
1618
+ # The trailing class also rejects the IPv6-capable siblings (sockaddr_in6, AF_INET6,
1619
+ # gethostbyname2) because their next character is alphanumeric.
1620
+ ipv4_api_re='(^|[^A-Za-z0-9_])(inet_addr|inet_aton|gethostbyname|sockaddr_in|AF_INET)([^A-Za-z0-9_]|$)'
1621
+ ipv4_api_hits=$(grep -rnEI "$ipv4_api_re" "$IOS_DIR" "${GREP_PRUNE[@]}" "${SRC_INC[@]}" 2>/dev/null \
1622
+ | grep -vE '^[^:]+:[0-9]+:[[:space:]]*(//|\*|/\*|#)' | head -5)
1623
+ # Literals: dotted quads in source AND plists (ATS exception domains, endpoints).
1624
+ # Pre-filter with grep, then let awk apply the exclusions per match. No brace
1625
+ # intervals in the awk regexes: mawk (Ubuntu CI) does not support them.
1626
+ ipv4_lit_hits=""
1627
+ while IFS= read -r ipv4_f; do
1628
+ [[ -n "$ipv4_f" ]] || continue
1629
+ ipv4_h=$(awk -v F="$ipv4_f" '
1630
+ {
1631
+ line = $0; prev = prevline; prevline = $0
1632
+ if (line ~ /^[[:space:]]*(\/\/|\*|\/\*|#)/) next # comment lines
1633
+ if (tolower(line) ~ /version/ || tolower(prev) ~ /version/) next # CFBundleVersion-style values
1634
+ s = line
1635
+ while (match(s, /[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?/)) {
1636
+ pre = (RSTART > 1) ? substr(s, RSTART - 1, 1) : ""
1637
+ lit = substr(s, RSTART, RLENGTH)
1638
+ post = substr(s, RSTART + RLENGTH)
1639
+ s = post
1640
+ if (pre ~ /[0-9A-Za-z._]/) continue # v1.2.3.4, 10.1.2.3.4
1641
+ if (post ~ /^[0-9A-Za-z._]/) continue # 1.2.3.4.5, 1.2.3.4a
1642
+ if (post ~ /^\/[0-9][0-9]?([^0-9]|$)/) continue # CIDR range, not a host
1643
+ n = split(lit, o, ".")
1644
+ if (o[1] > 255 || o[2] > 255 || o[3] > 255 || o[4] > 255) continue
1645
+ if (o[1] == 0 || o[1] == 127 || o[1] == 255) continue # bind-any, loopback, masks/broadcast
1646
+ printf "%s:%d:%s\n", F, NR, lit; break
1647
+ }
1648
+ }' "$ipv4_f" 2>/dev/null | head -2)
1649
+ [[ -n "$ipv4_h" ]] && ipv4_lit_hits+="$ipv4_h"$'\n'
1650
+ done < <(grep -rlE '(^|[^0-9])[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}([^0-9]|$)' "$IOS_DIR" "${GREP_PRUNE[@]}" "${SRC_INC[@]}" --include='*.plist' 2>/dev/null | head -50)
1651
+ ipv4_lit_hits="$(printf '%s' "$ipv4_lit_hits" | grep -v '^$' | head -5)"
1652
+ ipv4_hits="$(printf '%s\n%s\n' "$ipv4_api_hits" "$ipv4_lit_hits" | grep -v '^$')"
1653
+ if [[ -n "$ipv4_hits" ]]; then
1654
+ ipv4_n="$(printf '%s\n' "$ipv4_hits" | wc -l | tr -d ' ')"
1655
+ ipv4_first="$(printf '%s\n' "$ipv4_hits" | head -1)"
1656
+ ipv4_file="${ipv4_first%%:*}"; ipv4_rest="${ipv4_first#*:}"; ipv4_line="${ipv4_rest%%:*}"
1657
+ warn "2.5.5 IPv6-only — $ipv4_n IPv4-only networking signal(s): a legacy BSD socket API (inet_addr / inet_aton / gethostbyname / sockaddr_in / AF_INET) and/or a hardcoded IPv4 literal. App Review tests on an IPv6-only NAT64 network: hostnames are synthesized by DNS64, but an IPv4 literal has nothing to synthesize from and the IPv4 socket API cannot address that network, so the app fails in front of the reviewer. Use hostnames via URLSession / NWConnection (or getaddrinfo with AF_UNSPEC) and verify on a NAT64 network before submitting" "$ipv4_file" "$ipv4_line"
1658
+ detail "$ipv4_hits"
1659
+ else
1660
+ pass "2.5.5 IPv6-only — no IPv4-only socket API or hardcoded IPv4 literal found"
1661
+ fi
1662
+ fi
1663
+
1664
+ # shellcheck source=skills/appstore-precheck/scripts/lib/scan-guidelines.sh
1665
+ source "$SCRIPT_DIR/lib/scan-guidelines.sh"
1666
+
1667
+ optin_run || exit $?
1557
1668
  echo "---END-OF-SCAN---"
1558
1669
  if [[ "$FORMAT" == text && "${_SUPPRESSED_COUNT:-0}" -gt 0 ]]; then
1559
1670
  printf '(%s finding(s) suppressed via .precheck-ignore)\n' "$_SUPPRESSED_COUNT"
1560
1671
  fi
1561
- if [[ "$FORMAT" == json ]]; then exec 1>&4 4>&-; render_json;
1672
+ if [[ "$FORMAT" == json ]]; then exec 1>&4 4>&-; render_json | coverage_run_json | optin_render_json;
1562
1673
  elif [[ "$FORMAT" == sarif ]]; then exec 1>&4 4>&-; render_sarif; fi
@@ -0,0 +1 @@
1
+ """Optional TypeSafe semantic review, independent of the deterministic scanner."""
@@ -0,0 +1,95 @@
1
+ """Stdlib HTTP client with bounded retries and strict typed-response validation."""
2
+ import json
3
+ import math
4
+ import os
5
+ import time
6
+ import urllib.error
7
+ import urllib.request
8
+
9
+ ENDPOINT = 'https://api.typesafe.ai/v1/systemone'
10
+
11
+
12
+ class ServiceError(Exception):
13
+ """Safe diagnostic: never include headers, server bodies, or the API key."""
14
+
15
+
16
+ def number(value, low=0, high=1):
17
+ return (type(value) in (int, float) and math.isfinite(value) and low <= value <= high)
18
+
19
+
20
+ def validate_response(body, request):
21
+ if not isinstance(body, dict) or body.get('model') != request['model']:
22
+ raise ServiceError('response model does not match pinned model')
23
+ answers = body.get('answers')
24
+ if not isinstance(answers, dict) or set(answers) != set(request['questions']):
25
+ raise ServiceError('missing or unexpected answers')
26
+ for key, question in request['questions'].items():
27
+ answer = answers[key]
28
+ kind = question['type']
29
+ if not isinstance(answer, dict) or answer.get('type') != kind:
30
+ raise ServiceError('answer type mismatch')
31
+ if kind == 'noul':
32
+ if not number(answer.get('noul')):
33
+ raise ServiceError('invalid Noul probability')
34
+ continue
35
+ probabilities = answer.get('probabilities')
36
+ expected = set(question['criteria']) if kind == 'choice' else {str(i) for i in range(len(question['criteria']))}
37
+ if (not isinstance(probabilities, dict) or set(probabilities) != expected
38
+ or not all(number(p) for p in probabilities.values())
39
+ or abs(sum(probabilities.values()) - 1) > 0.001
40
+ or not number(answer.get('confidence'))):
41
+ raise ServiceError('invalid probability distribution')
42
+ if kind == 'choice':
43
+ selected = answer.get('choice')
44
+ if selected not in expected or probabilities[selected] < max(probabilities.values()) - 0.00001:
45
+ raise ServiceError('invalid Choice selection')
46
+ else:
47
+ weighted = sum(int(k) * p for k, p in probabilities.items())
48
+ if (not number(answer.get('score'), 0, len(expected) - 1)
49
+ or abs(answer['score'] - weighted) > 0.001
50
+ or not isinstance(answer.get('legend'), dict)
51
+ or set(answer['legend']) != expected
52
+ or any(answer['legend'][str(i)] != label for i, label in enumerate(question['criteria']))):
53
+ raise ServiceError('invalid Score value or legend')
54
+ usage = body.get('usage')
55
+ if (not isinstance(usage, dict)
56
+ or any(type(usage.get(k)) is not int or usage[k] < 0 for k in ('input_tokens', 'output_tokens'))):
57
+ raise ServiceError('invalid token usage')
58
+ return body
59
+
60
+
61
+ class NoRedirect(urllib.request.HTTPRedirectHandler):
62
+ def redirect_request(self, req, fp, code, msg, headers, newurl):
63
+ return None # Never forward the bearer credential to another endpoint.
64
+
65
+
66
+ def evaluate(request, timeout=15, retries=2, opener=None, sleep=time.sleep, telemetry=None):
67
+ key = os.environ.get('TYPESAFE_API_KEY')
68
+ if not key:
69
+ raise ServiceError('TYPESAFE_API_KEY is not set')
70
+ opener = opener or urllib.request.build_opener(NoRedirect()).open
71
+ req = urllib.request.Request(ENDPOINT, data=json.dumps(request, ensure_ascii=False).encode(),
72
+ headers={'Authorization': 'Bearer ' + key, 'Content-Type': 'application/json'})
73
+ for attempt in range(retries + 1):
74
+ if telemetry is not None:
75
+ telemetry['attempts'] = attempt + 1
76
+ try:
77
+ with opener(req, timeout=timeout) as response:
78
+ raw = response.read(2_000_001)
79
+ if len(raw) > 2_000_000:
80
+ raise ServiceError('response exceeds size limit')
81
+ return validate_response(json.loads(raw), request)
82
+ except urllib.error.HTTPError as exc:
83
+ if exc.code not in (429, 500, 502, 503, 504, 529) or attempt == retries:
84
+ raise ServiceError('TypeSafe HTTP %d' % exc.code) from None
85
+ delay = min(2 ** attempt, 4)
86
+ try:
87
+ delay = min(max(float(exc.headers.get('Retry-After', delay)), 0), 5)
88
+ except (TypeError, ValueError):
89
+ pass
90
+ sleep(delay)
91
+ except (urllib.error.URLError, TimeoutError, OSError):
92
+ # A lost response may have been billed; do not blindly retry it.
93
+ raise ServiceError('TypeSafe transport failure') from None
94
+ except (ValueError, UnicodeDecodeError):
95
+ raise ServiceError('TypeSafe returned malformed JSON') from None