- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
最近,我项目的安全团队发布了一份安全代码指南文档,旨在用作我们代码审查的一部分。首先让我印象深刻的是一个项目,上面写着“不要使用内部类”。我认为这似乎是一个非常严厉和笼统的声明。如果使用正确,内部类很好吗?但我做了一些谷歌搜索,发现 this ,为方便起见,在此引用。
Rule 5: Don't Use Inner Classes
Some Java language books say that inner classes can only be accessed by the outer classes that enclose them. This is not true. Java byte code has no concept of inner classes, so inner classes are translated by the compiler into ordinary classes that happen to be accessible to any code in the same package. And Rule 4 says not to depend on package scope for protection.
But wait, it gets worse. An inner class gets access to the fields of the enclosing outer class, even if these fields are declared private. And the inner class is translated into a separate class. In order to allow this separate class access to the fields of the outer class, the compiler silently changes these fields from private to package scope! It's bad enough that the inner class is exposed, but it's even worse that the compiler is silently overruling your decision to make some fields private. Don't use inner classes if you can help it. (Ironically, the new Java 2 doPrivileged() API usage guidelines suggest that you use an inner class to write privileged code. That's one reason we don't like the doPrivileged() API.)
我的问题是
最佳答案
此信息已经过时了大约十年。 AccessController.doPrivileged
广泛使用匿名内部类应该是一个线索。 (如果您不喜欢该 API,请考虑 JDK 中错误丢失的 try
-finally
block 的比例。)
策略是,如果两个类由不同的类加载器加载或具有不同的证书,则它们不能共享同一个包。为了获得更多保护,请在您的 jar list 中将包裹标记为已密封。因此,从安全的角度来看,“规则 4”是虚假的,因此也是这条规则。
在任何情况下,制定安全策略您都应该了解您要防范的内容。这些类型的策略用于处理可能具有不同信任级别的移动代码(移动的代码)。除非您正在处理移动代码,或者您的代码正在进入可能需要的库,否则这些预防措施几乎没有意义。然而,使用健壮的编程风格几乎总是一个好主意,例如复制和验证参数和返回值。
关于java - java的内部类会带来安全风险吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1935479/
我有一个 Magento 网站,其中似乎没有出现交叉销售产品。 在查看 Stack 和 Google 之后,似乎“重新索引数据”已经为很多人解决了这个问题。 我的问题是,执行此任务是否有任何风险?或者
为了避免在某些简单命令中使用括号,我编写了以下运算符以创建新的图形窗口。我的问题是:除了明显无法在我的变量“ newdev”上执行“ not”功能之外,我是否有“破坏” R中任何内容的风险? # fu
你好 我正在开发一个联系表格。我正在使用邮件功能将其通过电子邮件发送给网站管理员。 是否存在有人可以注入(inject)恶意 javascript 和任何其他注入(inject)攻击的风险? $to
我想知道在 Objective C 中将消息传递给 nil 对象不会执行任何操作,这样依赖是否存在任何风险。 在我的代码中,我有很多对 UIKit 和其他对象的弱引用,这些引用可能随时被清除。由于我来
我被指派修复遗留代码的安全问题,并获得了安全扫描的结果: Poor Error Handling: Server Error Message ( 10932 ) 基本上,当扫描尝试使用一些奇怪的代码进
我有一个匿名类,在创建时需要使用自引用。我的业务代码可以简化为如下代码,我知道这段代码: final Runnable runnable=new Runnable() { @Override
有几个基类是我无法控制的:- class BaseNode // Just a POD class. No VTable { void foo(); } class BaseHost { publ
这个问题已经有答案了: Do I have to guard against SQL injection if I used a dropdown? (11 个回答) 已关闭 7 年前。 我希望我的网
这是根据用户提供的输入创建表的简单过程: PROCEDURE `hackProcedure`( IN tab_name VARCHAR(63)) BEGIN IF (tab_name REGEXP '
我知道在您的网站上显示用户输入时,使用 php 中的 htmlentities() 之类的函数来清理用户输入很有用。但是这样的事情会带来 XSS 风险吗? " /> 像这样清理输入会更好吗? " />
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 关闭 10 年前。 Improve thi
谁能阐明图表上曲线的含义、阴影区域的含义以及轴的含义? 最佳答案 这是对风险随时间变化的预测。在 NCrunch wiki 中有一些文档对此进行了描述:http://wiki.ncrunch.net/
我有一个包含 200 万条记录的集合,如果可能的话,我希望在不停机的情况下在其上添加单个字段索引。 我的问题是:是否可以/需要备份集合?使用 azure 门户创建索引在后台运行它而不会造成任何服务停机
我正在使用Symfony2并使用 CSRF token 保护我的表单。 我有一个基于 Ajax 调用的评论系统。如果用户想要编辑他的评论,则会发生以下情况: 用户点击编辑按钮。 通过 ajax 加载“
Checkmark 扫描了我们的代码并显示这些代码存在二阶注入(inject)的风险像这样的代码 @SuppressWarnings("unchecked") public List> findByS
我有一个包含几百行的小型 MySQL 数据库(全部为文本,无图像)。我正在使用 iQuery 请求所有行并在客户端进行所有过滤。 iQuery 代码如下: $(document).ready( fun
如果我的网站只允许用户查看他们自己提交的数据,而永远不允许其他用户提交的数据(即没有一般的“帖子”等)——那么我的网站是否真的存在 XSS 风险? 我仍将致力于 XSS 解决方案(如 httmlspe
我正在构建一个 iframe,而不是 innerHTML , 但带有 createElement .. 我使用了两个不受信任的字符串: iframeEl.title = untrustedStr1;
我正在生成如下动态prepareStatement(字段可能会根据请求输入而变化)。 Veracode 扫描持续报告 SQL 注入(inject)风险 - CWE-89:SQL 命令中使用的特殊元素的
我有一个可以在英语和德语之间切换语言的应用程序。当使用德语时,我希望货币显示将自动转换为德语格式。因此,在我的程序中,我必须检查区域设置,然后根据所选语言转换货币。我选择使用 locale.setDe
我是一名优秀的程序员,十分优秀!