zoukankan      html  css  js  c++  java
  • java-@callersensitive注解

     
    这个注解是为了堵住漏洞用的。曾经有黑客通过构造双重反射来提升权限, 原理是当时反射只检查固定深度的调用者的类,看它有没有特权, 例如固定看两层的调用者(getCallerClass(2))。如果我的类本来没足够 权限群访问某些信息,那我就可以通过双重反射去达到目的:反射相关 的类是有很高权限的,而在 我->反射1->反射2 这样的调用链上,反射2 检查权限时看到的是反射1的类,这就被欺骗了,导致安全漏洞。 使用CallerSensitive后,getCallerClass不再用固定深度去寻找 actual caller(“我”),而是把所有跟反射相关的接口方法都标注上 CallerSensitive,搜索时凡看到该注解都直接跳过,这样就有效解决了 前面举例的问题
    转:链接:https://www.zhihu.com/question/274043800/answer/1098375809

    Reflection的getCallerClass的使用:可以得到调用者的类。
    参数:0- 返回 Reflection类 1- 返回自己的类 2- 返回调用者的类 3. 4. ....层层上传。
    public class Test {
    public static void main(String[] args) {
    System.out.println(Reflection.getCallerClass(0));
    System.out.println(Reflection.getCallerClass(1));
    System.out.println(Reflection.getCallerClass(2));
    System.out.println(Reflection.getCallerClass(3));
    System.out.println(Reflection.getCallerClass(4));
    }
    }


    执行结果:

    class sun.reflect.Reflection
    class test.Test
    null
    null
    null

  • 相关阅读:
    MySQL 元数据
    MySQL 复制表
    MySQL 临时表
    MySQL 索引
    MySQL ALTER
    MySQL 事务
    MySQL 正则表达式
    Mysql Join
    Python(数据库之表操作)
    Python知识点复习之__call__
  • 原文地址:https://www.cnblogs.com/fangyanr/p/14073631.html
Copyright © 2011-2022 走看看