【问题标题】:Is a GWT app running on Google App Engine protected from CSRF是在受 CSRF 保护的 Google App Engine 上运行的 GWT 应用吗
【发布时间】:2011-02-28 04:43:01
【问题描述】:

我正在开发一个在 Google App Engine 上运行的 GWT 应用程序,我想知道我是否需要担心跨站点请求伪造或是否会自动为我处理?

对于每个需要身份验证的 RPC 请求,我都有以下代码:

public class BookServiceImpl extends RemoteServiceServlet implements
BookService {
    public void deleteInventory(Key<Inventory> inventoryKey) throws NotLoggedInException,  InvalidStateException, NotFoundException {
        DAO dao = new DAO();
            // This will throw NotLoggedInException if user is not logged in
        User user = dao.getCurrentUser();
            // Do deletion here
    }
}

public final class DAO extends DAOBase {
    public User getCurrentUser() throws NotLoggedInException {
            currentUser = UserServiceFactory.getUserService().getCurrentUser();
            if(currentUser == null) {
                throw new NotLoggedInException();
            }
        return currentUser;
    }

我找不到任何关于UserService 如何检查身份验证的文档。依赖上面的代码就足够了吗,还是我需要更多?我是这方面的初学者,但据我了解,避免 CSRF 攻击的一些策略是:

  1. 在 请求有效负载,而不仅仅是 检查 cookie
  2. 检查 HTTP 引用标头

我可以看到我从 Google 设置了带有 SID 值的 cookie,但是我无法从有效负载中的序列化 Java 对象中判断是否传递了令牌。我也不知道是否使用了Referer标头。

那么,我是否担心没有问题?如果不是,这里最好的策略是什么?这是一个很常见的问题,必须有标准的解决方案......

【问题讨论】:

    标签: java security google-app-engine gwt csrf


    【解决方案1】:

    如果您将相同的代码放在常规 servlet 中,您肯定会受到 XSRF 的攻击。但是由于您使用的是 GWT RemoteServiceServlet - 答案取决于您使用的 GWT 版本。

    从尚未发布的 GWT 2.1 开始,RPC 机制添加请求标头并验证 RemoteServiceServlet 中是否存在这些标头。 This has its limitations - 特别是旧版本的 flash 允许您从不同的域发送请求标头,但这确实让潜在的攻击者更加困难。

    如果您想充分保护自己免受 XSRF 的侵害,请参阅 Lombardi's Development blog。该博客讨论了两种技术。第一个是简单的更改,将 2.1 端口更改为旧版本的 GWT。第二种方法需要将会话标识符复制为请求参数,并且是防止 XSRF 的推荐方法。

    参考文献

    1. GWT RPC - Does it do enough to protect against CSRF?
    2. Lombardi development blog on GWT RPC and XSRF
    3. Security for GWT Applications

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-04-16
      • 1970-01-01
      • 2017-04-23
      • 2013-12-20
      • 2016-03-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多