【发布时间】:2015-08-24 10:34:32
【问题描述】:
我正在为我的后端使用 GAE。我想为每个 Cloud Endpoint 方法设置类似“默认异常”的内容。换句话说,如果该方法抛出了一些我不期望的异常(此异常未在 throws 的方法签名中列出),则抛出的异常可能包含有关我的数据库的一些信息......攻击者可以利用这些信息。此问题也称为 OWASP 10 [1] 中列出的“错误处理不当”。因此我想捕获这样的异常并抛出一个默认的自定义异常而不是它。
在实践中:
这段代码是我的问题的一个可能的“硬编码”解决方案。但是对于许多云端点方法来说,这写得太多了。所以我问是否有一些模式,或者 GAE 的一些 .xml 中的一些设置以更简单的方式解决了我的问题。
public User insertUser(User user) throws ExceptionA, ExceptionB, ExceptionC, DefaultException
//I am expecting that insertUser can throw ExceptionA, ExceptionB, ExceptionC
{
try {
}
catch (ExceptionA e1) {
throw new ExceptionA(e1.getMessage());
}
catch (ExceptionB e2) {
throw new ExceptionB(e2.getMessage());
}
catch (ExceptionC e3) {
throw new ExceptionC(e2.getMessage());
}
catch (Exception e4) {
/*This Exception can contain some exploitable information*/
throw new DefaultException("Something went wrong");
}
finally {
}
return user;
}
【问题讨论】: