FixVibe
Covered by FixVibehigh

CORS 配置錯誤:政策過於寬鬆的風險 ZXCVFIXVIBESEND ZXCVFIXVIBESEG1 了解 CORS 錯誤配置如何讓攻擊者繞過同源策略並從 ZXCVFIXVIBETOKEN1ZXCV 產生的 Web 應用程式竊取敏感使用者資料。 ZXCVFIXVIBESEND ZXCVFIXVIBESEG2 跨來源資源共享(CORS)是一種旨在放寬同源策略(SOP)的瀏覽器機制。雖然對於現代 Web 應用程式來說是必要的,但不正確的實作(例如回顯請求者的 Origin 標頭或將「空」來源列入白名單)可能會允許惡意網站竊取私人使用者資料。 ZXCVFIXVIBESEND ZXCVFIXVIBESEG3 ## 影響 ZXCVFIXVIBESEND ZXCVFIXVIBESEG4 攻擊者可以從易受攻擊的應用程式 CORS 的用戶那裡竊取敏感的、經過身份驗證的資料。如果使用者在登入易受攻擊的應用程式時造訪惡意網站,則惡意網站可以向應用程式的 ZXCVFIXVIBETOKEN4ZXCV 發出跨網域請求並讀取回應 ZXCVFIXVIBETOKEN1ZXCVZXCVFIXVIBETOKEN2ZXCV。這可能會導致私人資訊被盜,包括使用者設定檔、CSRF 令牌或私人訊息 ZXCVFIXVIBETOKEN3ZXCV。 ZXCVFIXVIBESEND ZXCVFIXVIBESEG5 ## 根本原因 ZXCVFIXVIBESEND ZXCVFIXVIBESEG6 ZXCVFIXVIBETOKEN2ZXCV 是一種基於 HTTP 標頭的機制,可讓伺服器指定允許哪些來源(網域、方案或連接埠)載入資源 CORS。當伺服器的 ZXCVFIXVIBETOKEN3ZXCV 策略過於靈活或 ZXCVFIXVIBETOKEN1ZXCV 實施不善時,通常會出現漏洞: ZXCVFIXVIBESEND ZXCVFIXVIBESEG7 * **反射的原始標頭:** 某些伺服器從用戶端請求中讀取 CORS 標頭,並將其回顯在 ZXCVFIXVIBETOKEN1ZXCV (ACAO) 回應標頭 ZXCVFIXVIBETOKEN2ZXCV 中。這有效地允許任何網站存取資源 ZXCVFIXVIBETOKEN3ZXCV。 ZXCVFIXVIBESEND ZXCVFIXVIBESEG8 * **配置錯誤的通配符:** 雖然 CORS 通配符允許任何來源存取資源,但它不能用於需要憑證(如 cookie 或授權標頭)ZXCVFIXVIBETOKEN1ZXCV 的請求。開發人員經常嘗試根據要求 ZXCVFIXVIBETOKEN2ZXCV 動態產生 ACAO 標頭來繞過此問題。 ZXCVFIXVIBESEND ZXCVFIXVIBESEG9 * **將「null」列入白名單:**某些應用程式將 CORS 來源列入白名單,該來源可以透過重定向請求或本機檔案觸發,從而允許惡意站點偽裝成 ZXCVFIXVIBETOKEN1ZXCV 來源來取得 ZXCVFIXVIBETOKEN2ZXCVZCVFEN2ZXCVZ74IXA3743444343X 的存取權限。 ZXCVFIXVIBESEND ZXCVFIXVIBESEG10 * **解析錯誤:** 驗證 CORS 標頭時正則表達式或字串匹配中的錯誤可能允許攻擊者使用 ZXCVFIXVIBETOKEN1ZXCV ZXCVFIXVIBETOKEN2ZXCV 等域。 ZXCVFIXVIBESEND ZXCVFIXVIBESEG11 需要注意的是,ZXCVFIXVIBETOKEN1ZXCV 並不能防止跨站要求偽造 (CSRF) CORS。 ZXCVFIXVIBESEND ZXCVFIXVIBESEG12 ## 具體修復 ZXCVFIXVIBESEND ZXCVFIXVIBESEG13 * **使用靜態白名單:** 避免從要求的 ZXCVFIXVIBETOKEN1ZXCV 標頭 ZXCVFIXVIBETOKEN2ZXCV 動態產生 CORS 標頭。相反,將請求的來源與受信任域 ZXCVFIXVIBETOKEN3ZXCV 的硬編碼清單進行比較。 ZXCVFIXVIBESEND ZXCVFIXVIBESEG14 * **避免「空」來源:** 切勿將 CORS 包含在允許來源 ZXCVFIXVIBETOKEN1ZXCV 的白名單中。 ZXCVFIXVIBESEND ZXCVFIXVIBESEG15 * **限制憑證:** 如果特定跨源互動 ZXCVFIXVIBETOKEN1ZXCV 絕對必要,則僅設定 CORS。 ZXCVFIXVIBESEND ZXCVFIXVIBESEG16 * **使用正確的驗證:** 如果您必須支援多個來源,請確保 CORS 標頭的驗證邏輯穩健,並且不能被子域或類似域 ZXCVFIXVIBETOKEN1ZXCV 繞過。 ZXCVFIXVIBESEND ZXCVFIXVIBESEG17 ## CORS 如何測試它 ZXCVFIXVIBESEND ZXCVFIXVIBESEG18 ZXCVFIXVIBETOKEN1ZXCV 現在將此作為門控主動檢查。域驗證後,CORS 發送具有合成攻擊者來源的同源 ZXCVFIXVIBETOKEN2ZXCV 請求,並審查 ZXCVFIXVIBETOKEN4ZXCV 回應標頭。它報告反映了非公共 ZXCVFIXVIBETOKEN3ZXCV 端點上的任意來源、通配符認證的 ZXCVFIXVIBETOKEN5ZXCV 和完全開放的 ZXCVFIXVIBETOKEN6ZXCV,同時避免了公共資產噪音。

Cross-Origin Resource Sharing (CORS) is a browser mechanism designed to relax the Same-Origin Policy (SOP). While necessary for modern web apps, improper implementation—such as echoing the requester's Origin header or whitelisting the 'null' origin—can allow malicious sites to exfiltrate private user data.

CWE-942

Impact

An attacker can steal sensitive, authenticated data from users of a vulnerable application [S2]. If a user visits a malicious website while logged into the vulnerable app, the malicious site can make cross-origin requests to the app's API and read the responses [S1][S2]. This can lead to the theft of private information, including user profiles, CSRF tokens, or private messages [S2].

Root Cause

CORS is an HTTP-header based mechanism that allows servers to specify which origins (domain, scheme, or port) are permitted to load resources [S1]. Vulnerabilities typically arise when a server's CORS policy is too flexible or poorly implemented [S2]:

  • Reflected Origin Header: Some servers read the Origin header from a client request and echo it back in the Access-Control-Allow-Origin (ACAO) response header [S2]. This effectively allows any website to access the resource [S2].
  • Misconfigured Wildcards: While the * wildcard allows any origin to access a resource, it cannot be used for requests that require credentials (like cookies or Authorization headers) [S3]. Developers often try to bypass this by dynamically generating the ACAO header based on the request [S2].
  • Whitelisting 'null': Some applications whitelist the null origin, which can be triggered by redirected requests or local files, allowing malicious sites to masquerade as a null origin to gain access [S2][S3].
  • Parsing Errors: Mistakes in regex or string matching when validating the Origin header can allow attackers to use domains like trusted-domain.com.attacker.com [S2].

It is important to note that CORS is not a protection against Cross-Site Request Forgery (CSRF) [S2].

Concrete Fixes

  • Use a Static Whitelist: Avoid dynamically generating the Access-Control-Allow-Origin header from the request's Origin header [S2]. Instead, compare the request's origin against a hardcoded list of trusted domains [S3].
  • Avoid the 'null' Origin: Never include null in your whitelist of allowed origins [S2].
  • Restrict Credentials: Only set Access-Control-Allow-Credentials: true if absolutely necessary for the specific cross-origin interaction [S3].
  • Use Proper Validation: If you must support multiple origins, ensure the validation logic for the Origin header is robust and cannot be bypassed by subdomains or similar-looking domains [S2].

How FixVibe tests for it

FixVibe now includes this as a gated active check. After domain verification, active.cors sends same-origin API requests with a synthetic attacker origin and reviews CORS response headers. It reports reflected arbitrary origins, wildcard credentialed CORS, and wide-open CORS on non-public API endpoints while avoiding public asset noise.