Skip to content

Formerly KrillinAI, VideoTranslation and Dubbing Tool for 120+ Languages. Open-source AI workspace for creators, powered by Codex. Video downloader, video translation, create videos, images, audios, and edits with Agents in one place. For your Social Media like YouTube, TikTok, Instagram, etc.

fix(desktop): grant signed Remotion browser JIT permissions and verify clean quit

Leggettf9ee01008ce5
diff --git a/apps/desktop/e2e/desktop.spec.ts b/apps/desktop/e2e/desktop.spec.ts
index 499f9e0f..afb2735e 100644
--- a/apps/desktop/e2e/desktop.spec.ts
+++ b/apps/desktop/e2e/desktop.spec.ts
@@ -32,6 +32,7 @@ import {
launchPackagedApp,
launchSecondInstance,
relaunchPackagedApp,
+ requestPackagedAppQuit,
waitForProcessExit,
type PackagedApp
} from './packaged-app.js';
@@ -1104,10 +1105,9 @@ test('@package-smoke 退出期间会回收仍在 Probe 中的 Codex 子进程',
const codexPid = Number(readFileSync(pidPath, 'utf8'));
expect(isProcessAlive(codexPid)).toBe(true);
- await fixture.page.evaluate(() => {
- void window.opencreatorDesktop?.quit();
- });
+ await requestPackagedAppQuit(fixture);
expect(await waitForProcessExit(fixture.process, 15_000)).toBe(true);
+ expect(fixture.process.exitCode).toBe(0);
await expect.poll(() => isProcessAlive(codexPid), { timeout: 15_000 }).toBe(false);
} finally {
await closeFixture(fixture);
@@ -1126,11 +1126,10 @@ test('@package-smoke 启动 Codex app-server 后在 3 秒内退出', async () =>
expect(models.status).toBe(200);
const startedAt = Date.now();
- await fixture.page.evaluate(() => {
- void window.opencreatorDesktop?.quit();
- });
+ await requestPackagedAppQuit(fixture);
expect(await waitForProcessExit(fixture.process, 3_000)).toBe(true);
+ expect(fixture.process.exitCode).toBe(0);
expect(Date.now() - startedAt).toBeLessThan(3_000);
} finally {
await closeFixture(fixture);
diff --git a/apps/desktop/e2e/packaged-app.ts b/apps/desktop/e2e/packaged-app.ts
index b04c14ef..2d71ac30 100644
--- a/apps/desktop/e2e/packaged-app.ts
+++ b/apps/desktop/e2e/packaged-app.ts
@@ -101,14 +101,28 @@ export async function waitForPackagedPage(
}
export async function closePackagedApp(app: PackagedApp): Promise<void> {
- await app.page.evaluate(() => {
- void window.opencreatorDesktop?.quit();
- }).catch(() => undefined);
+ await requestPackagedAppQuit(app).catch(() => undefined);
const exited = await waitForProcessExit(app.process, 8_000);
if (!exited) await terminateProcessTree(app.process);
await app.browser.close().catch(() => undefined);
}
+export async function requestPackagedAppQuit(app: PackagedApp): Promise<void> {
+ try {
+ await app.page.evaluate(() => {
+ if (!window.opencreatorDesktop) throw new Error('Desktop quit bridge is unavailable');
+ void window.opencreatorDesktop.quit();
+ });
+ } catch (error) {
+ // A successful quit can close CDP before evaluate's response arrives.
+ // Only accept that error after a clean native process exit.
+ if (!(error instanceof Error)
+ || !error.message.includes('Target page, context or browser has been closed')
+ || !await waitForProcessExit(app.process, 1_000)
+ || app.process.exitCode !== 0) throw error;
+ }
+}
+
export async function waitForProcessExit(
child: ChildProcess,
timeoutMs: number
diff --git a/apps/desktop/scripts/sign-creator-runtime-after-pack.mjs b/apps/desktop/scripts/sign-creator-runtime-after-pack.mjs
index 7750e35a..5b1c12ce 100644
--- a/apps/desktop/scripts/sign-creator-runtime-after-pack.mjs
+++ b/apps/desktop/scripts/sign-creator-runtime-after-pack.mjs
@@ -9,7 +9,8 @@ import {
writeFileSync
} from 'node:fs';
import { createHash } from 'node:crypto';
-import { join, relative } from 'node:path';
+import { join, relative, resolve } from 'node:path';
+import { fileURLToPath } from 'node:url';
import { spawnSync } from 'node:child_process';
import { verifyCreatorRuntime } from './creator-runtime-contract.mjs';
import { verifyStickmanRuntime } from './stickman-runtime-contract.mjs';
@@ -27,6 +28,10 @@ const machOMagicValues = new Set([
'bfbafeca'
]);
+const remotionBrowserEntitlements = fileURLToPath(
+ new URL('../resources/entitlements.mac.plist', import.meta.url)
+);
+
export async function afterPack(context) {
await prepareMacAppIcon(context);
if (process.env.OPENCREATOR_SIGN_CREATOR_RUNTIME !== '1') return;
@@ -43,7 +48,18 @@ export async function signRemotionComponent(runtimeRoot, env = process.env, opti
|| (options.findIdentity ?? findSigningIdentity)(signingEnv.OPENCREATOR_APPLE_TEAM_ID, keychainFile);
const binaries = (options.findBinaries ?? findMachOBinaries)(runtimeRoot);
if (binaries.length === 0) throw new Error('Remotion component has no native binaries');
- for (const path of binaries) await (options.signBinary ?? signMachOBinary)(path, identity, keychainFile);
+ const manifest = JSON.parse(readFileSync(join(runtimeRoot, 'manifest.json'), 'utf8'));
+ const browserExecutable = resolve(runtimeRoot, manifest.browserExecutable);
+ const signBinary = options.signBinary ?? signMachOBinary;
+ for (const path of binaries) {
+ // Chromium's V8 needs JIT permissions when hardened runtime is enabled.
+ // Keep these permissions scoped to the browser executable.
+ if (resolve(path) === browserExecutable) {
+ await signBinary(path, identity, keychainFile, remotionBrowserEntitlements);
+ } else {
+ await signBinary(path, identity, keychainFile);
+ }
+ }
updateManifestHashes(runtimeRoot, binaries);
});
}
@@ -172,7 +188,7 @@ function listSigningIdentities(keychainFile) {
return result.stdout;
}
-function signMachOBinary(path, identity, keychainFile) {
+function signMachOBinary(path, identity, keychainFile, entitlementsPath) {
const args = [
'--force',
'--timestamp',
@@ -182,6 +198,7 @@ function signMachOBinary(path, identity, keychainFile) {
identity
];
if (keychainFile) args.push('--keychain', keychainFile);
+ if (entitlementsPath) args.push('--entitlements', entitlementsPath);
args.push(path);
const result = spawnSync('codesign', args, {
encoding: 'utf8',
diff --git a/apps/desktop/test/creator-runtime-signing.test.mjs b/apps/desktop/test/creator-runtime-signing.test.mjs
index 27655b0b..20c3ad8d 100644
--- a/apps/desktop/test/creator-runtime-signing.test.mjs
+++ b/apps/desktop/test/creator-runtime-signing.test.mjs
@@ -40,7 +40,29 @@ describe('Creator Runtime Developer ID signing', () => {
}, { platform: 'darwin', withKeychain, findIdentity, findBinaries: () => fixture.binaryPaths, signBinary });
expect(withKeychain).toHaveBeenCalledTimes(1);
expect(findIdentity).toHaveBeenCalledWith('NVRH5R5DJ5', '/tmp/component-test.keychain');
- expect(signBinary).toHaveBeenCalledWith(fixture.binaryPaths[0], 'Developer ID Application: Junxi YIN (NVRH5R5DJ5)', '/tmp/component-test.keychain');
+ const browserCall = signBinary.mock.calls.find(([path]) => path === fixture.binaryPaths[0]);
+ expect(browserCall.slice(0, 3)).toEqual([fixture.binaryPaths[0], 'Developer ID Application: Junxi YIN (NVRH5R5DJ5)', '/tmp/component-test.keychain']);
+ const entitlements = readFileSync(browserCall[3], 'utf8');
+ expect(entitlements).toMatch(/com\.apple\.security\.cs\.allow-jit<\/key>\s*<true\/>/);
+ expect(entitlements).toMatch(/com\.apple\.security\.cs\.allow-unsigned-executable-memory<\/key>\s*<true\/>/);
+ expect(entitlements).toMatch(/com\.apple\.security\.cs\.disable-library-validation<\/key>\s*<false\/>/);
+ expect(() => verifyStickmanRuntime(fixture.runtimeRoot, 'darwin', 'arm64')).not.toThrow();
+ });
+
+ it('does not grant browser JIT permissions to other Remotion native binaries', async () => {
+ const fixture = createStickmanFixture();
+ const compositor = join(fixture.runtimeRoot, 'node_modules', 'compositor', 'ffmpeg');
+ mkdirSync(dirname(compositor), { recursive: true });
+ writeFileSync(compositor, 'ffmpeg');
+ const manifestPath = join(fixture.runtimeRoot, 'manifest.json');
+ const manifest = JSON.parse(readFileSync(manifestPath, 'utf8'));
+ manifest.resources.push({ ...manifest.resources.find(resource => resource.kind === 'browser'), path: relative(fixture.runtimeRoot, compositor).replaceAll('\\', '/'), kind: 'renderer', sha256: hashFile(compositor), bytes: readFileSync(compositor).length });
+ writeFileSync(manifestPath, JSON.stringify(manifest));
+ const signBinary = vi.fn();
+ await signRemotionComponent(fixture.runtimeRoot, {
+ ...signingEnv(), OPENCREATOR_SIGN_CREATOR_RUNTIME: '1', APPLE_KEYCHAIN: '/tmp/component-test.keychain'
+ }, { platform: 'darwin', findIdentity: () => 'test-identity', findBinaries: () => [...fixture.binaryPaths, compositor], signBinary });
+ expect(signBinary).toHaveBeenCalledWith(compositor, 'test-identity', '/tmp/component-test.keychain');
expect(() => verifyStickmanRuntime(fixture.runtimeRoot, 'darwin', 'arm64')).not.toThrow();
});