নিরাপদ ক্লিপবোর্ড হ্যান্ডলিং
সেভ করা পৃষ্ঠা গুছিয়ে রাখতে 'সংগ্রহ' ব্যবহার করুন
আপনার পছন্দ অনুযায়ী কন্টেন্ট সেভ করুন ও সঠিক বিভাগে রাখুন।
OWASP বিভাগ: MASVS-CODE: কোড গুণমান
ওভারভিউ
অ্যাপ্লিকেশানগুলির মধ্যে ডেটা অনুলিপি এবং আটকানোর জন্য অ্যান্ড্রয়েড একটি শক্তিশালী ফ্রেমওয়ার্ক অফার করে যাকে ক্লিপবোর্ড হিসাবে উল্লেখ করা হয়। এই বৈশিষ্ট্যটির একটি অনুপযুক্ত বাস্তবায়ন ব্যবহারকারী-সম্পর্কিত ডেটা অননুমোদিত দূষিত অভিনেতা বা অ্যাপ্লিকেশনের কাছে প্রকাশ করতে পারে।
ক্লিপবোর্ড ডেটার এক্সপোজারের সাথে সম্পর্কিত নির্দিষ্ট ঝুঁকি অ্যাপ্লিকেশনের প্রকৃতি এবং এটি পরিচালনা করা ব্যক্তিগত শনাক্তযোগ্য তথ্য (PII) এর উপর নির্ভর করে। প্রভাব বিশেষত আর্থিক অ্যাপ্লিকেশনগুলির জন্য বেশি, কারণ তারা অর্থপ্রদানের ডেটা বা অ্যাপগুলিকে প্রকাশ করতে পারে যা টু-ফ্যাক্টর-অথেন্টিকেশন (2FA) কোডগুলি পরিচালনা করে।
অ্যাটাক ভেক্টর যেগুলিকে ক্লিপবোর্ড ডেটা এক্সফিল্ট করার জন্য ব্যবহার করা যেতে পারে তা অ্যান্ড্রয়েড সংস্করণের উপর নির্ভর করে পরিবর্তিত হয়:
- Android 10 (API লেভেল 29) এর চেয়ে পুরানো Android সংস্করণগুলি পটভূমি অ্যাপ্লিকেশনগুলিকে ফোরগ্রাউন্ড অ্যাপ ক্লিপবোর্ডের তথ্য অ্যাক্সেস করার অনুমতি দেয়, সম্ভাব্যভাবে ক্ষতিকারক অভিনেতাদের দ্বারা অনুলিপি করা ডেটাতে সরাসরি অ্যাক্সেসের অনুমতি দেয়।
- অ্যান্ড্রয়েড 12 এর পর থেকে (এপিআই লেভেল 31), প্রতিবার যখন কোনও অ্যাপ্লিকেশন ক্লিপবোর্ডের মধ্যে ডেটা অ্যাক্সেস করে এবং এটি পেস্ট করে, ব্যবহারকারীকে একটি টোস্ট বার্তা দেখানো হয়, যা আক্রমণগুলিকে অলক্ষিত করা আরও কঠিন করে তোলে। উপরন্তু, PII রক্ষা করার জন্য, Android
ClipDescription.EXTRA_IS_SENSITIVE
বা android.content.extra.IS_SENSITIVE
বিশেষ পতাকা সমর্থন করে। এটি বিকাশকারীদেরকে কীবোর্ড GUI-এর মধ্যে ক্লিপবোর্ড সামগ্রীর পূর্বরূপ দৃশ্যত অস্পষ্ট করার অনুমতি দেয়, অনুলিপি করা ডেটা দৃশ্যত পরিষ্কার-টেক্সটে দেখানো থেকে বাধা দেয় এবং দূষিত অ্যাপ্লিকেশনগুলি দ্বারা সম্ভাব্য চুরি হয়৷ উপরে উল্লিখিত ফ্ল্যাগগুলির একটি বাস্তবায়ন না করা আসলে আক্রমণকারীদের ক্লিপবোর্ডে অনুলিপি করা সংবেদনশীল ডেটা কাঁধে সার্ফিং বা ক্ষতিকারক অ্যাপ্লিকেশনগুলির মাধ্যমে বের করে দেওয়ার অনুমতি দিতে পারে যা ব্যাকগ্রাউন্ডে চলাকালীন, স্ক্রিনশট নিতে বা বৈধ ব্যবহারকারীর কার্যকলাপের ভিডিও রেকর্ড করে৷
প্রভাব
অনুপযুক্ত ক্লিপবোর্ড পরিচালনার শোষণের ফলে ব্যবহারকারী-সম্পর্কিত সংবেদনশীল বা আর্থিক ডেটা দূষিত অভিনেতাদের দ্বারা বহিষ্কৃত হতে পারে। এটি ফিশিং প্রচারাভিযান বা পরিচয় চুরির মতো আরও অ্যাকশন পরিচালনা করতে আক্রমণকারীদের সাহায্য করতে পারে৷
প্রশমন
পতাকা সংবেদনশীল ডেটা
এই সমাধানটি কীবোর্ড GUI-এর মধ্যে ক্লিপবোর্ড বিষয়বস্তুর পূর্বরূপ দৃশ্যত অস্পষ্ট করার জন্য নিযুক্ত করা হয়। ClipboardManager.setPrimaryClip()
কল করার আগে পাসওয়ার্ড বা ক্রেডিট কার্ড ডেটার মতো যে কোনো সংবেদনশীল ডেটা কপি করা যেতে পারে, ClipDescription.EXTRA_IS_SENSITIVE
বা android.content.extra.IS_SENSITIVE
দিয়ে ফ্ল্যাগ করা উচিত।
কোটলিন
// If your app is compiled with the API level 33 SDK or higher.
clipData.apply {
description.extras = PersistableBundle().apply {
putBoolean(ClipDescription.EXTRA_IS_SENSITIVE, true)
}
}
// If your app is compiled with API level 32 SDK or lower.
clipData.apply {
description.extras = PersistableBundle().apply {
putBoolean("android.content.extra.IS_SENSITIVE", true)
}
}
জাভা
// If your app is compiled with the API level 33 SDK or higher.
PersistableBundle extras = new PersistableBundle();
extras.putBoolean(ClipDescription.EXTRA_IS_SENSITIVE, true);
clipData.getDescription().setExtras(extras);
// If your app is compiled with API level 32 SDK or lower.
PersistableBundle extras = new PersistableBundle();
extras.putBoolean("android.content.extra.IS_SENSITIVE", true);
clipData.getDescription().setExtras(extras);
সর্বশেষ অ্যান্ড্রয়েড সংস্করণ প্রয়োগ করুন
অ্যাপ্লিকেশানটিকে Android 10 (API 29) এর সমতুল্য পরবর্তী সংস্করণগুলিতে চালানোর জন্য প্রয়োগ করা পটভূমি প্রক্রিয়াগুলিকে অগ্রভাগের অ্যাপ্লিকেশনে ক্লিপবোর্ড ডেটা অ্যাক্সেস করতে বাধা দেয়৷
অ্যাপটিকে শুধুমাত্র Android 10 (API 29) বা তার পরে চালানোর জন্য প্রয়োগ করতে, Android স্টুডিওতে আপনার প্রকল্পের মধ্যে Gradle বিল্ড ফাইলগুলিতে সংস্করণ সেটিংসের জন্য নিম্নলিখিত মানগুলি সেট করুন।
গ্রোভি
android {
namespace 'com.example.testapp'
compileSdk [SDK_LATEST_VERSION]
defaultConfig {
applicationId "com.example.testapp"
minSdk 29
targetSdk [SDK_LATEST_VERSION]
versionCode 1
versionName "1.0"
...
}
...
}
...
কোটলিন
android {
namespace = "com.example.testapp"
compileSdk = [SDK_LATEST_VERSION]
defaultConfig {
applicationId = "com.example.testapp"
minSdk = 29
targetSdk = [SDK_LATEST_VERSION]
versionCode = 1
versionName = "1.0"
...
}
...
}
...
একটি নির্দিষ্ট সময়ের পরে ক্লিপবোর্ড সামগ্রী মুছুন
যদি অ্যাপ্লিকেশানটি Android 10 (API স্তর 29) এর চেয়ে কম Android সংস্করণগুলিতে চালানোর উদ্দেশ্যে হয় তবে যে কোনও ব্যাকগ্রাউন্ড অ্যাপ্লিকেশন ক্লিপবোর্ড ডেটা অ্যাক্সেস করতে পারে। এই ঝুঁকি কমানোর জন্য, একটি নির্দিষ্ট সময়ের পরে ক্লিপবোর্ডে অনুলিপি করা যেকোন ডেটা সাফ করে এমন একটি ফাংশন বাস্তবায়ন করা দরকারী। এই ফাংশনটি স্বয়ংক্রিয়ভাবে Android 13 (API স্তর 33) দিয়ে শুরু হয় । পুরানো অ্যান্ড্রয়েড সংস্করণগুলির জন্য, অ্যাপ্লিকেশনের কোডের মধ্যে নিম্নলিখিত স্নিপেটটি অন্তর্ভুক্ত করে এই মুছে ফেলার কাজটি করা যেতে পারে৷
কোটলিন
//The Executor makes this task Asynchronous so that the UI continues being responsive
backgroundExecutor.schedule({
//Creates a clip object with the content of the Clipboard
val clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val clip = clipboard.primaryClip
//If SDK version is higher or equal to 28, it deletes Clipboard data with clearPrimaryClip()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
clipboard.clearPrimaryClip()
} else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
//If SDK version is lower than 28, it will replace Clipboard content with an empty value
val newEmptyClip = ClipData.newPlainText("EmptyClipContent", "")
clipboard.setPrimaryClip(newEmptyClip)
}
//The delay after which the Clipboard is cleared, measured in seconds
}, 5, TimeUnit.SECONDS)
জাভা
//The Executor makes this task Asynchronous so that the UI continues being responsive
ScheduledExecutorService backgroundExecutor = Executors.newSingleThreadScheduledExecutor();
backgroundExecutor.schedule(new Runnable() {
@Override
public void run() {
//Creates a clip object with the content of the Clipboard
ClipboardManager clipboard = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = clipboard.getPrimaryClip();
//If SDK version is higher or equal to 28, it deletes Clipboard data with clearPrimaryClip()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
clipboard.clearPrimaryClip();
//If SDK version is lower than 28, it will replace Clipboard content with an empty value
} else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
ClipData newEmptyClip = ClipData.newPlainText("EmptyClipContent", "");
clipboard.setPrimaryClip(newEmptyClip);
}
//The delay after which the Clipboard is cleared, measured in seconds
}, 5, TimeUnit.SECONDS);
সম্পদ
এই পৃষ্ঠার কন্টেন্ট ও কোডের নমুনাগুলি Content License-এ বর্ণিত লাইসেন্সের অধীনস্থ। Java এবং OpenJDK হল Oracle এবং/অথবা তার অ্যাফিলিয়েট সংস্থার রেজিস্টার্ড ট্রেডমার্ক।
2025-07-29 UTC-তে শেষবার আপডেট করা হয়েছে।
[[["সহজে বোঝা যায়","easyToUnderstand","thumb-up"],["আমার সমস্যার সমাধান হয়েছে","solvedMyProblem","thumb-up"],["অন্যান্য","otherUp","thumb-up"]],[["এতে আমার প্রয়োজনীয় তথ্য নেই","missingTheInformationINeed","thumb-down"],["খুব জটিল / অনেক ধাপ","tooComplicatedTooManySteps","thumb-down"],["পুরনো","outOfDate","thumb-down"],["অনুবাদ সংক্রান্ত সমস্যা","translationIssue","thumb-down"],["নমুনা / কোড সংক্রান্ত সমস্যা","samplesCodeIssue","thumb-down"],["অন্যান্য","otherDown","thumb-down"]],["2025-07-29 UTC-তে শেষবার আপডেট করা হয়েছে।"],[],[],null,["# Secure Clipboard Handling\n\n\u003cbr /\u003e\n\n**OWASP category:** [MASVS-CODE: Code Quality](https://mas.owasp.org/MASVS/10-MASVS-CODE)\n\nOverview\n--------\n\nAndroid offers a powerful framework referred to as the [clipboard](/develop/ui/views/touch-and-input/copy-paste#Clipboard) for\ncopying and pasting data between applications. An improper implementation of\nthis feature could expose user-related data to unauthorized malicious actors or\napplications.\n\nThe specific risk associated with the exposure of clipboard data depends on the\nnature of the application and the Personal Identifiable Information (PII) it is\nhandling. The impact is especially high for financial applications, as they may\nexpose payment data, or apps that handle two-factor-authentication (2FA) codes.\n\nThe attack vectors that could be leveraged in order to exfiltrate clipboard data\nvary depending on Android version:\n\n- [Android versions older than Android 10 (API level 29)](/about/versions/10/privacy/changes#clipboard-data) allow background applications to access foreground app clipboard information, potentially allowing direct access to any copied data by malicious actors.\n- From Android 12 onwards (API level 31), every time an application accesses data within the clipboard and pastes it, a toast message is shown to the user, making it more difficult for attacks to go unnoticed. Additionally, in order to protect PII, Android supports the `ClipDescription.EXTRA_IS_SENSITIVE` or `android.content.extra.IS_SENSITIVE` special flag. This allows developers to visually obfuscate the clipboard content preview within the keyboard GUI, preventing copied data from being visually shown in clear-text and potentially stolen by malicious applications. Not implementing one of the aforementioned flags could in fact allow attackers to exfiltrate sensitive data copied to the clipboard by either shoulder surfing or through malicious applications that, while running in background, take screenshots or record videos of a legitimate user's activities.\n\nImpact\n------\n\nThe exploitation of improper clipboard handling could result in user-related\nsensitive or financial data being exfiltrated by malicious actors. This may aid\nattackers in conducting further actions such as phishing campaigns or identity\ntheft.\n\nMitigations\n-----------\n\n### Flag Sensitive Data\n\nThis solution is employed to visually obfuscate the clipboard content preview\nwithin the keyboard GUI. Any sensitive data that can be copied, such as\npasswords or credit card data, should be flagged with\n`ClipDescription.EXTRA_IS_SENSITIVE` or `android.content.extra.IS_SENSITIVE`\nbefore calling [`ClipboardManager.setPrimaryClip()`](/reference/android/content/ClipboardManager#setPrimaryClip(android.content.ClipData)). \n\n### Kotlin\n\n // If your app is compiled with the API level 33 SDK or higher.\n clipData.apply {\n description.extras = PersistableBundle().apply {\n putBoolean(ClipDescription.EXTRA_IS_SENSITIVE, true)\n }\n }\n\n // If your app is compiled with API level 32 SDK or lower.\n clipData.apply {\n description.extras = PersistableBundle().apply {\n putBoolean(\"android.content.extra.IS_SENSITIVE\", true)\n }\n }\n\n### Java\n\n // If your app is compiled with the API level 33 SDK or higher.\n PersistableBundle extras = new PersistableBundle();\n extras.putBoolean(ClipDescription.EXTRA_IS_SENSITIVE, true);\n clipData.getDescription().setExtras(extras);\n\n // If your app is compiled with API level 32 SDK or lower.\n PersistableBundle extras = new PersistableBundle();\n extras.putBoolean(\"android.content.extra.IS_SENSITIVE\", true);\n clipData.getDescription().setExtras(extras);\n\n### Enforce Latest Android Versions\n\nEnforcing the app to run on Android versions later or equal to Android 10 (API\n29) prevents background processes from accessing clipboard data in the\nforeground application.\n\nTo enforce the app to run only on Android 10 (API 29) or later, set the\nfollowing values for the version settings in the Gradle build files within your\nproject in Android Studio. \n\n### Groovy\n\n android {\n namespace 'com.example.testapp'\n compileSdk [SDK_LATEST_VERSION]\n\n defaultConfig {\n applicationId \"com.example.testapp\"\n minSdk 29\n targetSdk [SDK_LATEST_VERSION]\n versionCode 1\n versionName \"1.0\"\n ...\n }\n ...\n }\n ...\n\n### Kotlin\n\n android {\n namespace = \"com.example.testapp\"\n compileSdk = [SDK_LATEST_VERSION]\n\n defaultConfig {\n applicationId = \"com.example.testapp\"\n minSdk = 29\n targetSdk = [SDK_LATEST_VERSION]\n versionCode = 1\n versionName = \"1.0\"\n ...\n }\n ...\n }\n ...\n\n### Delete Clipboard content after a defined period of time\n\nIf the application is meant to run on Android versions lower than Android 10\n(API level 29), any background application can access clipboard data.\nIn order\nto reduce this risk, it's useful to implement a function that clears any data\ncopied to the clipboard after a specific period of time. This function is\n[automatically performed starting with Android 13 (API level 33)](https://blog.google/products/android/android-13/).\nFor older\nAndroid versions, this deletion can be performed by including the following\nsnippet within the application's code. \n\n### Kotlin\n\n //The Executor makes this task Asynchronous so that the UI continues being responsive\n backgroundExecutor.schedule({\n //Creates a clip object with the content of the Clipboard\n val clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager\n val clip = clipboard.primaryClip\n //If SDK version is higher or equal to 28, it deletes Clipboard data with clearPrimaryClip()\n if (Build.VERSION.SDK_INT \u003e= Build.VERSION_CODES.P) {\n clipboard.clearPrimaryClip()\n } else if (Build.VERSION.SDK_INT \u003c Build.VERSION_CODES.P) {\n //If SDK version is lower than 28, it will replace Clipboard content with an empty value\n val newEmptyClip = ClipData.newPlainText(\"EmptyClipContent\", \"\")\n clipboard.setPrimaryClip(newEmptyClip)\n }\n //The delay after which the Clipboard is cleared, measured in seconds\n }, 5, TimeUnit.SECONDS)\n\n### Java\n\n //The Executor makes this task Asynchronous so that the UI continues being responsive\n\n ScheduledExecutorService backgroundExecutor = Executors.newSingleThreadScheduledExecutor();\n\n backgroundExecutor.schedule(new Runnable() {\n @Override\n public void run() {\n //Creates a clip object with the content of the Clipboard\n ClipboardManager clipboard = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);\n ClipData clip = clipboard.getPrimaryClip();\n //If SDK version is higher or equal to 28, it deletes Clipboard data with clearPrimaryClip()\n if (Build.VERSION.SDK_INT \u003e= Build.VERSION_CODES.P) {\n clipboard.clearPrimaryClip();\n //If SDK version is lower than 28, it will replace Clipboard content with an empty value\n } else if (Build.VERSION.SDK_INT \u003c Build.VERSION_CODES.P) {\n ClipData newEmptyClip = ClipData.newPlainText(\"EmptyClipContent\", \"\");\n clipboard.setPrimaryClip(newEmptyClip);\n }\n //The delay after which the Clipboard is cleared, measured in seconds\n }, 5, TimeUnit.SECONDS);\n\nResources\n---------\n\n- [The clipboard framework](/develop/ui/views/touch-and-input/copy-paste#Clipboard)\n- [System notification shown when your app accesses clipboard data](/develop/ui/views/touch-and-input/copy-paste#PastingSystemNotifications)\n- [Add sensitive content to the clipboard](/develop/ui/views/touch-and-input/copy-paste#SensitiveContent)\n- [Privacy changes in Android 10](/about/versions/10/privacy/changes)\n- [Set app version information](/studio/publish/versioning#appversioning)"]]