Skip to content

Commit ec29a3d

Browse files
author
Daniel Neto
committed
fix: Update allowOrigin function to support dynamic CORS headers
1 parent 88711b4 commit ec29a3d

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

objects/functions.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2757,11 +2757,29 @@ function object_to_array($obj, $level = 0)
27572757
}
27582758
}
27592759

2760-
function allowOrigin()
2760+
function allowOrigin($allowAll = false)
27612761
{
27622762
global $global;
27632763
cleanUpAccessControlHeader();
27642764

2765+
// Public resources (e.g. VAST/VMAP ad XML) should be readable by any
2766+
// origin. Pass $allowAll = true to emit Access-Control-Allow-Origin: *
2767+
// and skip credential-related headers (browsers reject credentials + *).
2768+
if ($allowAll) {
2769+
header('Access-Control-Allow-Origin: *');
2770+
header('Access-Control-Allow-Private-Network: true');
2771+
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS, HEAD');
2772+
header('Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With, ua-resolution, APISecret, Origin, Accept, Access-Control-Request-Method, Access-Control-Request-Headers');
2773+
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
2774+
header('Access-Control-Max-Age: 86400');
2775+
header('Access-Control-Allow-Private-Network: true');
2776+
http_response_code(204);
2777+
exit;
2778+
}
2779+
return;
2780+
}
2781+
2782+
27652783
// Derive the site's own origin from configuration so we can validate
27662784
// inbound Origin headers instead of blindly reflecting them.
27672785
// Reflecting an arbitrary Origin with Access-Control-Allow-Credentials:true

plugin/AD_Server/VAST.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
header('Content-type: application/xml');
33

44
require_once '../../videos/configuration.php';
5-
allowOrigin();
6-
header('Access-Control-Allow-Credentials: true');
5+
allowOrigin(true);
76
require_once $global['systemRootPath'] . 'objects/video.php';
87
$ad_server = AVideoPlugin::loadPlugin('AD_Server');
98
$obj = AVideoPlugin::getObjectData('AD_Server');
@@ -62,7 +61,7 @@
6261
<Creative id="Linear_<?php echo $_GET['campaign_has_videos_id']; ?>" sequence="1">
6362
<Linear skipoffset="<?php echo $obj->skipoffset->value; ?>">
6463
<Duration><?php echo $video->getDuration(); ?></Duration>
65-
64+
6665
<TrackingEvents>
6766
<Tracking event="start">
6867
<![CDATA[<?php echo $global['webSiteRootURL']; ?>plugin/AD_Server/log.php?videos_id=<?php echo $videos_id; ?>&label=<?php echo AD_Server::AD_STARTED; ?>&ad_mt=[AD_MT]&campaign_has_videos_id=<?php echo $_GET['campaign_has_videos_id']; ?>]]>
@@ -253,4 +252,4 @@
253252
</Extensions>
254253
</InLine>
255254
</Ad>
256-
</VAST>
255+
</VAST>

plugin/AD_Server/VMAP.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
header('Content-type: application/xml');
33

44
require_once '../../videos/configuration.php';
5-
allowOrigin();
6-
header('Access-Control-Allow-Credentials: true');
5+
allowOrigin(true);
76
$ad_server = AVideoPlugin::loadPluginIfEnabled('AD_Server');
87
if (empty($ad_server)) {
98
die("not enabled");
@@ -52,7 +51,7 @@
5251
$AdTagURI = addQueryStringParameter($AdTagURI, 'vmap_id', $_GET['vmap_id'] ?? '');
5352
$AdTagURI = addQueryStringParameter($AdTagURI, 'key', $key);
5453
$AdTagURI = addQueryStringParameter($AdTagURI, 'videos_id', $videos_id);
55-
54+
5655
$AdTagURI = AVideoPlugin::replacePlaceHolders($AdTagURI, $videos_id);
5756
?>
5857
<vmap:AdBreak timeOffset="<?php echo $value['timeOffset']; ?>">
@@ -64,4 +63,4 @@
6463
}
6564
?>
6665
</vmap:VMAP>
67-
<!-- AD_Server -->
66+
<!-- AD_Server -->

0 commit comments

Comments
 (0)