該程序違反了移動代碼的安全編碼原則,它從 public 訪問方法中返回了一個 private 數組變量。
程序可以從 public 訪問方法中返回一個 private 數組變量,通過此種方式,您可以調用代碼來修改該數組的內容,還可以輕易地獲取數組的 public 訪問,并阻止程序員將其設置為 private 的計劃。
例 1:以下 Java Applet 代碼錯誤地從 public 訪問方法中返回了一個 private 數組變量。
public final class urlTool extends Applet {
private URL[] urls;
public URL[] getURLs() {
return urls;
}
...
}
[1] Standards Mapping - Common Weakness Enumeration - (CWE) CWE ID 495
[2] G. McGraw Securing Java.Chapter 7:Java Security Guidelines