【问题标题】:default Exception in GAEGAE 中的默认异常
【发布时间】: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;
}

【问题讨论】:

    标签: java google-app-engine


    【解决方案1】:

    一段时间后,有了一些新知识,我又回到了我的问题。
    这可以使用Spring MVC exception handling

    按照教程,我可以创建一个 GlobalExceptionHandler,它可以返回具体的 HTTP 值,以防在某些端点方法中引发异常。

    @ControllerAdvice
    class GlobalControllerExceptionHandler {
        @ResponseStatus(corresponding HTTP return value) 
        @ExceptionHandler(SomeException.class)
        public void handleException() {
            // Nothing to do
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-06
      • 1970-01-01
      • 2022-01-19
      • 1970-01-01
      相关资源
      最近更新 更多