【问题标题】:How to protect expired session clean-up with a security constraint?如何使用安全约束保护过期的会话清理?
【发布时间】:2014-01-06 23:05:50
【问题描述】:

保护尝试

网址

http://[GAE app URL]/_ah/sessioncleanup?clear

从 GAE 数据存储中清除 100 个过期会话(看起来如此)。

我想保护此 URL,以便可以使用 cron.xml 中的条目从应用程序中调用它

<cronentries>
  [...]

  <cron>
    <url>/_ah/sessioncleanup?clear</url>
    <description>Clean 100 expired sessions up</description>
    <schedule>[Schedule]</schedule>
  </cron>
</cronentries>

但并非来自任何遵循上述表单 URL 的用户。

所以我将以下代码添加到web.xml

<web-app>
[...]

  <security-constraint>
    <web-resource-collection>
      <web-resource-name>session-clean-up</web-resource-name>
      <url-pattern>/_ah/sessioncleanup</url-pattern>
    </web-resource-collection>
    <auth-constraint>
      <role-name>admin</role-name>
    </auth-constraint>
  </security-constraint>
</web-app>

我省略了将以下内容添加到web.xml,因为会话清理是在没有它的情况下使用手动 URL 调用进行的:

<web-app>
  [...]

  <servlet>
    <servlet-name>_ah_sessioncleanup</servlet-name>
    <servlet-class>com.google.apphosting.utils.servlet.SessionCleanupServlet</servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>_ah_sessioncleanup</servlet-name>
    <url-pattern>/_ah/sessioncleanup</url;-pattern>
  </servlet-mapping>
</web-app>

结果

遗憾的是,在将此代码部署到生产环境后,我发现添加上述&lt;security-constraint&gt; 并没有提供任何保护

http://[GAE app URL]/_ah/sessioncleanup?clear

http://[GAE app URL]/_ah/sessioncleanup

背景信息

我上面的代码基于 GAE issue 10047 (Request to document or publish code for SessionCleanupServlet) 中引用的 Google 员工的帖子。

我的问题

有人知道我该如何解决我的问题吗?

【问题讨论】:

  • 为什么要限制访问?最坏的情况是有人会为你打这个,清理过期的会话:)
  • @maximbr 这不是一个严重的问题,我同意。我只是不想将此功能公开给非管理员的任何人。

标签: java google-app-engine session google-cloud-datastore


【解决方案1】:

通过将 /* 附加到 URL 模式来调整我在 web.xml 中的条目会成功。相关的web.xml 条目变为:

    <web-app>
    [...]

      <security-constraint>
        <web-resource-collection>
          <web-resource-name>session-clean-up</web-resource-name>
          <url-pattern>/_ah/sessioncleanup/[asterisk]</url-pattern>
        </web-resource-collection>
        <auth-constraint>
          <role-name>admin</role-name>
        </auth-constraint>
      </security-constraint>
    </web-app>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-06
    • 2023-04-01
    • 2011-12-07
    • 2012-09-05
    • 2015-06-26
    • 2010-09-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多