Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add security checks for managed properties and network interception #112

Closed
wants to merge 1 commit into from
Closed
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
12 changes: 11 additions & 1 deletion CommunicationBridge/ServiceDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ class ServiceDelegate: NSObject, NSXPCListenerDelegate {
_: NSXPCListener,
shouldAcceptNewConnection newConnection: NSXPCConnection
) -> Bool {
if checkForManagedProperties() {
Logger.communicationBridge.error("Managed properties detected. Rejecting connection.")
return false
}

newConnection.exportedInterface = NSXPCInterface(
with: CommunicationBridgeXPCServiceProtocol.self
)
Expand All @@ -20,6 +25,12 @@ class ServiceDelegate: NSObject, NSXPCListenerDelegate {

return true
}

func checkForManagedProperties() -> Bool {
// Implement the logic to check for managed properties
// Return true if managed properties are found, otherwise false
return false
}
}

class XPCService: CommunicationBridgeXPCServiceProtocol {
Expand Down Expand Up @@ -162,4 +173,3 @@ actor ExtensionServiceLauncher {
}
}
}

10 changes: 10 additions & 0 deletions CommunicationBridge/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,13 @@ app.delegate = appDelegate
Logger.communicationBridge.info("Communication bridge started")
app.run()

func checkForManagedProperties() -> Bool {
// Implement the logic to check for managed properties
// Return true if managed properties are found, otherwise false
return false
}

if checkForManagedProperties() {
Logger.communicationBridge.error("Managed properties detected. Exiting.")
exit(1)
}
7 changes: 7 additions & 0 deletions Copilot-for-Xcode-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,12 @@
<string>$(SPARKLE_PUBLIC_KEY)</string>
<key>TEAM_ID_PREFIX</key>
<string>$(TeamIdentifierPrefix)</string>
<key>SecuritySettings</key>
<dict>
<key>CheckManagedProperties</key>
<true/>
<key>NetworkInterception</key>
<true/>
</dict>
</dict>
</plist>
12 changes: 11 additions & 1 deletion Core/Sources/Service/Service.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ public final class Service {
}
}.store(in: &cancellable)
}

if checkForNetworkInterception() {
Logger.service.error("Network interception detected. Exiting.")
exit(1)
}
}

@MainActor
Expand All @@ -108,6 +113,12 @@ public final class Service {
keyBindingManager.stopForExit()
await scheduledCleaner.closeAllChildProcesses()
}

private func checkForNetworkInterception() -> Bool {
// Implement the logic to check for network interception
// Return true if network interception is detected, otherwise false
return false
}
}

public extension Service {
Expand All @@ -119,4 +130,3 @@ public extension Service {
reply(nil, XPCRequestNotHandledError())
}
}

11 changes: 10 additions & 1 deletion Core/Sources/Service/XPCService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ public class XPCService: NSObject, XPCServiceProtocol {
// MARK: - Service

public func getXPCServiceVersion(withReply reply: @escaping (String, String) -> Void) {
if checkForNetworkInterception() {
Logger.service.error("Network interception detected. Exiting.")
exit(1)
}
reply(
Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "N/A",
Bundle.main.infoDictionary?["CFBundleVersion"] as? String ?? "N/A"
Expand Down Expand Up @@ -219,6 +223,12 @@ public class XPCService: NSObject, XPCServiceProtocol {
reply: reply
)
}

private func checkForNetworkInterception() -> Bool {
// Implement the logic to check for network interception
// Return true if network interception is detected, otherwise false
return false
}
}

struct NoAccessToAccessibilityAPIError: Error, LocalizedError {
Expand All @@ -228,4 +238,3 @@ struct NoAccessToAccessibilityAPIError: Error, LocalizedError {

init() {}
}

19 changes: 19 additions & 0 deletions Core/Tests/ServiceTests/ManagedPropertiesTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import XCTest
@testable import CommunicationBridge

class ManagedPropertiesTests: XCTestCase {

func testCheckForManagedProperties() {
let result = checkForManagedProperties()
XCTAssertFalse(result, "Managed properties should not be detected in this test environment.")
}

func testListenerShouldAcceptNewConnection() {
let serviceDelegate = ServiceDelegate()
let listener = NSXPCListener(machServiceName: "com.example.service")
let connection = NSXPCConnection(machServiceName: "com.example.service", options: [])

let shouldAccept = serviceDelegate.listener(listener, shouldAcceptNewConnection: connection)
XCTAssertTrue(shouldAccept, "Connection should be accepted in this test environment.")
}
}
17 changes: 17 additions & 0 deletions Core/Tests/ServiceTests/NetworkInterceptionTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import XCTest
@testable import Service

class NetworkInterceptionTests: XCTestCase {

func testNetworkInterceptionDetected() {
let service = Service.shared
let result = service.checkForNetworkInterception()
XCTAssertTrue(result, "Network interception should be detected.")
}

func testNetworkInterceptionNotDetected() {
let service = Service.shared
let result = service.checkForNetworkInterception()
XCTAssertFalse(result, "Network interception should not be detected.")
}
}