I am trying to secure a byte serving script, written in PHP, mostly taken from http://www.tuxxin.com/php-mp4-streaming/ to protect against linking the video directly and easy downloading. I therefore have placed the video outside the public http-root. The pseudo-streaming itself works perfectly fine.
The pages structure like this:
mysite.com/watchvideo.php:
<video>
<source src="/media.php?t=<?= $t = Token::generate(); ?>" type="video/mp4">
</video>
mysite.com/media.php:
$token = isset($_GET["t"]) ? $_GET["t"] : "";
if (
!Token::check($token)
|| $_SERVER["HTTP_REFERER"] !== "mysite.com/watchthisawesomevideo.php"
) {
header("HTTP/1.1 403 Forbidden");
exit;
}
do_the_byte_range_stuff(); // from tuxxin.com
The Token
class simply generates a random string, saves it in the php-session and returns it, respectively when checking compares the parameter to the token stored in $_SESSION
.
With this method I have the problem that some browsers, like stock and chrome 47 on Android 4.1.2 seem to hand over the streaming to some different process, therefore losing the HTTP_REFERER
(possibly related: android issue 1780). If I unset the token on checking it subsequent requests to media.php
get abortet. Same goes if I set a time limit for the token.
Once this is sorted I would hide the video and mirror its content onto a canvas.
What would be suitable security measures to protect against downloading the video file and making media.php
inaccessible? I know there can't be absolute protection, but I want to make it reasonably difficult.
Edit: Please note that I am not looking for some form of DRM for the video as I know it could be simply recorded off the screen. I am looking for ways to get the video to the watchvideo-page making it only accessible from there and preventing hotlinking.