-
-
Notifications
You must be signed in to change notification settings - Fork 129
feat(cli): expand iOS pre-scan checks (plist, Xcode, entitlements, Capacitor config, pods/SPM, app icons) #2565
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
WcaleNieWolny
wants to merge
7
commits into
main
Choose a base branch
from
wolny/prescan-ios-expansion
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ccc2529
feat(cli): ios prescan parsing helpers (plist/buildsettings/entitleme…
WcaleNieWolny ef9580c
feat(cli): +33 iOS prescan checks (plist, xcode, entitlements, capaci…
WcaleNieWolny c3a3136
fix(cli): address iOS prescan expansion review findings
WcaleNieWolny beca2e9
docs(cli): iOS prescan expansion implementation-ready design spec
WcaleNieWolny cb58d7c
fix(cli): address remaining low-severity iOS prescan review findings
WcaleNieWolny 8de18d9
Merge remote-tracking branch 'origin/main' into wolny/prescan-ios-exp…
WcaleNieWolny 727c621
chore(cli): allowlist ITMS + loca typos (App Store error codes + loca…
WcaleNieWolny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // src/build/prescan/capacitor-version.ts | ||
| import { join } from 'node:path' | ||
| import { readTextIfExists } from './gradle' | ||
|
|
||
| /** | ||
| * Major version of the Capacitor runtime declared in package.json, or null. | ||
| * | ||
| * Checks `@capacitor/core` first (the platform-agnostic runtime), then the | ||
| * platform packages `@capacitor/ios` and `@capacitor/android`, so both the iOS | ||
| * and Android prescan checks resolve the same major from one shared place. | ||
| * Reads dev+prod dependencies, returns null on a missing/malformed package.json | ||
| * (never throws). | ||
| */ | ||
| export function capacitorMajor(projectDir: string): number | null { | ||
| const raw = readTextIfExists(join(projectDir, 'package.json')) | ||
| if (raw === null) | ||
| return null | ||
| let deps: Record<string, string> | ||
| try { | ||
| const pkg = JSON.parse(raw) as { dependencies?: Record<string, string>, devDependencies?: Record<string, string> } | ||
| deps = { ...pkg.devDependencies, ...pkg.dependencies } | ||
| } | ||
| catch { | ||
| return null | ||
| } | ||
| const range = deps['@capacitor/core'] ?? deps['@capacitor/ios'] ?? deps['@capacitor/android'] | ||
| if (!range) | ||
| return null | ||
| const m = range.match(/(\d+)/) | ||
| return m ? Number(m[1]) : null | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| // src/build/prescan/checks/ios-capacitor-config.ts | ||
| // | ||
| // §2.D — Capacitor config checks. These read only ctx.config (a passthrough | ||
| // zod object, so server.* is reached via safe optional access — no parser | ||
| // needed). Upload intent escalates severity for the server.url check. All | ||
| // findings name only config values, never credential material. | ||
| import type { Finding, PrescanCheck, ScanContext } from '../types' | ||
| import { willUploadToAppStore } from '../upload-intent' | ||
|
|
||
| // ctx.config is `.passthrough()`, so the server block is not in the static type. | ||
| // Read it through a narrow shape rather than re-parsing the config. | ||
| interface CapServer { | ||
| url?: unknown | ||
| cleartext?: unknown | ||
| allowNavigation?: unknown | ||
| } | ||
| function serverOf(ctx: ScanContext): CapServer | undefined { | ||
| return (ctx.config as { server?: CapServer } | undefined)?.server | ||
| } | ||
| function serverUrlOf(ctx: ScanContext): string | null { | ||
| const url = serverOf(ctx)?.url | ||
| return typeof url === 'string' && url !== '' ? url : null | ||
| } | ||
|
|
||
| // Dev-only markers that make a shipped server.url unambiguously a live-reload | ||
| // leftover rather than a deliberate production host. | ||
| const RFC1918_RE = /^https?:\/\/(?:10\.|172\.(?:1[6-9]|2\d|3[01])\.|192\.168\.)/i | ||
| const LOCALHOST_RE = /^https?:\/\/(?:localhost|127\.0\.0\.1)(?:[:/]|$)/i | ||
| const TUNNEL_RE = /^https?:\/\/[^/]*\.(?:ngrok\.io|ngrok-free\.app|trycloudflare\.com|loca\.lt)(?:[:/]|$)/i | ||
|
|
||
| /** A human-readable reason this url looks like a dev/live-reload target, or null. */ | ||
| function devTargetReason(url: string): string | null { | ||
| if (LOCALHOST_RE.test(url)) | ||
| return 'points at localhost / 127.0.0.1' | ||
| if (RFC1918_RE.test(url)) | ||
| return 'points at a private LAN IP (live-reload)' | ||
| if (TUNNEL_RE.test(url)) | ||
| return 'points at a dev tunnel host (ngrok / cloudflare / localtunnel)' | ||
| if (/^http:\/\//i.test(url)) | ||
| return 'uses cleartext http://' | ||
| return null | ||
| } | ||
|
|
||
| export const serverUrlShipped: PrescanCheck = { | ||
| id: 'ios/capacitor-server-url-shipped', | ||
| platforms: ['ios'], | ||
| appliesTo: ctx => serverUrlOf(ctx) !== null, | ||
| async run(ctx): Promise<Finding[]> { | ||
| const url = serverUrlOf(ctx) | ||
| if (url === null) | ||
| return [] | ||
| const uploading = willUploadToAppStore(ctx) | ||
| const reason = devTargetReason(url) | ||
| const detail = reason | ||
| ? `server.url=${url} (${reason}) — this ships a live-reload/remote endpoint into the build` | ||
| : `server.url=${url} — this ships a remote endpoint into the build instead of the bundled web assets` | ||
| return [{ | ||
| id: 'ios/capacitor-server-url-shipped', | ||
| severity: uploading ? 'error' : 'warning', | ||
| title: 'capacitor.config server.url is set — the build will load a remote URL instead of bundled assets', | ||
| detail, | ||
| fix: 'Remove the server.url live-reload block before a production build; build web assets and run `npx cap sync`', | ||
| }] | ||
| }, | ||
| } | ||
|
|
||
| export const serverCleartext: PrescanCheck = { | ||
| id: 'ios/capacitor-server-cleartext', | ||
| platforms: ['ios'], | ||
| appliesTo: ctx => serverOf(ctx)?.cleartext === true, | ||
| async run(ctx): Promise<Finding[]> { | ||
| if (serverOf(ctx)?.cleartext !== true) | ||
| return [] | ||
| const url = serverUrlOf(ctx) | ||
| const httpUrl = url !== null && /^http:\/\//i.test(url) | ||
| return [{ | ||
| id: 'ios/capacitor-server-cleartext', | ||
| severity: httpUrl ? 'error' : 'warning', | ||
| title: 'capacitor.config server.cleartext is enabled — arbitrary cleartext HTTP traffic is allowed', | ||
| detail: httpUrl ? `paired with a cleartext server.url (${url})` : undefined, | ||
| fix: 'Remove server.cleartext (or set it false) for production; use https or a scoped ATS exception', | ||
| }] | ||
| }, | ||
| } | ||
|
|
||
| /** A blanket `*` or public-suffix wildcard (`*.com`, `*.io`) with no specific host. */ | ||
| function isPublicWildcard(entry: string): boolean { | ||
| if (entry === '*') | ||
| return true | ||
| // `*.<single-label>` such as *.com / *.io — a wildcard with no concrete host. | ||
| // `*.example.com` (two+ labels after the dot) is a specific subdomain wildcard | ||
| // and is NOT flagged. | ||
| return /^\*\.[a-z0-9-]+$/i.test(entry) | ||
| } | ||
| function navWildcards(ctx: ScanContext): string[] { | ||
| const list = serverOf(ctx)?.allowNavigation | ||
| if (!Array.isArray(list)) | ||
| return [] | ||
| return list.filter((e): e is string => typeof e === 'string' && isPublicWildcard(e)) | ||
| } | ||
|
|
||
| export const allowNavigationWildcard: PrescanCheck = { | ||
| id: 'ios/capacitor-allow-navigation-wildcard', | ||
| platforms: ['ios'], | ||
| appliesTo: ctx => navWildcards(ctx).length > 0, | ||
| async run(ctx): Promise<Finding[]> { | ||
| const offenders = navWildcards(ctx) | ||
| if (offenders.length === 0) | ||
| return [] | ||
| return [{ | ||
| id: 'ios/capacitor-allow-navigation-wildcard', | ||
| severity: 'warning', | ||
| title: 'capacitor.config server.allowNavigation contains a blanket wildcard', | ||
| detail: `wildcard entr(y/ies): ${offenders.join(', ')}`, | ||
| fix: 'Restrict allowNavigation to specific hosts; remove blanket "*" / "*.<tld>" entries', | ||
| }] | ||
| }, | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guard non-string dependency ranges before calling
.match().On Line 29,
rangecan be a non-string whenpackage.jsonis syntactically valid but malformed (for example, numeric/object dependency values), which throws at runtime and breaks the documented "never throws" contract.Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents