Sanitize Android artifact filenames#551
Conversation
Greptile SummaryThis PR sanitizes user-supplied
Confidence Score: 4/5Safe to merge; the core path-traversal fix is correct and well-tested, and all four targets pass their expanded test suites. The safeFileStem function omits underscore from its preserved-character set, so a valid Android package name like com.example.my_app silently becomes com.example.my-app in the artifact filename. Two distinct package names could map to the same filename once Gradle actually writes the .aab. The rest of the changes are straightforward and low-risk. packages/targets/mobile-android/src/index.ts — the safeFileStem character set warrants a second look regarding underscore handling. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[User-supplied config] --> B{Target}
B --> AND[mobile-android build]
B --> FLAT[pkg-flatpak build/ship]
B --> SNAP[pkg-snap build/ship]
B --> WIN[pkg-winget build/ship]
AND --> SF[safeFileStem strips path separators and unsafe chars]
SF --> ART[join outDir with sanitized stem produces safe artifact path]
FLAT --> VA[validateAppId checks path chars, segment count, letter-leading regex]
VA -->|valid| FM[Write .yml manifest]
VA -->|invalid| ERR1[throw Error]
SNAP --> VS[validateSnapName checks length, hyphens, consecutive hyphens, charset]
VS -->|valid| SM[Write snapcraft.yaml]
VS -->|invalid| ERR2[throw Error]
WIN --> VP[validatePackageId checks leading/trailing dots, segment count, charset]
VP -->|valid| WM[Write winget manifests]
VP -->|invalid| ERR3[throw Error]
Reviews (1): Last reviewed commit: "Sanitize Android artifact filenames" | Re-trigger Greptile |
| function safeFileStem(value: string): string { | ||
| return value | ||
| .replace(/[^a-zA-Z0-9._-]+/g, '-') |
There was a problem hiding this comment.
Underscore (
_) is a valid character in Android package names (e.g., com.example.my_app) but is not in the preserved set, so it gets silently replaced with -. Two distinct package names — com.example.my_app and com.example.my-app — would produce identical filenames and could overwrite each other once Gradle actually writes the .aab.
| function safeFileStem(value: string): string { | |
| return value | |
| .replace(/[^a-zA-Z0-9._-]+/g, '-') | |
| function safeFileStem(value: string): string { | |
| return value | |
| .replace(/[^a-zA-Z0-9._\-_]+/g, '-') |
Summary
mobile-androidpackage/version values before using them in local.aabartifact filenamesctx.outDirFixes #550.
Verification