是否在Google App Engine上运行的GWT应用程序受CSRF保护

时间:2010-06-05 16:31:25

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

我正在开发一个在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 Referer header
  3. 我可以看到我从Google设置的Cookie看起来像SID值,但我无法从有效负载中的序列化Java对象中判断出是否传递了令牌。我也不知道是否使用了Referer标题。

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

1 个答案:

答案 0 :(得分:6)

如果要将相同的代码放在常规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