為 VAST 伺服器設定 CORS
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
新式瀏覽器會對 JavaScript 網路套用相同來源的安全性限制
也就是說,從一個來源執行的網頁應用程式無法擷取資料
其他資源。針對 VAST,這項安全限制可避免
使用 JavaScript VAST 顯示程式碼建立的 JavaScript XMLHttpRequests
,也就是讀取
另一個來源提供的 VAST 廣告回應。
這項安全性限制旨在防止以下問題發生:單一來源能
來從使用者可能登入的另一個來源讀取資料
授予使用者的權限這項限制為 JavaScript 放送的 VAST 帶來問題
因為廣告伺服器通常位於
廣告播放器。
跨來源資源分享 (CORS) 標頭是一種 W3C 草擬規格,
這樣就能在不同來源之間分享檔案可在 JavaScript 中提供
VAST 廣告伺服器回應必須包含下列 HTTP CORS 標頭:
Access-Control-Allow-Origin: <origin header value>
Access-Control-Allow-Credentials: true
敬上
這個 HTTP 標頭允許任何來源上的廣告播放器讀取 VAST 回應
來自廣告伺服器來源的請求。
Access-Control-Allow-Origin:
的值
必須是與廣告請求一併傳送的
Origin
標頭值。
Access-Control-Allow-Credentials:
標頭可確保
正確傳送及接收 Cookie。
詳情請參閱跨來源資源分享的 W3C 草擬規格。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-31 (世界標準時間)。
[null,null,["上次更新時間:2025-08-31 (世界標準時間)。"],[[["\u003cp\u003eModern browsers restrict JavaScript from accessing data from different origins for security reasons, impacting VAST ad serving.\u003c/p\u003e\n"],["\u003cp\u003eThis restriction prevents JavaScript in VAST ads from loading resources like the ad response if they are hosted on a different domain than the player.\u003c/p\u003e\n"],["\u003cp\u003eCross-Origin Resource Sharing (CORS) headers enable cross-origin data access, requiring VAST ad servers to include specific headers to allow JavaScript ad players to read responses.\u003c/p\u003e\n"],["\u003cp\u003eThese CORS headers, \u003ccode\u003eAccess-Control-Allow-Origin\u003c/code\u003e and \u003ccode\u003eAccess-Control-Allow-Credentials\u003c/code\u003e, specify permitted origins and ensure proper cookie handling for seamless ad delivery.\u003c/p\u003e\n"]]],[],null,["# Configure CORS for VAST servers\n\nModern browsers apply same-origin security restrictions to JavaScript network\nrequests, meaning that a web application running from one origin cannot retrieve data\nserved from a different origin. For VAST, this security restriction prevents\nJavaScript `XMLHttpRequests` made from JavaScript VAST rendering code from reading\na VAST ad response served from a different origin.\n\n\nThis security restriction is meant to prevent issues where one origin is able\nto read data from another origin that a user may be logged into without that\nuser's permission. The restriction poses problems for VAST served in a JavaScript\nenvironment because an ad server is often on a different domain than the\nads player.\n\n\nCross-Origin Resource Sharing (CORS) headers is a W3C draft specification meant\nto allow sharing across different origins. To be servable in a JavaScript\nenvironment a VAST ad server's response must include the following HTTP CORS headers: \n\n```text\nAccess-Control-Allow-Origin: \u003corigin header value\u003e\nAccess-Control-Allow-Credentials: true\n```\nThis HTTP header allows an ads player on any origin to read the VAST response from the ad server origin. The value of `Access-Control-Allow-Origin:` should be the value of the `Origin` header sent with the ad request. The `Access-Control-Allow-Credentials:` header ensures that cookies are sent and received properly.\n\n\u003cbr /\u003e\n\n\nFor more information, refer to the [W3C Draft Specification on Cross-Origin Resource Sharing](//www.w3.org/TR/cors)"]]