Định cấu hình CORS cho máy chủ VAST
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Các trình duyệt hiện đại áp dụng các hạn chế bảo mật cùng nguồn gốc cho các yêu cầu mạng JavaScript, nghĩa là một ứng dụng web chạy từ một nguồn gốc không thể truy xuất dữ liệu được phân phát từ một nguồn gốc khác. Đối với VAST, hạn chế bảo mật này ngăn chặn
JavaScript XMLHttpRequests được tạo từ mã kết xuất VAST của JavaScript từ việc đọc
một lượt phản hồi quảng cáo VAST được phân phát từ một nguồn gốc khác.
Quy định hạn chế bảo mật này nhằm ngăn chặn các vấn đề mà một nguồn gốc có thể
để đọc dữ liệu từ một nguồn khác mà người dùng có thể đăng nhập mà không cần nguồn gốc đó
sự cho phép của người dùng. Hạn chế này gây ra vấn đề cho VAST được phân phát trong môi trường JavaScript vì máy chủ quảng cáo thường nằm trên một miền khác với trình phát quảng cáo. Tuy nhiên, tính năng Chia sẻ tài nguyên trên nhiều nguồn gốc (CORS)
tiêu đề là một đề xuất W3C giải quyết hạn chế này bằng cách cho phép
chia sẻ giữa nhiều nguồn gốc.
Tiêu đề CORS
Để tránh sự cố trên nhiều nguồn gốc, phản hồi của máy chủ quảng cáo VAST cho các yêu cầu do SDK đưa ra phải
bao gồm các tiêu đề HTTP CORS sau:
Access-Control-Allow-Origin: <origin header value>
Access-Control-Allow-Credentials: true
Các tiêu đề này cho phép trình phát quảng cáo trên bất kỳ nguồn gốc nào đọc phản hồi VAST từ nguồn gốc máy chủ quảng cáo. Đặt giá trị của Access-Control-Allow-Origin
vào giá trị của tiêu đề Origin
được gửi cùng với yêu cầu quảng cáo và
Access-Control-Allow-Credentials
đến true
để đảm bảo
cookie được gửi và nhận đúng cách.
Để biết thêm hướng dẫn về cách bật CORS, hãy xem phần Bật tính năng chia sẻ tài nguyên trên nhiều nguồn gốc.
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-08-31 UTC.
[null,null,["Cập nhật lần gần đây nhất: 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/)."]]