美文网首页hello world
@CallerSensitive一些理解

@CallerSensitive一些理解

作者: 王侦 | 来源:发表于2019-06-21 20:22 被阅读0次
    @CallerSensitive
    public static Lookup lookup() {
        return new Lookup(Reflection.getCallerClass());
    }

    @CallerSensitive
    public static native Class<?> getCallerClass();

JEP 176: Mechanical Checking of Caller-Sensitive Methods中的说明:

Improve the security of the JDK's method-handle implementation by replacing 
the existing hand-maintained list of caller-sensitive methods with a mechanism 
that accurately identifies such methods and allows their callers to be discovered reliably.

使用能够精确识别caller-sensitive方法并且保证这些方法的调用者可靠地被发现的一种机制 代替 现存的手动维护的caller-sensitive方法表,提高JDK method-handler实现的安全性。

A caller-sensitive method varies its behavior according to the class of its immediate caller. 
It discovers its caller's class by invoking the sun.reflect.Reflection.getCallerClass method.

caller-sensitive方法会根据其直接调用者的类型改变其行为。通过调用sun.reflect.Reflection.getCallerClass方法可以获得调用者class类型。

Most caller-sensitive methods act in some way as an agent for the caller. 
When invoked via reflection, these methods must be handled specially in order to 
ensure that the class of the actual caller, rather than some class of the reflection mechanism itself, 
is returned by the getCallerClass method.

大多数caller-sensitive方法某种程度上是作为调用者的代理。当通过反射调用时,这些方法必须经过特殊处理以确保getCallerClass返回的是实际调用者的class类型,而不是反射机制本身的某些类。

另外,据JVM注解@CallSensitive文章,有一个类似的解释:

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

相关文章

  • @CallerSensitive一些理解

    JEP 176: Mechanical Checking of Caller-Sensitive Methods中...

  • Java CallerSensitive

    CallerSensitive ensures correct caller of a method is ret...

  • @CallerSensitive注解(随笔)

    前言 在阅读Unsafe源码是,以下是Unsafe部分源码: 我们可以看到,这个方法上有一个@CallerSens...

  • CallerSensitive注解是什么鬼?

    https://www.jianshu.com/p/cec71079acdf4.3.5用@CallerSensit...

  • 一些理解

    近日,江苏南京,一女生深夜乘坐网约车发现司机改道,怀疑其绕路。两人产生矛盾后,女生越想越害怕,在途经收费站时,她强...

  • 一些理解

    周五了,算算时间,上了好长时间的班,不知道怎么说,做不到洒脱,顾虑那么多。好多时候,其实好讨厌自己的性格,在这一块...

  • flutter 一些理解

    刷新机制1.Widget不能改变,只能重建并且携带着State的newWidget来代替oldWidget2.当调...

  • 理解一些词

    多肉 我说的不是我自己,而是背景上的这种植物 有着饱满厚实的叶子,甚至不能称之为“叶子” 飞乐鸟的绘系列中最新的一...

  • 理解一些词

    耐心 传说中的金牛座都是慢条斯理单纯温和极具耐心 而我遇到的金牛要不就是暴脾气,要不就是死脑筋,要不就是心机鬼,要...

  • 多一些理解

    2020.04.26 第14天 今天与孩子们一起共读《想换父母的男孩》。在前面的文字中,我曾提过,我在童年时期也想...

网友评论

    本文标题:@CallerSensitive一些理解

    本文链接:https://www.haomeiwen.com/subject/aynuqctx.html