From 32bab8dcca488e45526991e8e6fe97d07f121082 Mon Sep 17 00:00:00 2001 From: lcian <17258265+lcian@users.noreply.github.com> Date: Sat, 21 Nov 2026 20:40:12 +0100 Subject: [PATCH 1/2] fix(ios): Preserve executable bits in distribution IPAs --- .../artifacts/apple/zipped_xcarchive.py | 20 +++++++++++++++++-- tests/integration/test_ipa.py | 19 +++++++++++++----- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/launchpad/artifacts/apple/zipped_xcarchive.py b/src/launchpad/artifacts/apple/zipped_xcarchive.py index af33bf54..640e8a86 100644 --- a/src/launchpad/artifacts/apple/zipped_xcarchive.py +++ b/src/launchpad/artifacts/apple/zipped_xcarchive.py @@ -1,6 +1,7 @@ import json import plistlib import shutil +import stat import subprocess import tempfile import uuid @@ -8,6 +9,7 @@ from dataclasses import dataclass from pathlib import Path from typing import Any, List, NamedTuple +from zipfile import ZipFile import lief import sentry_sdk.traces @@ -229,8 +231,22 @@ def generate_ipa(self, output_path: Path): payload_dir.mkdir() dest_app_path = payload_dir / app_bundle_path.name - # Copy the .app bundle into Payload (preserve symlinks, permissions, etc.) - shutil.copytree(app_bundle_path, dest_app_path, symlinks=True) + # ZipFile.extract creates regular files with default permissions. Carry + # only the original execute bits onto the copy made for distribution. + with ZipFile(self.path) as archive: + members = {Path(entry.filename): entry for entry in archive.infolist()} + + def copy_app_file(src: str, dst: str) -> str: + copied = shutil.copy2(src, dst) + member = members.get(Path(src).relative_to(self._extract_dir.path)) + if member is not None and member.create_system == 3: + mode = member.external_attr >> 16 + if stat.S_IFMT(mode) in (0, stat.S_IFREG) and mode & 0o111: + path = Path(copied) + path.chmod(path.stat().st_mode | (mode & 0o111)) + return copied + + shutil.copytree(app_bundle_path, dest_app_path, symlinks=True, copy_function=copy_app_file) # Create the IPA file using zip to preserve symlinks and metadata try: diff --git a/tests/integration/test_ipa.py b/tests/integration/test_ipa.py index 6138ed4d..0ce4785e 100644 --- a/tests/integration/test_ipa.py +++ b/tests/integration/test_ipa.py @@ -1,22 +1,21 @@ import subprocess -import tempfile from pathlib import Path +from zipfile import ZipFile from launchpad.artifacts.artifact_factory import ArtifactFactory class TestIPA: - def test_ipa_generation(self, hackernews_xcarchive: Path): + def test_ipa_generation(self, hackernews_xcarchive: Path, tmp_path: Path): artifact = ArtifactFactory.from_path(hackernews_xcarchive) - temp_dir = Path(tempfile.mkdtemp()) - ipa_path = temp_dir / "HackerNews.ipa" + ipa_path = tmp_path / "HackerNews.ipa" artifact.generate_ipa(ipa_path) assert ipa_path.exists() - extract_dir = temp_dir / "extracted_ipa" + extract_dir = tmp_path / "extracted_ipa" extract_dir.mkdir() try: @@ -31,3 +30,13 @@ def test_ipa_generation(self, hackernews_xcarchive: Path): payload_dir = extract_dir / "Payload" app_bundles = list(payload_dir.glob("*.app")) assert len(app_bundles) == 1, f"Expected exactly one .app bundle, found {len(app_bundles)}" + + app = app_bundles[0].relative_to(extract_dir) + with ZipFile(ipa_path) as ipa: + for executable in ( + app / "HackerNews", + app / "Frameworks/Sentry.framework/Sentry", + app / "PlugIns/HackerNewsHomeWidgetExtension.appex/HackerNewsHomeWidgetExtension", + ): + assert (ipa.getinfo(executable.as_posix()).external_attr >> 16) & 0o111 == 0o111 + assert (ipa.getinfo((app / "Info.plist").as_posix()).external_attr >> 16) & 0o111 == 0 From 27ef2fd49b6c9df91eed4d16a07bfe069fd43801 Mon Sep 17 00:00:00 2001 From: lcian <17258265+lcian@users.noreply.github.com> Date: Sat, 21 Nov 2026 21:02:41 +0100 Subject: [PATCH 2/2] fix(ios): Key IPA mode lookup through SafeDirectory Zip member names are untrusted, so resolve them against the extraction directory instead of building raw paths from them. --- src/launchpad/artifacts/apple/zipped_xcarchive.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/launchpad/artifacts/apple/zipped_xcarchive.py b/src/launchpad/artifacts/apple/zipped_xcarchive.py index 640e8a86..36961d7c 100644 --- a/src/launchpad/artifacts/apple/zipped_xcarchive.py +++ b/src/launchpad/artifacts/apple/zipped_xcarchive.py @@ -233,12 +233,13 @@ def generate_ipa(self, output_path: Path): # ZipFile.extract creates regular files with default permissions. Carry # only the original execute bits onto the copy made for distribution. + # Member names are untrusted, so key them by where they were extracted. with ZipFile(self.path) as archive: - members = {Path(entry.filename): entry for entry in archive.infolist()} + members = {self._extract_dir.resolve(entry.filename): entry for entry in archive.infolist()} def copy_app_file(src: str, dst: str) -> str: copied = shutil.copy2(src, dst) - member = members.get(Path(src).relative_to(self._extract_dir.path)) + member = members.get(Path(src)) if member is not None and member.create_system == 3: mode = member.external_attr >> 16 if stat.S_IFMT(mode) in (0, stat.S_IFREG) and mode & 0o111: