`
wenson
  • 浏览: 1051003 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

Define a Security Policy(定义java安全策略)

 
阅读更多

from:http://web.securityinnovation.com/appsec-weekly/blog/bid/72451/Define-a-Security-Policy

Applies to

Applications written using Servlets or JSP.

What to Do

Define a security policy for your application while applying the principle of least privilege. Restrict application execution to allow only the minimum set of necessary actions.

Why

Defining a Java security policy is a defense in-depth mechanism for restricting your application from performing tasks that the operating system would otherwise allow. This is especially important in the event your application becomes compromised by an attacker.

When

Always define a security policy for your application. This process should take place during your application's design stage.

How

Although Java applications run inside a virtual machine, do not execute your application in the context of a privileged user. Consider tightening the restrictions on your application by employing Java Policies.

Use the following steps to successfully utilize Java Permissions:

  1. Identify the system resources that your application uses. Enumerate all resources that your application will need to access. Identify the types of permissions that your application requires to access those resources. For example, your application will need to connect to your database via a socket connection or write to your logs.

  2. Identify your application. Your application can be identified via two ways inside a Java policy — code signing or code base.

    • Code signing. Always sign your code whenever possible. This ensures the authenticity of your code. Use Java's KeyTool when signing your code.

    • Code base. Identify the location of your code. Example:

      codeBase "file:e:/myapp/bin/"
  3. Create the appropriate policy. Once all required resources are enumerated, create a Java policy that reflects the type of access that is required for each resource. Example:

    grant codeBase "file:e:/myapp/bin/-" 
    {
        // A placeholder for all appropriate permissions
    };

    Assign a permission for each required resource. Java provides different types of permissions, each of which can be customized to meet your application's needs:

    • java.security.AllPermission: AllPermission grants all other permissions to the code. It should seldom be used. Example:

      permission java.security.AllPermission;

      For more information, consult the documentation for Class AllPermission in the Java SDK.

    • javax.sound.sampled.AudioPermission: AudioPermission grants access rights to the system's audio components. It should be used only when the application is required to play or record audio. Example:

      permission javax.sound.sampled.AudioPermission "play";

      For more information, consult the documentation for Class AudioPermission in the Java SDK.

    • javax.security.auth.AuthPermission: AuthPermission is used during authentication procedures. TheAuthPermission's only argument is the name of the security configuration parameter. This permission class is used to guard access to the Policy, Subject, LoginContext, and Configuration objects. Example:

      permission javax.security.auth.AuthPermission "modifyPrincipals";

      For more information, consult the documentation for Class AuthPermission in the Java SDK.

    • java.awt.AWTPermission: AWTPermission grants access to the system's user experience and graphical interface. For example, the following permission would allow the application to access the system's clipboard:

      permission java.awt.AWTPermission "accessClipboard";

      For more information, consult the documentation for Class AWTPermission in the Java SDK.

    • javax.security.auth.kerberos.DelegationPermission: DelegationPermission restricts the usage of the Kerberos delegation model. Example:

      permission javax.security.auth.kerberos.DelegationPermission
             "\"host/foo.example.com@EXAMPLE.COM\" \"krbtgt/EXAMPLE.COM@EXAMPLE.COM\"";

      For more information, consult the documentation for Class DelegationPermission in the Java SDK.

    • java.io.FilePermission: FilePermission grants access to files on the local system. Access right are read, write, execute, delete. Note that FilePermission always grants read access to files within the code's directory and any subdirectories. Example:

      permission java.io.FilePermission "e:/myapp/logs/20061016.log", "write";

      For more information, consult the documentation for Class FilePermission in the Java SDK.

    • java.util.logging.LoggingPermission: LoggingPermission is associated with Java's standard logging mechanism. Because Java's logging mechanism does not meet the recommendation for logging security events, please consult the Log Important Security Operations guideline if your application performs logging. CurrentlyLoggingPermission grants only the right to control Java's logging configuration. Example:

      permission java.util.logging.LoggingPermission "control";

      For more information, consult the documentation for Class LoggingPermission in the Java SDK.

    • java.net.NetPermission: NetPermission grants access to various network permissions. For example, the following permission allows the ability to specify a stream handler when constructing a URL:

      permission java.net.NetPermission "specifyStreamHandler";

      For more information, consult the documentation for Class NetPermission in the Java SDK.

    • javax.security.auth.PrivateCredentialPermission: PrivateCredentialPermission protects access to the privateCredentials belonging to a particular Subject. Example:

      permission javax.security.auth.PrivateCredentialPermission
                      "javax.resource.spi.security.PasswordCredential * \"*\"","read";

      For more information, consult the documentation for Class PrivateCredentialPermission in the Java SDK.

    • java.util.PropertyPermission: PropertyPermission specifies the read/write access to an object's or System's properties. Example:

      permission java.util.PropertyPermission "java.home", "read";

      For more information, consult the documentation for Class PropertyPermission in the Java SDK.

    • java.lang.reflect.ReflectPermission: ReflectPermission grants access to reflective operations. Currently it only allows suppressing the standard Java language access checks (i.e. public, protected and private) by reflected objects at their point of use. Example:

      permission java.lang.reflect.ReflectPermission "suppressAccessChecks";

      For more information, consult the documentation for Class ReflectPermission in the Java SDK.

    • java.lang.RuntimePermission: RuntimePermission grants access to runtime operations such as loading external libraries and halting the JVM. Example:

      permission java.lang.RuntimePermission "accessDeclaredMembers";

      For more information, consult the documentation for Class RuntimePermission in the Java SDK.

    • java.security.SecurityPermission: SecurityPermission is used any security related events. Example:

      permission java.security.SecurityPermission "createAccessControlContext";

      For more information, consult the documentation for Class SecurityPermission in the Java SDK.

    • java.io.SerializablePermission: SerializablePermission grant access to more advanced features of Java's serialization model. For example, the following permission allows the substitution of one object for another during serialization:

      permission java.io.SerializablePermission "enableSubstitution";

      For more information, consult the documentation for Class SerializablePermission in the Java SDK.

    • javax.security.auth.kerberos.ServicePermission: ServicePermission protects the access to Kerberos services and any supplemental credentials. Example:

      permission javax.security.auth.kerberos.ServicePermission
                                          "krbtgt/EXAMPLE.COM@EXAMPLE.COM", "initiate";

      For more information, consult the documentation for Class ServicePermission in the Java SDK.

    • java.net.SocketPermission: SocketPermission grants access to the network via sockets. It allows your application to connect to a host, accept connections from a host, listen on a given port, or resolve the other host's IP/hostname. Example:

      permission java.net.SocketPermission "serv02.example.com:3306", "connect";

      For more information, consult the documentation for Class SocketPermission in the Java SDK.

    • java.sql.SQLPermission: SQLPermission grants access to operations executed during database access. Currently all standard Java methods that use SQLPermission are deprecated. For more information, consult the documentation for Class SQLPermission in the Java SDK.

    • javax.net.ssl.SSLPermission: SSLPermission grants access to SSL related operations. For example, anSSLPermission would be required to get the SSLSessionContext of an SSLSession:

      permission javax.net.ssl.SSLPermission "getSSLSessionContext";

      For more information, consult the documentation for Class SSLPermission in the Java SDK.

  4. Load the policy at runtime. By default Java provides two policy files: a system policy file({java.home}/lib/security/java.policy) and a user policy file ({user.home}/.java.policy). Use the -Djava.security.policy(={policy file}) flag to load your policy during the start-up routine of your application's server. Make sure you use only a single = to append your policy to the JVM's default policies as == will force the JVM to load your policy only. Example:

    -Djava.security.policy=e:/myapp/config/myapp.policy
  5. Enforce your application's policy. To fully enforce your application's policy, attach a SecurityManager to the System object. Because most standard Java packages come with built-in permission checks that are linked to the System's SecurityManager, enforcing a certain set of permissions is a fairly easy task. Example:

    if (System.getSecurityManager() == null)
    {
          System.setSecurityManager(new SecurityManager());
    }

    or

    -Djava.security.manager

    Be aware that enforcing a security policy may restrict access to various resources that are essential to the application's environment. Examples of such resources include, but are not limited to, use of network sockets, application server's local files, etc. Use the following steps to resolve such problems:

    1. Enumerate all permissions that are granted to your application's environment. Enumerating all granted permissions to your application's environment helps identify the basic functionality that it requires for its normal operations. The following code helps you identify all permissions that your application inherits from its environment:

      public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException
      {
            PrintWriter out = response.getWriter();
            CodeSigner[] cSign = null;
            CodeSource cSource = new CodeSource(null, cSign);
            Principal[] principals = new Principal[0];
            ProtectionDomain pDomain = new ProtectionDomain(cSource,
                                                          null, null, principals);
            java.security.Policy policy = java.security.Policy.getPolicy();
            PermissionCollection permCollect = policy.getPermissions(pDomain);
            Enumeration permList = permCollect.elements();
            while (permList.hasMoreElements())
            {
                  out.println( "<br>" + permList.nextElement().toString());
            }
      }

      Note that the code snippet will perform its intended action only if the System's SecurityManager is set to null.

    2. Check if your application's environment performs unauthorized actions. Enable the SecurityManagerduring the start-up routine of your application's environment. Monitor the environment's logs for any access denied errors. For instance, Tomcat will not function properly if the administrator does not grant aSocketPermission to connect and resolve 127.0.0.1 on port 8005:

      Exception in thread "ContainerBackgroundProcessor[StandardEngine[Catalina]]"
           java.security.AccessControlException: access denied
                (java.lang.RuntimePermission setContextClassLoader)
      ...
      Caused by: java.security.AccessControlException: access denied
                (java.net.SocketPermission 127.0.0.1:8005 connect,resolve)
    3. Grant the essential permissions for your application's environment. Grant all essential permissions into the security policy for your application's environment to allow the environment to function properly.

  6. Protect security policy files. Make sure that appropriate security measures are taken when storing the security policy files.

    • Choose a security policy directory: Dedicate a directory for storing your application's security policy files. Make sure the directory is not web-accessible. This limits the scope of users who can potentially compromise the contents inside the directory.
    • Set appropriate permissions: Apply the appropriate filesystem permissions such that the security policy files can be only accessed by your application and its administrators.
  7. Avoid common mistakes.

    • Delegate a Policy Manager: Java allows its applications to alter the JVM's policies during runtime. If your application needs to alter its policies during runtime, create a custom Policy Manager and delegate it the task of altering Java policies. Using the SecurityPermission class, enforce strict access control to the manager's functionality such that only authorized components can request modifications to the JVM's policies.

      The following permissions must be granted to the Policy Manager's code:

      java.security.SecurityPermission "getPolicy";
      java.security.SecurityPermission "setPolicy";
    • Enforce the security policy as early as possible: Delaying the enforcement of the security policies provides a bigger window of opportunity for an attacker to execute a payload through your compromised application.

分享到:
评论

相关推荐

    MongoDB分片集群搭建教程:副本集创建与数据分片

    内容概要:本文提供了详细的MongoDB分片集群的搭建指导,涵盖了从环境准备、配置文件编写、副本集的建立、主节点的选择、配置服务器和数据分片服务器的配置到最后的路由节点的搭建与操作整个流程,以及对数据库的哈希与范围两种分片策略的应用介绍和具体命令执行。 适合人群:熟悉NoSQL数据库概念并对MongoDB有一定了解的技术人员,尤其是在大型数据管理和分布式数据库架构设计中有需求的开发者。 使用场景及目标:帮助技术人员掌握构建高效能、高可用性的MongoDB分片集群的方法,适用于处理大规模、实时性强的数据存储与读取场景。 其他说明:文中通过实例演示了每个步骤的具体操作方法,便于跟随文档实操,同时也介绍了可能遇到的问题及其解决方案,如在没有正确配置的情况下试图写入数据时出现错误等情况的处理。

    CPPC++_嵌入式硬件的物联网解决方案blinker库与Arduino ESP8266 ESP32一起工作.zip

    CPPC++_嵌入式硬件的物联网解决方案blinker库与Arduino ESP8266 ESP32一起工作

    CPPC++_逆向调用QQ Mojo IPC与WeChat XPlugin.zip

    CPPC++_逆向调用QQ Mojo IPC与WeChat XPlugin

    CPPC++_现代活动指标.zip

    CPPC++_现代活动指标

    CPPC++_Xournal是一款手写笔记软件,支持PDF注释,使用C语言编写,支持GTK3,支持Linux,如Ubu.zip

    CPPC++_Xournal是一款手写笔记软件,支持PDF注释,使用C语言编写,支持GTK3,支持Linux,如Ubu

    基于SSM学生实习管理系统前台小程序与后台管理系统开发实践

    资源概述: 本资源提供了一套完整的学生实习管理系统解决方案,涵盖了前台小程序页面与后台管理系统两大模块。前台小程序页面设计简洁直观,用户可根据不同身份(学生或企业)进行登录。学生用户能够方便地浏览并投递感兴趣的实习岗位,而企业用户则能轻松发布实习信息,吸引优秀人才。后台管理系统功能全面,包括个人中心、首页、学生管理、教师管理、企业管理、招聘管理、评分管理以及实习管理等多个方面,为管理员提供了强大的数据管理和操作工具。 技术栈亮点: SSM框架:系统后台采用Spring、Spring MVC和MyBatis Plus(简称SSM)作为核心开发框架,确保了系统的稳定性、可扩展性和可维护性。Spring作为控制反转(IoC)和面向切面编程(AOP)的容器,为系统提供了强大的业务逻辑处理能力;Spring MVC则负责处理Web请求和响应,实现了前后端的分离;MyBatis Plus作为持久层框架,简化了数据库操作,提高了开发效率。 MySQL数据库:系统采用MySQL作为数据库存储解决方案,支持大数据量的存储和高效查询。 如有侵权请联系我删除,谢谢

    微服务闪聚支付项目.zip

    微服务闪聚支付项目

    Rust 与 Java 互调实战示例

    博客链接 https://blog.csdn.net/weixin_47560078/article/details/143714557 文章从原理介绍出发,实现了 Rust 与 Java 的互调。利用 JNI 技术,可以充分发挥 Rust 的性能优势,同时保持 Java 的跨平台特性。这种技术组合适用于对性能要求较高的应用场景,如图像处理、数据分析和系统级编程等。

    CPPC++_这是我翻译的艾根中文文档.zip

    cppc++

    Matlab实现斑马优化算法ZOA-TCN-Multihead-Attention多输入单输出回归预测算法研究.rar

    1.版本:matlab2014/2019a/2024a 2.附赠案例数据可直接运行matlab程序。 3.代码特点:参数化编程、参数可方便更改、代码编程思路清晰、注释明细。 4.适用对象:计算机,电子信息工程、数学等专业的大学生课程设计、期末大作业和毕业设计。 替换数据可以直接使用,注释清楚,适合新手

    Matlab实现雪融优化算法SAO-TCN-Multihead-Attention多输入单输出回归预测算法研究.rar

    1.版本:matlab2014/2019a/2024a 2.附赠案例数据可直接运行matlab程序。 3.代码特点:参数化编程、参数可方便更改、代码编程思路清晰、注释明细。 4.适用对象:计算机,电子信息工程、数学等专业的大学生课程设计、期末大作业和毕业设计。 替换数据可以直接使用,注释清楚,适合新手

    分布式事务lcn.zip

    分布式事务lcn

    基于Simulink的正弦波PWM技术和三次谐波注入PWM技术研究.rar

    1.版本:matlab2014/2019a/2024a 2.附赠案例数据可直接运行matlab程序。 3.代码特点:参数化编程、参数可方便更改、代码编程思路清晰、注释明细。 4.适用对象:计算机,电子信息工程、数学等专业的大学生课程设计、期末大作业和毕业设计。

    【风电功率预测】基于BiTCN的风电功率多变量输入预测研究附Matlab代码.rar

    1.版本:matlab2014/2019a/2024a 2.附赠案例数据可直接运行matlab程序。 3.代码特点:参数化编程、参数可方便更改、代码编程思路清晰、注释明细。 4.适用对象:计算机,电子信息工程、数学等专业的大学生课程设计、期末大作业和毕业设计。

    CPPC++_这是由一块迷你带OV2640双DRV8833驱动TypeC接口PSRAM的ESP32PicoD4开发板驱.zip

    cppc++

    JAVA安卓手机与电脑的socket通信源码数据库 其他源码类型 WinForm

    安卓手机与电脑的socket通信源码

    Anaconda:JupyterNotebook使用教程.docx

    Anaconda:JupyterNotebook使用教程.docx

    Amazon S3:S3静态网站托管教程.docx

    Amazon S3:S3静态网站托管教程.docx

    Python商品销售数据分析可视化项目源码(期末大作业).zip

    Python商品销售数据分析可视化项目源码(期末大作业).zip,个人经导师指导并认可通过的98分大作业设计项目。主要针对计算机相关专业的正在做期末大作业设计的学生和需要项目实战练习的学习者,可作为课程设计、期末大作业,代码资料完整下载可用。 Python商品销售数据分析可视化项目源码(期末大作业).zip,个人经导师指导并认可通过的98分大作业设计项目。主要针对计算机相关专业的正在做期末大作业设计的学生和需要项目实战练习的学习者,可作为课程设计、期末大作业,代码资料完整下载可用。Python商品销售数据分析可视化项目源码(期末大作业).zip,个人经导师指导并认可通过的98分大作业设计项目。主要针对计算机相关专业的正在做期末大作业设计的学生和需要项目实战练习的学习者,可作为课程设计、期末大作业,代码资料完整下载可用。Python商品销售数据分析可视化项目源码(期末大作业).zip,个人经导师指导并认可通过的98分大作业设计项目。主要针对计算机相关专业的正在做期末大作业设计的学生和需要项目实战练习的学习者,可作为课程设计、期末大作业,代码资料完整下载可用。Python商品销售数据分析

    CPPC++_wechathookWeChatApi微信Api微信hook微信接口python微信接口java微信Ap.zip

    CPPC++_wechathookWeChatApi微信Api微信hook微信接口python微信接口java微信Ap

Global site tag (gtag.js) - Google Analytics