Java


JAVA.IO.PERM : Permissive File Mode (Java)

Summary

A file is world-readable or world-writable.

Properties

Class Name Permissive File Mode (Java)
Significance security
Mnemonic JAVA.IO.PERM
Categories
CWE CWE:732 Incorrect Permission Assignment for Critical Resource
CERT-Java CERT-Java:ENV03-J Do not grant dangerous combinations of permissions
  CERT-Java:FIO01-J Create files with appropriate access permissions
  CERT-Java:SEC01-J Do not allow tainted variables in privileged blocks
Availability Available for Java only.

Android Only. Warnings of this class will only be reported in Android code: that is, code that uses the Android API.

Enabling Checks for this warning class are enabled by default. To disable them, add the following WARNING_FILTER rule to the project configuration file.
WARNING_FILTER += discard class="Permissive File Mode (Java)"

Example

// MainActivity.java
package example.fileaccessexample;

import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

public class MainActivity extends AppCompatActivity {

  private static final String TAG = "MainActivity";

  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      try {

            FileOutputStream fileOutputStream1 = openFileOutput("foo.txt", Context.MODE_WORLD_READABLE);  // Accessing File in Permissive Mode (Java) warning issued here 
            FileOutputStream fileOutputStream2 = openFileOutput("foo.txt", Context.MODE_WORLD_WRITEABLE); // Accessing File in Permissive Mode (Java) warning issued here 

        } catch (FileNotFoundException | SecurityException e) {
            e.printStackTrace();
        }
      extendAccessPermission(new File("myfile.txt"));
  }

  public  void extendAccessPermission(File f) {
      if ( !f.setReadable( true , false )) {           // Permissive File Mode (Java) warning issued here 
          Log.e(TAG,"Unable to set readable permission");
      }

      if ( !f.setWritable( true , false )) {           // Permissive File Mode (Java) warning issued here 
          Log.e(TAG,"Unable to set writable permission");
      }
  }
}

Resolution

Android's security design philosophy recommends the use of files only for the purpose of perpetuating or temporarily storing information. In principle the file access permissions should be private, in order to limit the risk of information leakage.

The Android API documentation includes guidelines for securely sharing files.

Relevant Configuration File Parameters

The following configuration file parameters affect checks for this warning class.