簡體   English   中英

Access-Control-Allow-Origin:當我在 Nginx 和 Tomcat 中設置值時檢測到 null

[英]Access-Control-Allow-Origin: null got detected while I've set value in Nginx and Tomcat

WebInspect 檢測到目標應用程序支持 CORS 請求的“Origin: null”,使其容易受到 CORS 攻擊。 這是漏洞掃描報告的一個高問題。
我已經在 Tomcat 的 web.xml 和 Nginx 中設置了相應的標頭值“Access-Control-Allow-Origin:*.example.com”以解決這個問題,但仍然被檢測為空。
但是如果通過瀏覽器檢查,響應頭顯示“Access-Control-Allow-Origin:*.example.com”,為什么掃描報告中仍然存在空值? 這可能是一個錯誤的問題嗎?

在 nginx.conf 中:

    location /frontend{
    add_header Access-Control-Allow-Origin *.example.com
  }

瀏覽器響應頭:
 HTTP/1.1 200 Server: nginx Date: Mon, 08 Nov 2021 04:05:21 GMT Content-Type: text/html;charset=UTF-8 Transfer-Encoding: chunked Connection: keep-alive Vary: Origin Vary: Access-Control-Request-Method Vary: Access-Control-Request-Headers Last-Modified: Wed, 03 Nov 2021 07:16:34 GMT ETag: W/"0d4a4d79789d33107032637b2af5c74f1" X-Content-Type-Options: nosniff X-XSS-Protection: 1; mode=block Cache-Control: no-cache, no-store, max-age=0, must-revalidate Pragma: no-cache Expires: 0 X-Frame-Options: DENY Access-Control-Allow-Origin: *.example.com Content-Encoding: gzip

掃描報告的圖像顯示“來源:空”

快速回答:
將下面的設置放在 nginx.conf 中

location /frontend{
    proxy_set_header Origin '*.example.com';
}

解釋:
掃描報告顯示了攻擊請求是如何設置的,因此使用 Postman 模擬所有請求標頭值並查看 nginx 實際響應的內容將一目了然。
結果是請求標頭Origin:null ,響應顯示兩個Access-Control-Allow-Origin ,一個是null ,另一個是 * .example.com ,並且 null 覆蓋add_header Access-Control-Allow-Origin *.example.com nginx.conf 中的add_header Access-Control-Allow-Origin *.example.com設置,因為在項目中有一個 Spring Configuration 設置CorsConfigurationSource.setAllowedOrigins(Arrays.asList("*")) ,這表明 Access-Control-Allow-Origin 的所有響應標頭都可以Origin 中的請求。 因此,使用proxy_set_header在傳遞給 nginx 的請求頭中重新定義了 Origin。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM