บทนำ (Overview)
“Public Activity” เป็น “Activities” ที่สามารถถูกเรียกใช้งานโดย Application ใด ๆ ก็ตาม โดยส่งและรับ “Intent” จากโปรแกรมที่ไม่ได้ระบุเอาไว้ได้หมด
ระดับของความเสี่ยงและมาตรการป้องกันของการใช้งาน “Activities” ให้ปลอดภัยนั้น ขึ้นอยู่กับการนำไปใช้งาน ซึ่งเราสามารถที่จะจำแนกได้เป็น 4 ประเภทดังต่อไปนี้
เงื่อนไข | ประเภท | อธิบาย |
---|---|---|
สำหรับทุก “Application” | Public Activity | เป็น “Activity” ที่สามารถถูกเรียกใช้งานจาก Application ที่ติดตั้งอยู่ในเครื่องเดียวกัน |
เฉพาะ “Application” อนุญาต | Partner Activity | เป็น “Activity” ที่สามารถเรียกใช้งานเฉพาะ “Application” อนุญาตเท่านั้น |
เฉพาะ “Application” ภายใน | In-house Activity | เป็น “Activity” ที่สามารถใช้งานเฉพาะ Application ที่พัฒนาเฉพาะองค์กรเดียวกันเท่านั้น |
ไม่อนุญาต “Application” อื่น | Private Activity | เป็น “Activity” ที่ไม่สามารถเรียกใช้งานจาก “Application” อื่น ๆ ที่ติดตั้งอยู่ในเครื่องกัน ซึ่งเป็น “Activity” ที่มีความปลอดภัยสูงสุด |
ความเสี่ยง (Risks)
เป็นไปได้ว่า “Public Activities” อาจจะได้รับ “Intent” ที่ถูกส่งมาจากโปรแกรมประสงค์ร้าย (Malicious application) ที่ถูกติดตั้งไว้ที่เครื่องเดียวกัน รวมทั้งสามารถที่รับหรืออ่าน “Intent” ที่ส่งกลับไปเช่นกัน
การควบคุมความปลอดภัย (Control Activities)
ลำดับ | การควบคุม | สาเหตุ |
---|---|---|
ขั้นตอนการสร้าง “Activity” | ||
1 | สามารถตั้งค่า “Export” ของ “Activity” สำคัญ เป็น “True” หรือ “Implicit Intent” ได้เฉพาะ “Public Activity” เท่านั้น | ตรวจสอบให้แน่ใจว่า ถ้าพบว่ามีการตั้งค่า “Export” เป็น “True” หรือ “Implicit Intent” จะต้องยืนยันกับผู้พัฒนาระบบว่า ระบบตั้งใจให้ “Application” ใด ๆ สามารถเรียกใช้งาน “Activity” ดังกล่าวได้หรือไม่ เพื่อป้องกันโปรแกรมสงค์ร้ายเรียกใช้งาน |
2 | จัดการข้อมูลนำเข้าอย่างปลอดภัย (Input validation) |
ตรวจสอบให้แน่ใจว่า ข้อมูลนำเข้ามีการตรวจสอบ (Input validation) อย่างปลอดภัยดังนี้
|
3 | ไม่ส่งข้อมูล “Sensitive information” กลับไป (Return value) | ตรวจสอบให้แน่ใจว่า โปรแกรมจะต้องไม่ส่ง “Sensitive Information กลับไป” เพื่อป้องกันการอ่านข้อมูลสำคัญ (Sensitive information) จาก “Application” ประสงค์ร้าย |
การสอบทานโปรแกรม (Source code review)
ขั้นตอนที่ 1 การตั้งค่าใน AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.itselectlab.android.activity.publicactivity" > <application android:allowBackup="false" android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <!-- Public Activity (Explicit Intent) --> <!-- ถ้าพบว่ามีการตั้งค่า “Export” เป็น “True” หรือ “Implicit Intent” จะต้องยืนยันกับผู้พัฒนาระบบว่า --> <!-- ระบบตั้งใจให้ “Application” ใด ๆ สามารถเรียกใช้งาน “Activity” ดังกล่าวได้หรือไม่ เพื่อป้องกันโปรแกรมสงค์ร้ายเรียกใช้งาน --> <activity android:name=".PublicActivity" android:label="@string/app_name" android:exported="true" > <!-- Public Activity (Implicit Intent) --> <intent-filter> <action android:name="org.itselectlab.android.activity.MY_ACTION" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity> </application> </manifest>
ขั้นตอนที่ 2 การใช้งาน “Private Activity”
public class PublicActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //Control Activity 2: ข้อมูลนำเข้ามีการตรวจสอบ (Input validation) อย่างปลอดภัย // จากตัวอย่างข้างล่าง // - ข้อมูลนำเข้าจะต้องถูกรูปแบบ (Valid Format) = กำหนดเป็น String // - ขนาดข้อมูลนำเข้า (Value range) String param = getIntent().getStringExtra("PARAM"); Toast.makeText(this, String.format("Received param:", param), Toast.LENGTH_LONG).show(); } public void onReturnResultClick(View view) { //Control Activity 3: โปรแกรมจะต้องไม่ส่ง “Sensitive Information กลับไป” Intent intent = new Intent(); intent.putExtra("RESULT", "Not Sensitive Info"); setResult(RESULT_OK, intent); finish(); } }
เอกสารอ้างอิง (Referrences)
- Android Application Secure Design/Secure CodingGuidebook, February 1st, 2016 Edition, Japan Smartphone Security Association (JSSEC)
- https://developer.android.com/guide/topics/manifest/activity-element.html