הגדרת CORS לשרתים של VAST
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
בדפדפנים מודרניים חלות הגבלות אבטחה של מקור זהה על בקשות רשת של JavaScript, כלומר אפליקציית אינטרנט שפועלת ממקור אחד לא יכולה לאחזר נתונים שמוצגים ממקור אחר. ב-VAST, הגבלת האבטחה הזו מונעת
קובצי JavaScript XMLHttpRequests שנוצרו מקוד רינדור VAST של JavaScript מקריאה
תגובת VAST שהוצגה ממקור אחר.
הגבלת האבטחה הזו נועדה למנוע בעיות שבהן מקור אחד יכול
כדי לקרוא נתונים ממקור אחר שיכול להיות שהמשתמש מחובר אליו בלי המידע הזה
משתמש. ההגבלה יוצרת בעיות בקובצי VAST שמוצגים ב-JavaScript.
מאחר ששרת מודעות נמצא בדרך כלל בדומיין שונה
נגן המודעות. אבל שיתוף משאבים בין מקורות (CORS)
כותרות הן המלצה של W3C שמסייעת לעקוף את ההגבלה הזו באמצעות
ושיתוף בין מקורות שונים.
כותרות CORS
כדי למנוע בעיות במקורות שונים, התגובות של שרת המודעות מסוג VAST לבקשות שנשלחות על ידי ה-SDK חייבות לכלול את כותרות ה-HTTP CORS הבאות:
Access-Control-Allow-Origin: <origin header value>
Access-Control-Allow-Credentials: true
הכותרות האלה מאפשרות לנגן מודעות מכל מקור לקרוא את התגובה של VAST ממקור שרת המודעות. הגדרת הערך של Access-Control-Allow-Origin
לערך של הכותרת Origin
שנשלחה עם הבקשה להצגת מודעה, וגם
Access-Control-Allow-Credentials
אל true
כדי לוודא
שקובצי Cookie נשלחים ומתקבלים כראוי.
להוראות נוספות על הפעלת CORS, ראו הפעלת שיתוף משאבים בין מקורות.
אלא אם צוין אחרת, התוכן של דף זה הוא ברישיון Creative Commons Attribution 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/)."]]