Geoserver 中 SAMEORIGIN 的 X-Frame-Options 阻止查看我的 iframe

问题描述 投票:0回答:2

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/product/config.html

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

javascript maps openlayers geoserver x-frame-options
2个回答
3
投票

按照GeoServer 文档中的建议很容易解决这个问题。

您需要将

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

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


    geoserver.xframe.policy
    允许来自 http://example.com

  2. 使用 -D 形式将其添加到

    startup.sh
    startup.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

0
投票

抱歉,我无法在这里发表评论。我可以问 Felipe Andrioli 或知道的人,你是如何删除 SAMEORIGIN 的吗?我有同样的原因需要允许来自 arcgis online 的弹出框架。然而,X-Frame-Opionts: SAMEORIGIN 可以防止这种情况发生。我尝试使用上面的所有建议来更改 web.xml 或startup.sh,并且它保持为 SAMEORIGIN。我正在使用一个定制的 Dockerfile,请帮我看看。

# Use the base image
FROM docker.osgeo.org/geoserver:2.24.2

ENV GEOSERVER_ADMIN_USER=admin
ENV GEOSERVER_ADMIN_PASSWORD=geoserver
ENV ROOT_WEBAPP_REDIRECT=true
# ENV SKIP_DEMO_DATA=true

# Enable CORS and set CORS configurations
ENV CORS_ENABLED=true
# ENV CORS_ALLOWED_ORIGINS="https://example.maps.arcgis.com/"
# ENV CORS_ALLOWED_METHODS=GET,POST,PUT,DELETE,HEAD,OPTIONS
# ENV CORS_ALLOWED_HEADERS=*
# ENV CORS_ALLOW_CREDENTIALS=true

ENV INSTALL_EXTENSIONS=true
ENV STABLE_EXTENSIONS="vectortiles"

EXPOSE 8080

# Copy the custom web.xml file into the container
COPY src/web.xml /opt/apache-tomcat-9.0.84/webapps/geoserver/WEB-INF/web.xml

COPY src/custom_osgeo_startup.sh /opt/apache-tomcat-9.0.84/bin/startup.sh
RUN chmod +x /opt/apache-tomcat-9.0.84/bin/startup.sh

COPY src/custom_osgeo_opt_startup.sh /opt/startup.sh
RUN chmod +x /opt/startup.sh
❯ curl -v http://localhost:8085/geoserver/web                                                                  
*   Trying 127.0.0.1:8085...
* Connected to localhost (127.0.0.1) port 8085 (#0)
> GET /geoserver/web HTTP/1.1
> Host: localhost:8085
> User-Agent: curl/7.88.1
> Accept: */*
> 
< HTTP/1.1 302 
< X-Frame-Options: SAMEORIGIN
< X-Content-Type-Options: nosniff
< Set-Cookie: JSESSIONID=5B16684F0C45B797C8955AEF2AB27FA3; Path=/geoserver; HttpOnly
< Location: /geoserver/web/
< Content-Length: 0
< Date: Sun, 28 Jan 2024 18:21:55 GMT
© www.soinside.com 2019 - 2024. All rights reserved.