Validate Safari bundle identifiers - #609
Conversation
Greptile SummaryThis PR adds runtime validation of Safari extension bundle identifiers via a new
Confidence Score: 4/5Safe to merge; the validation logic is sound and consistently applied across both build and ship paths. The core change — guarding both entry points with packages/targets/browser-safari/src/index.ts — the Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[build / ship called with Config] --> B[requireBundleId]
B --> C{config.bundleId truthy?}
C -- No --> D["TypeError: cannot read .trim()"]
C -- Yes --> E["bundleId = config.bundleId.trim()"]
E --> F{BUNDLE_ID_PATTERN.test}
F -- Fail --> G["throw Error: reverse-DNS identifier required"]
F -- Pass --> H[validated bundleId returned]
H --> I{build path}
H --> J{ship path}
I --> K[buildPlan uses bundleId for archivePath, converter args, plan JSON]
J --> L{dryRun?}
L -- Yes --> M[return dry-run id/url]
L -- No --> N[App Store Connect lookup + xcrun upload]
Reviews (1): Last reviewed commit: "Validate Safari bundle identifiers" | Re-trigger Greptile |
| const BUNDLE_ID_PATTERN = /^[A-Za-z][A-Za-z0-9-]*(\.[A-Za-z][A-Za-z0-9-]*)+$/; | ||
|
|
||
| function requireBundleId(config: Config): string { | ||
| const bundleId = config.bundleId.trim(); |
There was a problem hiding this comment.
Unchecked
.trim() on potentially absent bundleId
config.bundleId.trim() throws a TypeError: Cannot read properties of undefined (reading 'trim') when bundleId is absent or null — even though the TypeScript interface marks it as required, callers using as any or raw JSON configs can omit it at runtime. The resulting error gives no hint about the missing field, unlike the clear reverse-DNS message you get for a malformed value. A simple truthiness guard before trim() would surface a more actionable message in that case.
| return value.replace(/[^a-zA-Z0-9._-]+/g, '-').replace(/^-|-$/g, '') || 'safari-extension'; | ||
| } | ||
|
|
||
| const BUNDLE_ID_PATTERN = /^[A-Za-z][A-Za-z0-9-]*(\.[A-Za-z][A-Za-z0-9-]*)+$/; |
There was a problem hiding this comment.
BUNDLE_ID_PATTERN rejects digit-starting DNS components
The regex anchors every component to [A-Za-z] as its first character, so a bundle ID whose reverse-DNS origin starts with a digit — e.g. com.3m.MyApp or com.3shape.Plugin — is rejected even though Apple's bundle ID specification only requires alphanumeric characters, hyphens, and periods. Relaxing the per-component first character to [A-Za-z0-9] better matches the actual spec while still blocking obviously invalid identifiers like bare names without dots or slashes.
| const BUNDLE_ID_PATTERN = /^[A-Za-z][A-Za-z0-9-]*(\.[A-Za-z][A-Za-z0-9-]*)+$/; | |
| const BUNDLE_ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9-]*(\.[A-Za-z0-9][A-Za-z0-9-]*)+$/; |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
9 similar comments
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
Fixes #608.
Changes:
Validation: