Java


JAVA.IO.PERM.ACCESS : Accessing File in Permissive Mode (Java)

要旨

A file is accessed in Context.MODE_WORLD_WRITABLE or Context.MODE_WORLD_READABLE mode.

Constants android.content.Context.MODE_WORLD_READABLE and android.content.Context.MODE_WORLD_WRITABLE can potentially allow access by untrusted applications, and have been deprecated since Android 4.2 (android API 17). From Android 7.0 (android API 24), their use results in a java.lang.SecurityException.

In many cases, android.content.Context.MODE_PRIVATE is more suitable.

プロパティ

クラス名 Accessing File in Permissive Mode (Java)
日本語クラス名 Accessing File in Permissive Mode (Java)
クラス分類 セキュリティ (security)
ニーモニック JAVA.IO.PERM.ACCESS
カテゴリー
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
対応言語 Java で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで有効になっています。チェックを無効にするにはプロジェクト設定ファイル (configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += discard class="Accessing File in Permissive Mode (Java)"

// 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");
      }
  }
}

解決法

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.

関連のある設定ファイルパラメータ

設定ファイルの以下のパラメータがこのワーニングクラスのチェックに影響します。