【问题标题】:https only in google app enginehttps 仅在谷歌应用引擎中
【发布时间】:2011-07-19 02:04:35
【问题描述】:

我现在在做一个谷歌应用引擎项目。在我的应用程序中,我必须只允许 https 协议。而且我必须限制其他协议。它应该只允许 https。我在 web.xml 中添加了以下代码。

<security-constraint>
    <web-resource-collection>
        <web-resource-name>Protected Area</web-resource-name>
        <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <user-data-constraint>
        <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>
</security-constraint>

但在部署后,它可以在两种协议(http 和 https)上运行。如何限制http?

【问题讨论】:

  • 您正在测试您部署到的相同版本的应用程序吗?您是否尝试过删除“”?
  • 我正在测试我部署的相同版本。我没有通过删除网络资源名称进行测试。让我现在试试。谢谢。

标签: google-app-engine https maven-gae-plugin


【解决方案1】:

这是给未来的人的!!!

  1. 在 java 中在我的 web.xml 文件中添加以下代码对我有用

    <security-constraint>
       <web-resource-collection>
          <web-resource-name>HTTPS redirect</web-resource-name>
          <url-pattern>/*</url-pattern>
       </web-resource-collection>
       <user-data-constraint>
          <transport-guarantee>CONFIDENTIAL</transport-guarantee>
       </user-data-constraint>
    </security-constraint>
    
  2. 对于其他项目,在app.yaml文件的所有网址下添加secure: always

【讨论】:

    【解决方案2】:

    将此添加到您的 web.xml 文件中

    <security-constraint>
            <web-resource-collection>
                <web-resource-name>all</web-resource-name>
                <url-pattern>/*</url-pattern>
            </web-resource-collection>
            <user-data-constraint>
                <transport-guarantee>CONFIDENTIAL</transport-guarantee>
            </user-data-constraint>
        </security-constraint>
    

    【讨论】:

      【解决方案3】:

      如果您想坚持使用“web.xml”而不是使用“app.yaml”选项(这将在部署时覆盖您的 web.xml 和 appengine-web.xml 文件),您可以添加:

      <security-constraint>
          <web-resource-collection>
              <web-resource-name>everything</web-resource-name>
              <url-pattern>/*</url-pattern>
          </web-resource-collection>
          <user-data-constraint>
              <transport-guarantee>CONFIDENTIAL</transport-guarantee>
          </user-data-constraint>
      </security-constraint>
      

      参考: https://cloud.google.com/appengine/docs/java/config/webxml#Security_and_Authentication

      【讨论】:

        【解决方案4】:

        可以将各个处理程序配置为在 WEB-INF 文件夹中的 app.yaml 文件中要求 HTTPS,如下所述:Java Application Configuration Using app.yaml - Google App Engine

        您只需将这两个词添加到您的app.yaml 文件中相应的url 条目下:
        secure: always

        例如:

        - url: .*
          script: main.app
          secure: always
        

        然后,如果用户尝试使用 HTTP 访问 URL,她将自动重定向到 HTTPS。很酷。

        【讨论】:

        • 现在似乎已经为 GAE 添加了对自定义域的 SSL 支持。 developers.google.com/appengine/docs/ssl?hl=fr 感谢:安全:始终参与
        • 感谢您的评论。删除了该段落(因为此处没有删除线)。
        • 我可以在没有 SSL 的情况下在 GAE 上运行应用程序吗?
        • 是的。这是默认设置。
        • 如何使用 nodejs 做到这一点? url 条目似乎在 app.yaml 中不可用。
        【解决方案5】:

        您使用的是自己的域吗?目前,GAE 支持 *.appspot.com 域only 的 SSL。他们已经为非 appspot 域提供promising SSL 支持已有一段时间了,我们都在等待这方面的消息。

        【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-08-21
        • 2011-05-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多