Codeql Java Reftype记录

最近在看codeql 对 fastjson 的误报。意外的发现codeql 标准库对java的支持比go要友好多了。

Reftype的说明是:

A common super-class for various kinds of reference types, including classes, interfaces, type parameters and arrays.

这个reftype 包含了类、接口、类型参数(范型吗?)和数组这四种代码结构。我们可以很轻松的利用它来抽象代码结构。go的话就显得很原始,哪个类型就基本就只能管那个类型。

比如 fastjson的 json.parseObject和parse的写法。

class FastJson extends RefType {

FastJson() { this.hasQualifiedName("com.alibaba.fastjson", "JSON") }

}

这里先把fastjson 的JSON 类型定义出来。

class FastJsonParseMethod extends Method {
  FastJsonParseMethod() {
    this.getDeclaringType() instanceof FastJson and
    this.hasName(["parse", "parseObject"])
  }
}

然后在定义方法。这个方法的定义类型属于 Fastjson的JSON类。 名字可以是parse和parseObject。

在官方提供的不安全的反序列化漏洞java/unsafe-deserialization 的sink 代码中是这么使用 FastJsonParseMethod 的

ma.getMethod() instanceof FastJsonParseMethod and
    not fastJsonLooksSafe() and
    sink = ma.getArgument(0)

ma是MethodAccess, sink是 Expr

参考文章:

RefType

posted @ 2024-09-04 00:12  Expl0it  阅读(31)  评论(0)    收藏  举报  来源