Java logoJava/
JAVA-A1039

Audit: File is set as world readable or writableJAVA-A1039

Critical severityCritical
Security categorySecurity
a01, cwe-200, cwe-732, security, cwe-552, cwe-668, owasp-top-10

This code appears to open a file using Context.openFileOutput(String, int), but sets the mode (the second argument) to be one of Context.MODE_WORLD_READABLE or Context.MODE_WORLD_WRITABLE.

This is dangerous; it will always throw a SecurityException in android versions above jellybean (API level 17), and in the worst case could be abused by a malicious actor to access or manipulate data and even code.

Bad Practice


FileOutputStream fos = openFileOutput("somefile.txt", Context.MODE_WORLD_READABLE);

Use the MODE_PRIVATE or MODE_APPEND (if your file already exists) instead to privately create a writable file.


FileOutputStream fos = openFileOutput("somefile.txt", Context.MODE_PRIVATE);

If you need to expose this file to other applications/activities, consider using the content provider API to do so instead.

References