Geoserver 中 SAMEORIGIN 的 X-Frame-Options 阻止查看我的 iframe
X-Frame-Options to SAMEORIGIN in Geoserver prevents my iframe to be viewed
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 被阻止,X-Frame-Options to SAMEORIGIN 是错误的。有人知道我该如何避免吗?
Geoserver 文档中有解决方法,但我的应用方式对应用没有任何影响。 https://docs.geoserver.org/latest/en/user/production/config.html
这是我在 start.sh 中的执行行,应该将策略设置为 false。
按照 GeoServer docs 中的建议很容易解决这个问题。
您需要将 geoserver.xframe.shouldSetPolicy
变量设置为 false 以关闭 X-Frame 拒绝或将 geoserver.xframe.policy
设置为 "ALLOW-FROM [uri]",其中 uri 是 iFrame 的位置。
将其添加到web.xml文件中:
<上下文参数>
<参数名称>geoserver.xframe.policy参数名称>
ALLOW-FROM http://example.com
上下文参数>
使用-D 形式将其添加到CATALINA_OPTS 或startup.sh
或startup.bat
中的exec 行。
-Dgeoserver.xframe.shouldSetPolicy=假
将其添加为系统变量(对于用户 运行 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
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 被阻止,X-Frame-Options to SAMEORIGIN 是错误的。有人知道我该如何避免吗?
Geoserver 文档中有解决方法,但我的应用方式对应用没有任何影响。 https://docs.geoserver.org/latest/en/user/production/config.html
这是我在 start.sh 中的执行行,应该将策略设置为 false。
按照 GeoServer docs 中的建议很容易解决这个问题。
您需要将 geoserver.xframe.shouldSetPolicy
变量设置为 false 以关闭 X-Frame 拒绝或将 geoserver.xframe.policy
设置为 "ALLOW-FROM [uri]",其中 uri 是 iFrame 的位置。
将其添加到web.xml文件中:
<上下文参数>
<参数名称>geoserver.xframe.policy参数名称>
ALLOW-FROM http://example.com
上下文参数>使用-D 形式将其添加到CATALINA_OPTS 或
startup.sh
或startup.bat
中的exec 行。-Dgeoserver.xframe.shouldSetPolicy=假
将其添加为系统变量(对于用户 运行 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