diff --git a/resources/tokenisation/minter/token_gen.lua b/resources/tokenisation/minter/token_gen.lua
--- a/resources/tokenisation/minter/token_gen.lua
+++ b/resources/tokenisation/minter/token_gen.lua
#
@@ -67,6 +67,17 @@ function strSplit(delim,str)
#
+local hex_to_char = function(x)
#
+ -- From https://stackoverflow.com/questions/20282054/how-to-urldecode-a-request-uri-string-in-lua
#
+ return string.char(tonumber(x, 16))
#
+local unescape = function(url)
#
+ -- From https://stackoverflow.com/questions/20282054/how-to-urldecode-a-request-uri-string-in-lua
#
+ return url:gsub("%%(%x%x)", hex_to_char)
#
local function sendSuccessful(tok,expires,debug)
#
@@ -151,7 +162,7 @@ end
#
-- get some details from the request
#
-local referer = ngx.var.arg_ref
#
+local referer = unescape(ngx.var.arg_ref)
#
-- local referer = 'https://snippets.bentasker.co.uk/foobar' -- for offline testing only
#
local vidpath = ngx.var.arg_vidpath
#
@@ -163,8 +174,8 @@ local ip = ngx.var.remote_addr
#
-- Grab the HTTP referrer header if present
#
--- local httpref = ngx.var.http_referer
#
-local httpref = 'https://snippets.bentasker.co.uk/foobar'
#
+local httpref = ngx.var.http_referer
#
+-- local httpref = 'https://snippets.bentasker.co.uk/foobar' -- for offline testing only