Prevent copy & paste into other iOS apps
Advanced clipboard protection on iOS

I am a Software Engineer working on open source and enterprise mobile SDKs for iOS and MacOS developers written in Swift. From 🇩🇪 and happily living in 🇺🇸
Search for a command to run...
Advanced clipboard protection on iOS

I am a Software Engineer working on open source and enterprise mobile SDKs for iOS and MacOS developers written in Swift. From 🇩🇪 and happily living in 🇺🇸
No comments yet. Be the first to comment.
WWDC26 kicked off on June 8, 2026. The information in this article reflects the information published by Apple on that date. There are 14 new frameworks. Name Description AccessoryAccess Manage

WWDC25 kicked off on June 9, 2025. The information in this article reflects the information published by Apple on that date. New Frameworks NameDescription AlarmKitSchedule prominent alarms and countdowns to help people manage their time. AVR...

WWDC25 is almost here, and I couldn’t be more excited! Whether you're attending the official events, community meetups, or just soaking in the energy around Cupertino, there’s no better time to connect, share ideas, and celebrate everything we love a...

In this blog post, I’ll share an observation and advice regarding the caching behavior of network responses by Apple’s APIs. If you are unfamiliar with caching of network responses then I recommend Apple’s article Accessing cached data that introduce...
WWDC24 kicked off on June 10, 2024. The information in this article reflects the information published by Apple on that date. New Frameworks NameDescription AccessorySetupKitUse AccessorySetupKit to discover accessories with Bluetooth or Wi-Fi...

Especially for enterprise apps it is essential to protect sensitive information by preventing end-users from copying & paste the content into other apps.
In this blog post, I show you multiple ways to introduce such kind of advanced clipboard protection for your iOS app.
Apple @ Work introduced Managed Pasteboard in iOS 15 which allows IT administrators to apply restrictions to the copy & paste functionality, meaning that information copied from corporate apps cannot be pasted into unmanaged apps and/or the reverse.
Let's start by explaining that Apple uses the term pasteboard instead of clipboard. Also, it is essential to know that there are two kinds of pasteboards:
systemwide general pasteboard: for sharing data with any app. Persistent across device restarts and app uninstalls. Can be obtained by using UIPasteboard.general
custom / named pasteboards: for sharing data with another app/extension (having the same team ID as the app to share from) or with the app itself. Non-persistent by default. Such can be created with UIPasteboard.pasteboardWithName:create: or UIPasteboard.pasteboardWithUniqueName.
Allowing a user to copy/paste within our iOS application and preventing the user from pasting into other apps.
When the user attempts to switch apps then it is possible to get notified through the NotificationCenter and then clear, i.e. override, the clipboard.
NotificationCenter.default.addObserver(
self,
selector: #selector(appMovedToBackground),
name: UIApplication.willResignActiveNotification,
object: nil
)
@objc
func appMovedToBackground() {
UIPasteboard.general.string = ""
}
A drawback of this technique is that critical information might stay on the clipboard for a long time and attackers might read out the clipboard by periodically querying its content. Also Apple's handoff feature Universal Clipboard may automatically transfer content to other devices and therefore increases the attack vector.
Using the systemwide general pasteboard should be avoided when dealing with sensitive data.
P.S.: It is not an option to listen to UIPasteboard.changedNotification and immediately clear the clipboard because this would prevent the user from copying & paste within the app.
The goal is to return a custom UIPasteBoard whenever the system-wide pasteboard (UIPateboard.general) is requested. Using Swizzling guarantees that the custom pasteboard is always used. Even if the end-user uses the build-in copy capability from UI elements like UITextField that would normally use the system-wide pasteboard.
I'll demonstrate two swizzling techniques
Objective-C Runtime
Swift Native with @_dynamicReplacement
class AppDelegate: NSObject, UIApplicationDelegate {
static var privatePasteboard = UIPasteboard.withUniqueName()
func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
swizzleUIPasteboardGeneral()
return true
}
func swizzleUIPasteboardGeneral() {
let aClass: AnyClass! = object_getClass(UIPasteboard.general)
let targetClass: AnyClass! = object_getClass(self)
let originalMethod = class_getClassMethod(aClass, #selector(getter: UIPasteboard.general))
let swizzledMethod = class_getInstanceMethod(targetClass, #selector(privatePasteboard))
if let originalMethod, let swizzledMethod {
method_exchangeImplementations(originalMethod, swizzledMethod)
}
}
@objc
func privatePasteboard() -> UIPasteboard {
return AppDelegate.privatePasteboard
}
}
On application start the original implementation of UIPasteboard.general gets replaced with an implementation that returns a UIPasteboard that was created with UIPasteboard.withUniqueName()
Easier is the native Swift swizzling technique by using experimental Swift Attribute @_dynamicReplacement(for: targetFunc(label:))
extension UIPasteboard {
@_dynamicReplacement(for: generalPasteboard)
static var privatePasteboard: UIPasteboard {
return AppDelegate.privatePasteboard
}
}
The code replacement happens at the program start (or loading a shared library), instead of at an arbitrary point in time.
For a deep dive into Swift's native swizzling technique, I recommend the following article:
You can try both techniques in a sample application I published on GitHub.
The private UIPasteboard gets honored by WKWebView and UIWebView so the solution works for native controls as well as web views.
Another important piece of information, in case it is not obvious, the user will also not be able to paste content from other apps into the app.
By using a non-persistent, custom pasteboard, you can reduce the risk that attackers might steal sensitive information.
By using swizzling, you can guarantee that the custom pasteboard is always used. Even if the end-user uses the build-in copy capability from UI elements like UITextField.
Shoutout to Hacktricks iOS Pentesting article about iOS UIPasteboard!