javascript - Geoserver 中 SAMEORIGIN 的 X-Frame-Options 阻止查看我的 iframe
问题描述
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。
解决方案
按照GeoServer 文档中的建议,这很容易解决。
您需要将geoserver.xframe.shouldSetPolicy
变量设置为 false 以关闭 X-Frame 拒绝或geoserver.xframe.policy
设置为“ALLOW-FROM [uri]”,其中 uri 是 iFrame 的位置。
将其添加到 web.xml 文件中:
<context-param>
<param-name>geoserver.xframe.policy</param-name>
<param-value>ALLOW-FROM http://example.com </param-value>
</context-param>将其添加到 CATALINA_OPTS 或 exec 行中
startup.sh
或startup.bat
使用 -D 形式。-Dgeoserver.xframe.shouldSetPolicy=false
将其添加为系统变量(对于运行 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
推荐阅读
- swift - 不知道如何得到完成的结果
- react-native - 数据更改后如何在本机中刷新内容
- c# - Xamarin 发布模式失败,但调试模式工作(已在 AndroidManifest.xml 中添加了 INTERNET_PERMISSION)
- python - 我们能否定义一个函数,其输出是 Python 中定义的另一个函数
- c++ - 我想返回一个值是否在一组值中的 True/False
- css - 在角度 7 中覆盖身体背景颜色
- mysql - 如何解决我的 codeigniter 批量更新问题?
- python - Codeforces 不接受我的输出,即使它看起来完全一样?
- vue.js - 如何在页面刷新按钮上应用计算类?
- php - 我怎样才能订购这个 MySQL 日期?