MALICIOUS_CODE EI_EXPOSE_REP中等 [英] MALICIOUS_CODE EI_EXPOSE_REP Medium

查看:372
本文介绍了MALICIOUS_CODE EI_EXPOSE_REP中等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我针对我的所有代码运行findbugs,只处理最重要的事情。我终于解决了最重要的问题,现在正在查看细节。我有一个简单的实体,比如用户:

I run findbugs against all of my code and only tackle the top stuff. I finally got the top stuff resolved and now am looking at the details. I have a simple entity, say a user:

public class User implements Serializable
{
    protected Date birthDate;

    public Date getBirthDate()
    {return(birthDate);}

    public void setBirthDate(final Date birthDate)
    {this.birthDate = birthDate;}
}

此课程不完整,所以不要因为它丢失我 serialVersionUID 和其他标准内容,我只关心 birthDate 安全漏洞。

This class is incomplete, so don't harp me about it missing the serialVersionUID and other standard stuff, I am just concerned with the birthDate security hole.

现在,根据findbugs报告,由于我返回对可变对象的引用,这是一个潜在的安全风险。但在实践中,这究竟有多重要?

Now, according to the findbugs report, since I am returning a reference to a mutable object, that is a potential security risk. In practice though, how much does that really matter?

http://findbugs.sourceforge.net/bugDescriptions.html#EI_EXPOSE_REP

我想我还是不知道问题是什么在这种情况下。我应该传入并设置日期吗?

I suppose I still don't really see what the problem is here in this case. Should I pass in a long and set the date from that?

Walter

推荐答案

我认为这里的关键是如果


如果不受信任的代码访问实例,并且对可变对象的未经检查的更改会危及安全性或其他重要属性,则需要执行不同的操作。

If instances are accessed by untrusted code, and unchecked changes to the mutable object would compromise security or other important properties, you will need to do something different.

换句话说, if 你想要一个不可变对象(即你没有 setBirthdate()方法),你的代码不正确,因为有人可以写:

So in other words, if you wanted an immutable object (i.e. you didn't have a setBirthdate() method), your code be incorrect, because someone could write:

Date date = user.getBirthDate();
date.setMonth(1);  // mutated!

所以你可能需要以下代码:

So you would probably want the following instead:

public Date getBirthDate()
{return new Date(birthDate.getTime());}  // essentially a clone

这篇关于MALICIOUS_CODE EI_EXPOSE_REP中等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆