Skip to content

Free fork of NotProton: Windows Steam games in Mac Steam, on CodeWeavers' Wine and Apple's Game Porting Toolkit

fix(security): stop an engine or clone install when quarantine can't be cleared (#1637)

Raymond Chin63b754871ac5
diff --git a/app/Sources/BridgeplayApp/Model/FreeEngine.swift b/app/Sources/BridgeplayApp/Model/FreeEngine.swift
index 28f7e2b..7e22feb 100644
--- a/app/Sources/BridgeplayApp/Model/FreeEngine.swift
+++ b/app/Sources/BridgeplayApp/Model/FreeEngine.swift
@@ -308,7 +308,7 @@ enum FreeEngine {
]
let plist = try PropertyListSerialization.data(fromPropertyList: info, format: .xml, options: 0)
try plist.write(to: shaped.appending(path: "Contents/Info.plist"))
- RunnerInstaller.clearQuarantine(at: shaped)
+ try RunnerInstaller.clearQuarantine(at: shaped)
let install = CrossOverSource.inspect(bundle: shaped)
guard case .supported(let build) = install.support, build.id == release.build else {
diff --git a/app/Sources/BridgeplayApp/Model/FreeEngineWinecx.swift b/app/Sources/BridgeplayApp/Model/FreeEngineWinecx.swift
index fb5c182..84d684b 100644
--- a/app/Sources/BridgeplayApp/Model/FreeEngineWinecx.swift
+++ b/app/Sources/BridgeplayApp/Model/FreeEngineWinecx.swift
@@ -535,7 +535,7 @@ enum FreeEngineWinecx {
]
let plist = try PropertyListSerialization.data(fromPropertyList: info, format: .xml, options: 0)
try plist.write(to: shaped.appending(path: "Contents/Info.plist"))
- RunnerInstaller.clearQuarantine(at: shaped)
+ try RunnerInstaller.clearQuarantine(at: shaped)
let install = CrossOverSource.inspect(bundle: shaped)
guard case .supported(let build) = install.support, build.id == release.build else {
diff --git a/app/Sources/BridgeplayApp/Model/RunnerInstaller.swift b/app/Sources/BridgeplayApp/Model/RunnerInstaller.swift
index a5fa0b1..6b8f4c9 100644
--- a/app/Sources/BridgeplayApp/Model/RunnerInstaller.swift
+++ b/app/Sources/BridgeplayApp/Model/RunnerInstaller.swift
@@ -33,7 +33,7 @@ enum RunnerInstaller {
defer { try? fm.removeItem(at: staging) }
try copyPayload(from: install.crossOverRoot, to: staging)
try verifyClone(build: build, root: staging.appending(path: "CrossOver"))
- clearQuarantine(at: staging.appending(path: "CrossOver"))
+ try clearQuarantine(at: staging.appending(path: "CrossOver"))
guard occupied else {
try fm.moveItem(at: staging, to: target)
return build
@@ -287,9 +287,10 @@ enum RunnerInstaller {
// from pinned archives. A browser-downloaded CrossOver, or an engine archive that came in
// a browser-downloaded installer zip (tar passes the flag on), leaves quarantine on files
// Bridgeplay patches and signs ad hoc, and macOS then refuses to load them. -s keeps xattr
- // on the links themselves, so a link in the tree can't clear a file outside it.
- static func clearQuarantine(at tree: URL) {
- _ = try? Shell.run("/usr/bin/xattr", ["-r", "-s", "-d", "com.apple.quarantine", tree.path(percentEncoded: false)])
+ // on the links themselves, so a link in the tree can't clear a file outside it. xattr exits
+ // 0 for files that never had the flag, so a failure here means some file still has it.
+ static func clearQuarantine(at tree: URL) throws {
+ _ = try Shell.check("/usr/bin/xattr", ["-r", "-s", "-d", "com.apple.quarantine", tree.path(percentEncoded: false)])
}
static func verifyClone(build: RunnerBuild, root: URL) throws {
diff --git a/app/Tests/BridgeplayAppTests/RunnerInstallerTests.swift b/app/Tests/BridgeplayAppTests/RunnerInstallerTests.swift
index 40b5197..5686c32 100644
--- a/app/Tests/BridgeplayAppTests/RunnerInstallerTests.swift
+++ b/app/Tests/BridgeplayAppTests/RunnerInstallerTests.swift
@@ -48,7 +48,7 @@ struct RunnerInstallerTests {
try Shell.check("/usr/bin/xattr", ["-w", "com.apple.quarantine", "0083;6a2b3c4d;Safari;", file.path(percentEncoded: false)])
try Shell.check("/usr/bin/xattr", ["-w", "com.bridgeplay.keep", "1", file.path(percentEncoded: false)])
- RunnerInstaller.clearQuarantine(at: runners)
+ try RunnerInstaller.clearQuarantine(at: runners)
let left = try Shell.run("/usr/bin/xattr", [file.path(percentEncoded: false)]).stdout
#expect(!left.contains("com.apple.quarantine"))
@@ -73,7 +73,7 @@ struct RunnerInstallerTests {
try FileManager.default.createSymbolicLink(at: tree.appending(path: "dir"), withDestinationURL: outside)
try FileManager.default.createSymbolicLink(at: tree.appending(path: "file.dylib"), withDestinationURL: lonelyFile)
- RunnerInstaller.clearQuarantine(at: tree)
+ try RunnerInstaller.clearQuarantine(at: tree)
for target in [outside, outsideFile, lonelyFile] {
let left = try Shell.run("/usr/bin/xattr", [target.path(percentEncoded: false)]).stdout
@@ -81,6 +81,24 @@ struct RunnerInstallerTests {
}
}
+ @Test("A file whose quarantine can't be cleared fails the step")
+ func clearQuarantineReportsFailure() throws {
+ let runners = try makeRunners()
+ let locked = runners.appending(path: "lib")
+ defer {
+ _ = try? Shell.run("/bin/chmod", ["-R", "u+w", runners.path(percentEncoded: false)])
+ try? FileManager.default.removeItem(at: runners)
+ }
+ let file = locked.appending(path: "winemetal.so")
+ try FileManager.default.createDirectory(at: locked, withIntermediateDirectories: true)
+ try Data("so".utf8).write(to: file)
+ try Shell.check("/usr/bin/xattr", ["-w", "com.apple.quarantine", "0083;6a2b3c4d;Safari;", file.path(percentEncoded: false)])
+ try Shell.check("/bin/chmod", ["444", file.path(percentEncoded: false)])
+ try Shell.check("/bin/chmod", ["555", locked.path(percentEncoded: false)])
+
+ #expect(throws: CommandFailure.self) { try RunnerInstaller.clearQuarantine(at: runners) }
+ }
+
// A CrossOver bundle holding only the files the clone path hashes, with the build describing
// those exact bytes, so verification passes without a real 1.2G install to copy.
private func makeSupportedInstall(