Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion desktop/src-tauri/src/commerce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mod tests {
serde_json::from_str(include_str!("../tauri.app-store.conf.json")).unwrap();
assert_eq!(config["identifier"], "com.zenuml.app");
assert_eq!(config["version"], "1.1.0");
assert_eq!(config["bundle"]["macOS"]["bundleVersion"], "51");
assert_eq!(config["bundle"]["macOS"]["bundleVersion"], "52");
}
#[test]
fn app_store_does_not_advertise_external_codex_configuration_access() {
Expand Down
2 changes: 1 addition & 1 deletion desktop/src-tauri/tauri.app-store.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"createUpdaterArtifacts": false,
"macOS": {
"minimumSystemVersion": "13.5",
"bundleVersion": "51",
"bundleVersion": "52",
"entitlements": "app-store/shell.entitlements",
"infoPlist": "app-store/Info.plist"
}
Expand Down
7 changes: 5 additions & 2 deletions scripts/desktop-app-store.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const fs = require('node:fs'), path = require('node:path');
const root = fs.realpathSync(process.argv[2]), file = process.argv[3];
const audit = JSON.parse(fs.readFileSync(file, 'utf8'));
if (audit.format !== 1 || audit.bundleIdentifier !== 'com.zenuml.app' || audit.version !== '1.1.0' ||
audit.buildVersion !== '51' || !/^\d+\.\d+(?:\.\d+)?$/.test(audit.minimumSystemVersion) ||
audit.buildVersion !== '52' || !/^\d+\.\d+(?:\.\d+)?$/.test(audit.minimumSystemVersion) ||
!Array.isArray(audit.files) || !Array.isArray(audit.packages) || !Array.isArray(audit.native))
throw Error('Invalid bundle audit manifest');
const native = audit.native.map(entry => {
Expand All @@ -74,7 +74,7 @@ desktop_write_build_info() {
const fs = require('node:fs'), path = require('node:path'), crypto = require('node:crypto');
const [local, sourceSha, archive, mode, bundleIdentifier, version, buildVersion] = process.argv.slice(2);
if (!/^[a-f0-9]{40}$/.test(sourceSha)) throw Error('Exact Git source revision required');
if (bundleIdentifier !== 'com.zenuml.app' || version !== '1.1.0' || buildVersion !== '51')
if (bundleIdentifier !== 'com.zenuml.app' || version !== '1.1.0' || buildVersion !== '52')
throw Error('Unexpected ZenUML upgrade identity/version/build');
if (!['--unsigned', '--sign'].includes(mode)) throw Error('Unknown signing mode');
const sha256 = file => crypto.createHash('sha256').update(fs.readFileSync(file)).digest('hex');
Expand Down Expand Up @@ -154,6 +154,9 @@ NODE
# Optional peer suggestions include better-auth's Vitest integration. Shipping
# runtime peers (React, pg, zod) are already explicit production dependencies.
(cd "$STAGE" && bun install --production --omit peer --frozen-lockfile --ignore-scripts)
# sharp's native libvips imports a non-public CoreText function that App Review
# rejected in build 51. Ship the locked WebAssembly build of sharp instead.
"$NODE_BINARY" "$ROOT/scripts/desktop-sharp-wasm.mjs" "$STAGE/node_modules" "$STAGE/bun.lock"
ditto "$STAGE/node_modules" "$LOCAL/app/node_modules"
xcrun swiftc -O -parse-as-library -target "$(uname -m)-apple-macosx13.5" "$ROOT/desktop/scripts/FrameSnapshot.swift" -o "$APP/Contents/Helpers/DiagramlyFrameSnapshot"
desktop_run_audit "$NODE_BINARY" "$ROOT/scripts/desktop-bundle-audit.mjs" "$APP" "$OUTPUT/provenance-before-signing.json"
Expand Down
7 changes: 7 additions & 0 deletions scripts/desktop-bundle-audit.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import path from 'node:path'
import assert from 'node:assert/strict'
import { fileURLToPath } from 'node:url'

// Symbols that App Review's automatic scan reported as non-public. Build 51 was
// rejected for the first one, which sharp's bundled libvips imports from CoreText.
const NON_PUBLIC_APIS = ['_CTFontCopyDefaultCascadeList']

// Run after assembling and before signing. No network access or package code
// execution is needed. The manifest is an inventory, not a legal licence audit.
export async function auditBundle(app) {
Expand Down Expand Up @@ -72,6 +76,9 @@ export async function auditBundle(app) {
}
const magic = data.length >= 4 ? data.readUInt32BE(0) : 0
if ([0xfeedface, 0xcefaedfe, 0xfeedfacf, 0xcffaedfe, 0xcafebabe, 0xbebafeca].includes(magic)) {
for (const symbol of NON_PUBLIC_APIS) {
if (data.includes(symbol)) throw new Error(`Non-public Apple API ${symbol} referenced by ${relative}`)
}
const loadCommands = execFileSync('/usr/bin/otool', ['-l', file], { encoding: 'utf8' })
const targets = [...loadCommands.matchAll(/\bminos ([0-9.]+)/g)].map((match) => match[1])
for (const match of loadCommands.matchAll(/cmd LC_VERSION_MIN_MACOSX[\s\S]*?\n\s*version ([0-9.]+)/g))
Expand Down
29 changes: 27 additions & 2 deletions scripts/desktop-bundle-audit.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async function fixture(run) {
await mkdir(path.join(app, 'Contents', 'Resources'), { recursive: true })
await writeFile(
path.join(app, 'Contents/Info.plist'),
'<plist version="1.0"><dict><key>CFBundleIdentifier</key><string>com.zenuml.app</string><key>CFBundleShortVersionString</key><string>1.1.0</string><key>CFBundleVersion</key><string>51</string><key>LSMinimumSystemVersion</key><string>13.5</string></dict></plist>',
'<plist version="1.0"><dict><key>CFBundleIdentifier</key><string>com.zenuml.app</string><key>CFBundleShortVersionString</key><string>1.1.0</string><key>CFBundleVersion</key><string>52</string><key>LSMinimumSystemVersion</key><string>13.5</string></dict></plist>',
)
await run(app, temporary)
} finally {
Expand Down Expand Up @@ -131,12 +131,37 @@ test('rejects native code requiring an OS newer than the app declares', () =>
await assert.rejects(auditBundle(app), /requires macOS 15.*declares 13.5/)
}))

test('rejects a native library that imports a non-public Apple API', () =>
fixture(async (app) => {
const file = path.join(app, 'Contents/Resources/local-server/app/node_modules/vendor/libprivate.dylib')
await mkdir(path.dirname(file), { recursive: true })
execFileSync(
'/usr/bin/xcrun',
[
'clang',
'-mmacosx-version-min=13.5',
'-dynamiclib',
'-x',
'c',
'-',
'-Wl,-undefined,dynamic_lookup',
'-o',
file,
],
{
input:
'extern void *CTFontCopyDefaultCascadeList(void *, void *); int fixture(void) { return CTFontCopyDefaultCascadeList(0, 0) != 0; }',
},
)
await assert.rejects(auditBundle(app), /Non-public Apple API _CTFontCopyDefaultCascadeList.*libprivate\.dylib/)
}))

test('requires the existing paid app identity and records upgrade version', () =>
fixture(async (app) => {
const result = await auditBundle(app)
assert.equal(result.bundleIdentifier, 'com.zenuml.app')
assert.equal(result.version, '1.1.0')
assert.equal(result.buildVersion, '51')
assert.equal(result.buildVersion, '52')
await writeFile(
path.join(app, 'Contents/Info.plist'),
'<plist version="1.0"><dict><key>CFBundleIdentifier</key><string>ai.diagramly.desktop</string></dict></plist>',
Expand Down
11 changes: 6 additions & 5 deletions scripts/desktop-packaging.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ test('records actual app identity, exact source/archive and Node metadata for bo
await mkdir(local, { recursive: true })
await writeFile(
path.join(app, 'Contents/Info.plist'),
'<plist version="1.0"><dict><key>CFBundleIdentifier</key><string>com.zenuml.app</string><key>CFBundleShortVersionString</key><string>1.1.0</string><key>CFBundleVersion</key><string>51</string></dict></plist>',
'<plist version="1.0"><dict><key>CFBundleIdentifier</key><string>com.zenuml.app</string><key>CFBundleShortVersionString</key><string>1.1.0</string><key>CFBundleVersion</key><string>52</string></dict></plist>',
)
await writeFile(path.join(local, 'node'), 'fixture distribution executable before signing')
const licenseSource = path.join(temporary, 'LICENSE')
Expand All @@ -111,7 +111,7 @@ test('records actual app identity, exact source/archive and Node metadata for bo
assert.equal(info.sourceArchiveSha256, sha256(await readFile(archive)))
assert.equal(info.bundleIdentifier, 'com.zenuml.app')
assert.equal(info.version, '1.1.0')
assert.equal(info.buildVersion, '51')
assert.equal(info.buildVersion, '52')
assert.equal(info.nodeVersion, process.version)
assert.equal(info.nodeLicenseSha256, sha256(await readFile(licenseSource)))
assert.equal(info.adhoc, mode === '--unsigned')
Expand All @@ -124,7 +124,7 @@ test('records actual app identity, exact source/archive and Node metadata for bo
}
await writeFile(
path.join(app, 'Contents/Info.plist'),
'<plist version="1.0"><dict><key>CFBundleIdentifier</key><string>ai.diagramly.desktop</string><key>CFBundleShortVersionString</key><string>1.1.0</string><key>CFBundleVersion</key><string>51</string></dict></plist>',
'<plist version="1.0"><dict><key>CFBundleIdentifier</key><string>ai.diagramly.desktop</string><key>CFBundleShortVersionString</key><string>1.1.0</string><key>CFBundleVersion</key><string>52</string></dict></plist>',
)
assert.throws(
() => run('desktop_write_build_info', process.execPath, local, app, revision, archive, '--unsigned'),
Expand Down Expand Up @@ -173,6 +173,7 @@ test('the packaging command stops before signing when an audit exits zero withou
await mkdir(directory, { recursive: true })
await copyFile(script, path.join(scriptDirectory, 'desktop-app-store.sh'))
await writeFile(path.join(scriptDirectory, 'desktop-bundle-audit.mjs'), 'process.exit(0)')
await writeFile(path.join(scriptDirectory, 'desktop-sharp-wasm.mjs'), 'process.exit(0)')
await writeFile(path.join(entitlements, 'shell.entitlements'), '<plist version="1.0"><dict/></plist>')
for (const file of ['package.json', 'bun.lock', 'tsconfig.json', 'LICENSE'])
await writeFile(path.join(checkout, file), file === 'package.json' ? '{}' : 'fixture')
Expand Down Expand Up @@ -205,7 +206,7 @@ test('the packaging command stops before signing when an audit exits zero withou
await mkdir(path.join(target, 'release/bundle/macos/ZenUML.app/Contents'), { recursive: true })
await writeFile(
path.join(target, 'release/bundle/macos/ZenUML.app/Contents/Info.plist'),
'<plist version="1.0"><dict><key>CFBundleIdentifier</key><string>com.zenuml.app</string><key>CFBundleShortVersionString</key><string>1.1.0</string><key>CFBundleVersion</key><string>51</string></dict></plist>',
'<plist version="1.0"><dict><key>CFBundleIdentifier</key><string>com.zenuml.app</string><key>CFBundleShortVersionString</key><string>1.1.0</string><key>CFBundleVersion</key><string>52</string></dict></plist>',
)
await writeFile(path.join(mocks, 'bunx'), '#!/bin/sh\nexit 0\n', { mode: 0o700 })
await writeFile(
Expand Down Expand Up @@ -251,7 +252,7 @@ test('foreground audit parsing rejects execution errors, malformed or incomplete
format: 1,
bundleIdentifier: 'com.zenuml.app',
version: '1.1.0',
buildVersion: '51',
buildVersion: '52',
minimumSystemVersion: '13.5',
files: [],
packages: [],
Expand Down
74 changes: 74 additions & 0 deletions scripts/desktop-sharp-wasm.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { createHash } from 'node:crypto'
import { execFileSync } from 'node:child_process'
import assert from 'node:assert/strict'
import { mkdir, mkdtemp, readdir, readFile, realpath, rename, rm, writeFile } from 'node:fs/promises'
import os from 'node:os'
import path from 'node:path'
import { fileURLToPath } from 'node:url'

// The Mac App Store build must not ship sharp's native libvips: it imports the
// non-public CoreText function _CTFontCopyDefaultCascadeList, and App Review
// rejected build 51 for it. sharp falls back to its WebAssembly build when no
// native package is present. bun cannot select that build (its cpu is "wasm32"),
// so this step runs after `bun install` in the staging directory. It fetches the
// two packages pinned in bun.lock and checks their sha512 against the lockfile.
const WASM_PACKAGES = ['@img/sharp-wasm32', '@emnapi/runtime']

function locked(lockText, name) {
const escaped = name.replace(/[/@]/g, '\\$&')
const match = lockText.match(new RegExp(`"${escaped}": \\["(${escaped}@[^"]+)",[^\\n]*?"(sha512-[^"]+)"\\]`))
if (!match) throw new Error(`Lockfile has no locked entry for ${name}`)
return { spec: match[1], integrity: match[2] }
}

async function registryTarball(spec) {
const at = spec.lastIndexOf('@')
const name = spec.slice(0, at)
const version = spec.slice(at + 1)
const base = name.split('/').pop()
const response = await fetch(`https://registry.npmjs.org/${name}/-/${base}-${version}.tgz`)
if (!response.ok) throw new Error(`Download failed for ${spec}: ${response.status}`)
return Buffer.from(await response.arrayBuffer())
}

export async function useSharpWasm({ nodeModules, lock, fetchTarball = registryTarball }) {
const lockText = await readFile(lock, 'utf8')
const work = await mkdtemp(path.join(os.tmpdir(), 'diagramly-sharp-wasm-'))
try {
const staged = []
for (const name of WASM_PACKAGES) {
const { spec, integrity } = locked(lockText, name)
const bytes = await fetchTarball(spec)
const actual = 'sha512-' + createHash('sha512').update(bytes).digest('base64')
if (actual !== integrity) throw new Error(`Integrity mismatch for ${spec}`)
const archive = path.join(work, `${staged.length}.tgz`)
const unpacked = path.join(work, `unpacked-${staged.length}`)
await mkdir(unpacked, { recursive: true })
await writeFile(archive, bytes)
execFileSync('/usr/bin/tar', ['xzf', archive, '-C', unpacked, '--no-same-owner'])
staged.push({ name, from: path.join(unpacked, 'package') })
}
// Everything downloaded and verified: only now change the install.
for (const entry of await readdir(path.join(nodeModules, '@img'))) {
if (/^sharp-(?:libvips-)?(?:darwin|linux|win32|linuxmusl)/.test(entry))
await rm(path.join(nodeModules, '@img', entry), { recursive: true, force: true })
}
for (const { name, from } of staged) {
const target = path.join(nodeModules, name)
await rm(target, { recursive: true, force: true })
await mkdir(path.dirname(target), { recursive: true })
await rename(from, target).catch(() => {
execFileSync('/bin/cp', ['-R', from, target])
})
}
} finally {
await rm(work, { recursive: true, force: true })
}
}

const entry = process.argv[1] ? await realpath(process.argv[1]).catch(() => null) : null
if (entry === (await realpath(fileURLToPath(import.meta.url)))) {
assert(process.argv[2] && process.argv[3], 'Usage: node scripts/desktop-sharp-wasm.mjs <node_modules> <bun.lock>')
await useSharpWasm({ nodeModules: process.argv[2], lock: process.argv[3] })
console.log('sharp: native libvips removed, locked WebAssembly build installed')
}
84 changes: 84 additions & 0 deletions scripts/desktop-sharp-wasm.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import assert from 'node:assert/strict'
import { createHash } from 'node:crypto'
import { execFileSync } from 'node:child_process'
import { mkdtemp, mkdir, readFile, rm, writeFile } from 'node:fs/promises'
import { existsSync } from 'node:fs'
import os from 'node:os'
import path from 'node:path'
import test from 'node:test'
import { useSharpWasm } from './desktop-sharp-wasm.mjs'

async function tarball(directory, name, version) {
const source = path.join(directory, `pack-${name.replace('/', '-')}`)
await mkdir(path.join(source, 'package'), { recursive: true })
await writeFile(path.join(source, 'package/package.json'), JSON.stringify({ name, version }))
await writeFile(path.join(source, 'package/index.js'), 'module.exports = {}')
const file = `${source}.tgz`
execFileSync('/usr/bin/tar', ['czf', file, '-C', source, 'package'])
const bytes = await readFile(file)
return { bytes, integrity: 'sha512-' + createHash('sha512').update(bytes).digest('base64') }
}

async function fixture(run) {
const temporary = await mkdtemp(path.join(os.tmpdir(), 'diagramly-sharp-wasm-'))
try {
const modules = path.join(temporary, 'node_modules')
for (const native of [
'@img/sharp-darwin-arm64',
'@img/sharp-libvips-darwin-arm64',
'@img/sharp-libvips-darwin-x64',
])
await mkdir(path.join(modules, native), { recursive: true })
await mkdir(path.join(modules, 'sharp'), { recursive: true })
await mkdir(path.join(modules, 'tslib'), { recursive: true })
const wasm = await tarball(temporary, '@img/sharp-wasm32', '0.34.3')
const emnapi = await tarball(temporary, '@emnapi/runtime', '1.11.3')
const lock = path.join(temporary, 'bun.lock')
await writeFile(
lock,
`{
"packages": {
"@emnapi/runtime": ["@emnapi/runtime@1.11.3", "", { "dependencies": { "tslib": "^2.4.0" } }, "${emnapi.integrity}"],
"@img/sharp-wasm32": ["@img/sharp-wasm32@0.34.3", "", { "dependencies": { "@emnapi/runtime": "^1.4.4" }, "cpu": "none" }, "${wasm.integrity}"],
}
}
`,
)
const bodies = {
'@img/sharp-wasm32@0.34.3': wasm.bytes,
'@emnapi/runtime@1.11.3': emnapi.bytes,
}
await run({ modules, lock, fetchTarball: async (spec) => bodies[spec], bodies })
} finally {
await rm(temporary, { recursive: true, force: true })
}
}

test('replaces native libvips with the locked WebAssembly build', () =>
fixture(async ({ modules, lock, fetchTarball }) => {
await useSharpWasm({ nodeModules: modules, lock, fetchTarball })
assert.ok(existsSync(path.join(modules, '@img/sharp-wasm32/index.js')))
assert.ok(existsSync(path.join(modules, '@emnapi/runtime/index.js')))
assert.ok(!existsSync(path.join(modules, '@img/sharp-darwin-arm64')))
assert.ok(!existsSync(path.join(modules, '@img/sharp-libvips-darwin-arm64')))
assert.ok(!existsSync(path.join(modules, '@img/sharp-libvips-darwin-x64')))
}))

test('rejects a tarball that does not match the lockfile', () =>
fixture(async ({ modules, lock, bodies }) => {
const tampered = async () => Buffer.concat([bodies['@img/sharp-wasm32@0.34.3'], Buffer.from('x')])
await assert.rejects(useSharpWasm({ nodeModules: modules, lock, fetchTarball: tampered }), /Integrity mismatch/)
assert.ok(
existsSync(path.join(modules, '@img/sharp-libvips-darwin-arm64')),
'native files stay when the swap fails',
)
}))

test('fails when the lockfile has no WebAssembly entry', () =>
fixture(async ({ modules, lock, fetchTarball }) => {
await writeFile(lock, '{ "packages": {} }')
await assert.rejects(
useSharpWasm({ nodeModules: modules, lock, fetchTarball }),
/no locked entry for @img\/sharp-wasm32/,
)
}))
Loading