天天看點

Android deeplink安全

Android deeplink用來從網頁中自家網站直接打開自家APP,在微信各種封殺情況下,一般需要在浏覽器中通過deeplink方式打開APP

實作上,通過聲明導出activity元件,及相關intent-filter,如下

<intent-filter>
    <action android:name="android.intent.action.VIEW"/>
    <category android:name="android.intent.category.BROWSABLE"/>
    <data android:scheme="hwid"/>
    <data android:host="startup"/>
</intent-filter>
           

網站上通過如下代碼即可打開APP

<a href="hwid://com.huawei.hwid" target="_blank" rel="external nofollow" >hwid</a>

若惡意APP注冊相同的元件和intent-filter,則浏覽器會提示使用者自行選擇,這裡就存在被劫持風險,導緻使用者選擇了惡意APP

Android存在機制可從浏覽器直接打開目标APP,而不需要使用者選擇的過程

android:autoVerify="true"

除了activity元件的intent-filter配置該屬性,還需要在"host"上增加供查詢檔案(host為intent-filter中的配置)

https://host/.well-known/assetlinks.json

注意,僅支援https協定

assetlinks.json中需要包含sha256_cert_fingerprints和package_name

    [{
      "relation": ["delegate_permission/common.handle_all_urls"],
      "target": {
        "namespace": "android_app",
        "package_name": "com.example",
        "sha256_cert_fingerprints":
        ["14:6D:E9:83:C5:73:06:50:D8:EE:B9:95:2F:34:FC:64:16:A0:83:42:E6:1D:BE:A8:8A:04:96:B2:3F:CF:44:E5"]
      }
    }]
    
           

這樣,APP在安裝時就将對應的路由寫入配置(adb shell dumpsys package d 可以驗證),使用者也就不會看到選擇彈框

驗證assetlinks.json格式 https://digitalassetlinks.googleapis.com/v1/statements:list?source.web.site=https://domain.name:optional_port&relation=delegate_permission/common.handle_all_urls

參考 https://developer.android.com/training/app-links/verify-site-associations