简体   繁体   English

在Java中使用原始类型有什么安全隐患?

[英]What are the security implications of using raw types in Java?

I'm currently reviewing the security implications of various warnings in a large Java EE application. 我目前正在审查大型Java EE应用程序中各种警告的安全隐患。 Since most of the code is several years old, it contains many uses of the raw collection types: 由于大多数代码已有几年的历史,因此它包含了原始集合类型的许多用法:

List items = new List();

rather than the parametrized collection types: 而不是参数化的集合类型:

List<Item> items = new List<Item>();

The only security implication I can think of is that raw types cannot be statically type-checked at compilation and could potentially result in a run-time errors such as ClassCastException which, depending on where in the code this occurs, might lead to a denial of service. 我能想到的唯一安全隐含是在编译时不能对原始类型进行静态类型检查,并且可能导致运行时错误,例如ClassCastException ,这取决于代码中的位置,可能会导致拒绝服务。

Are there any other implications of using raw types that I'm not thinking of? 使用我没想过的原始类型还有其他含义吗?

I can't think of any other security implications. 我想不出任何其他安全隐患。

For non-security implications, generic types also do explicit casts* in the bytecode for types that return a generic. 对于非安全性含义,泛型类型还在返回泛型的类型的字节码中执行显式转换*。 Of course, this is transparent to the user, and it appears that the type returned is the generic type. 当然,这对用户是透明的,并且看起来返回的类型是泛型类型。

For example: 例如:

List<Item> items = new ArrayList<Item>();
// .get(int) and remove(int) return Item automatically

*This happens due to type erasure . *这是由于类型擦除而发生的。

Lack of type safety can lead to security problems. 缺乏类型安全可能导致安全问题。 For instance lets say this list was being used to build a query: 例如,假设此列表用于构建查询:

"select name from users where id="+items[x]

If items contained a string value of union select load_file('/var/passwd') an attacker could read an arbitrary file on your system. 如果items包含union select load_file('/var/passwd')的字符串值,则攻击者可以读取系统上的任意文件。 This is payload is assuming your using MySQL. 这是有效载荷假设你使用MySQL。 If items was a list of integers, then this query isn't vulnerable to sql injection. 如果items是整数列表,那么此查询不容易受到sql注入的影响。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM