【问题标题】:X-Frame-Options to SAMEORIGIN in Geoserver prevents my iframe to be viewedGeoserver 中 SAMEORIGIN 的 X-Frame-Options 阻止查看我的 iframe
【发布时间】:2019-01-28 11:52:54
【问题描述】:

exec "$_RUNJAVA" $JAVA_OPTS $MARLIN_ENABLER -DGEOSERVER_DATA_DIR="$GEOSERVER_DATA_DIR" -Dgeoserver.xframe.shouldSetPolicy=false -Djava.awt.headless=true -DSTOP.PORT=8079 -DSTOP.KEY=geoserver -jar start.jar 

我正在开发一个使用 Geoserver 来托管我的图层和数据的地图应用程序。我的目标之一是,当单击地图中的某个点时,会出现一个 iframe,其中显示有关同一点的一些信息。当我在我的应用程序中意识到 iframe 被阻止时,SAMEORIGIN 的 X-Frame-Options 是错误。有人知道我该如何避免吗?

Geoserver 文档有解决方案,但我应用它的方式对应用程序没有影响。 https://docs.geoserver.org/latest/en/user/production/config.html

这是我在 start.sh 中的 exec 行,应该将策略设置为 false。

【问题讨论】:

  • 但是还没有修复:/
  • 实际上它按设计工作,关闭 X-Frame 是不好的
  • 它可以防止点击劫持。但是当我点击地图中的某个点时,我真的需要显示一些信息:/
  • 究竟尝试了什么?

标签: javascript maps openlayers geoserver x-frame-options


【解决方案1】:

按照GeoServer docs 中的建议可以轻松解决此问题。

您需要将 geoserver.xframe.shouldSetPolicy 变量设置为 false 以关闭 X-Frame 拒绝或将 geoserver.xframe.policy 设置为“ALLOW-FROM [uri]”,其中 uri 是 iFrame 的位置。

  1. 将其添加到 web.xml 文件中:


    geoserver.xframe.policy
    ALLOW-FROM http://example.com

  2. 使用 -D 形式将其添加到 startup.shstartup.bat 中的 CATALINA_OPTS 或 exec 行。

    -Dgeoserver.xframe.shouldSetPolicy=false

  3. 将其添加为系统变量(用于运行 tomcat 或 jetty 的用户)。

    导出 geoserver.xframe.shouldSetPolicy=false 设置 geoserver.xframe.shouldSetPolicy=false

然后,您可以通过运行一个简单的 curl 请求轻松测试它是否正常工作:

第一个不属于上述情况的:

curl -v http://localhost:8080/geoserver/web
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /geoserver/web HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.58.0
> Accept: */*
> 
< HTTP/1.1 302 
< X-Frame-Options: SAMEORIGIN
< Set-Cookie: JSESSIONID=F844AFA320C4F711807759A2BEC96625.route1; Path=/geoserver; HttpOnly
< Location: /geoserver/web/;jsessionid=F844AFA320C4F711807759A2BEC96625.route1
< Content-Length: 0
< Date: Tue, 29 Jan 2019 11:15:49 GMT
< 
* Connection #0 to host localhost left intact

然后使用策略集:

curl -v http://localhost:8085/geoserver/web
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8085 (#0)
> GET /geoserver/web HTTP/1.1
> Host: localhost:8085
> User-Agent: curl/7.58.0
> Accept: */*
> 
< HTTP/1.1 302 Found
< X-Frame-Options: ALLOW-FROM http://example.com
< Set-Cookie: JSESSIONID=node010koqik22omjt1b1wbqewjrmcl0.node0;Path=/geoserver
< Expires: Thu, 01 Jan 1970 00:00:00 GMT
< Location: http://localhost:8085/geoserver/web/;jsessionid=node010koqik22omjt1b1wbqewjrmcl0.node0
< Content-Length: 0
< Server: Jetty(9.4.12.v20180830)
< 
* Connection #0 to host localhost left intact

最后关闭 XFrame:

curl -v http://localhost:8085/geoserver/web
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8085 (#0)
> GET /geoserver/web HTTP/1.1
> Host: localhost:8085
> User-Agent: curl/7.58.0
> Accept: */*
> 
< HTTP/1.1 302 Found
< Set-Cookie: JSESSIONID=node01pdyu4npf3xt6130w8gehjai7t0.node0;Path=/geoserver
< Expires: Thu, 01 Jan 1970 00:00:00 GMT
< Location: http://localhost:8085/geoserver/web/;jsessionid=node01pdyu4npf3xt6130w8gehjai7t0.node0
< Content-Length: 0
< Server: Jetty(9.4.12.v20180830)
< 
* Connection #0 to host localhost left intact

【讨论】:

  • 我该怎么做上面写的2和3步骤,因为,我已经做了第一个,没有发生任何事情,使用curl检查它,X-Frame-Options仍然是SAMEORIGIN跨度>
  • 请使用您的 startup.sh 文件中的 full 行编辑您的问题
  • 为什么要这么难?不仅仅是算法实现......我用我的 start.sh exec 行编辑了它,你发现有什么问题吗?
  • 你重启geoserver了吗?
  • 每次我测试新的东西时,我都会重新启动地理服务器。
猜你喜欢
  • 2012-08-24
  • 1970-01-01
  • 2021-05-09
  • 1970-01-01
  • 2019-06-02
  • 2015-10-27
  • 1970-01-01
  • 1970-01-01
  • 2019-06-22
相关资源
最近更新 更多