medium · M9 · MASVS-STORAGE-2 · PTKD-ANDROID-WORLD-READABLE

    Android file or preferences created world-readable or world-writable

    The app opens a file, database or SharedPreferences with MODE_WORLD_READABLE or MODE_WORLD_WRITEABLE, so every other app on the device may read or change it. On Android 7 (API 24) and later these modes throw a SecurityException, so the call is also a crash on most phones.

    How it is exploited

    openFileOutput("session.json", MODE_WORLD_READABLE) on an old device makes the file readable by every installed app: a game with no permissions reads /data/data/<app>/files/session.json.

    Why it matters

    Any app on the phone reads (or with WORLD_WRITEABLE, changes) the file; on Android 7 and later the call throws a SecurityException instead, which crashes that code path.

    How to fix it

    1. Replace MODE_WORLD_READABLE / MODE_WORLD_WRITEABLE with MODE_PRIVATE.
    2. Share files with other apps through a FileProvider content:// URI and FLAG_GRANT_READ_URI_PERMISSION.

    Does your app have this?

    PTKD checks your build or your source project for PTKD-ANDROID-WORLD-READABLE and every other check in this knowledge base.

    Scan your app

    References

    Related checks (M9)