กำหนดค่า CORS สำหรับเซิร์ฟเวอร์ VAST
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
เบราว์เซอร์สมัยใหม่ใช้ข้อจำกัดด้านความปลอดภัยของต้นทางเดียวกันกับคำขอเครือข่าย JavaScript ซึ่งหมายความว่าเว็บแอปพลิเคชันที่ทำงานจากต้นทางหนึ่งจะไม่สามารถดึงข้อมูลจากต้นทางอื่นได้ สำหรับ VAST ข้อจำกัดด้านความปลอดภัยนี้จะป้องกัน
XMLHttpRequests ที่สร้างจากโค้ดการแสดงผล VAST ของ JavaScript จากการอ่าน
การตอบกลับโฆษณา VAST ที่แสดงจากต้นทางอื่น
ข้อจํากัดด้านความปลอดภัยนี้มีไว้เพื่อป้องกันปัญหาที่ต้นทางหนึ่งสามารถอ่านข้อมูลจากต้นทางอื่นที่ผู้ใช้อาจเข้าสู่ระบบอยู่โดยไม่ได้รับอนุญาตจากผู้ใช้รายนั้น การจำกัดนี้ทำให้เกิดปัญหาสำหรับ VAST ที่แสดงใน JavaScript
เนื่องจากเซิร์ฟเวอร์โฆษณามักจะอยู่บนโดเมนที่แตกต่างจาก
โปรแกรมเล่นโฆษณา อย่างไรก็ตาม กลไกการแชร์ทรัพยากรข้ามโดเมน (CORS)
เป็นคำแนะนำของ W3C ซึ่งหลีกเลี่ยงข้อจำกัดนี้โดยอนุญาตให้
แชร์กับต้นทางต่างๆ ได้
ส่วนหัว CORS
การตอบกลับของเซิร์ฟเวอร์โฆษณา VAST สําหรับคําขอที่ SDK ส่งมาต้องมีส่วนหัว CORS ของ HTTP ต่อไปนี้เพื่อหลีกเลี่ยงปัญหาข้ามโดเมน
Access-Control-Allow-Origin: <origin header value>
Access-Control-Allow-Credentials: true
ส่วนหัวเหล่านี้ช่วยให้โปรแกรมเล่นโฆษณาในต้นทางอ่านการตอบสนองด้วย VAST ได้
จากต้นทางของเซิร์ฟเวอร์โฆษณา ตั้งค่า Access-Control-Allow-Origin
กับค่าของส่วนหัว Origin
ที่ส่งไปพร้อมกับคำขอโฆษณา และ
Access-Control-Allow-Credentials
ไปยัง true
เพื่อให้แน่ใจ
ว่ามีการส่งและรับคุกกี้อย่างเหมาะสม
โปรดดูวิธีการเปิดใช้ CORS เพิ่มเติมที่หัวข้อ
เปิดใช้การแชร์ทรัพยากรแบบข้ามต้นทาง
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-31 UTC
[null,null,["อัปเดตล่าสุด 2025-08-31 UTC"],[[["\u003cp\u003eModern browsers restrict JavaScript from accessing data from different origins for security reasons, impacting VAST ads served from a separate domain than the player.\u003c/p\u003e\n"],["\u003cp\u003eCross-Origin Resource Sharing (CORS) headers enable cross-origin data sharing, allowing VAST ads to be served from a different domain than the player.\u003c/p\u003e\n"],["\u003cp\u003eVAST ad server responses should include specific CORS headers: \u003ccode\u003eAccess-Control-Allow-Origin\u003c/code\u003e (set to the request's \u003ccode\u003eOrigin\u003c/code\u003e header value) and \u003ccode\u003eAccess-Control-Allow-Credentials\u003c/code\u003e (set to \u003ccode\u003etrue\u003c/code\u003e).\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\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 in to 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. However, [Cross-Origin Resource Sharing (CORS)](//www.w3.org/TR/cors)\nheaders is a W3C recommendation that works around this restriction by allowing\nsharing across different origins.\n\nCORS headers\n------------\n\nTo avoid cross-origin problems, VAST ad server responses to requests made by the SDK must\ninclude following HTTP CORS headers: \n\n```text\nAccess-Control-Allow-Origin: \u003corigin header value\u003e\nAccess-Control-Allow-Credentials: true\n```\n\nThese headers allow an ads player on any origin to read the VAST response\nfrom the ad server origin. Set the value of `Access-Control-Allow-Origin`\nto the value of the `Origin` header sent with the ad request, and\n`Access-Control-Allow-Credentials` to `true` to ensure\nthat cookies are sent and received properly.\n\nFor further instructions on enabling CORS, see\n[Enable cross-origin resource sharing](//enable-cors.org/)."]]