From ca7aacd601177b417acc3d30768e05460d019d51 Mon Sep 17 00:00:00 2001 From: Matt Kendall Date: Mon, 10 Dec 2018 16:35:19 -0500 Subject: [PATCH 1/3] validate URLs using regex --- src/cookieSync.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/cookieSync.js b/src/cookieSync.js index ff2b1d38..a87d0cd4 100644 --- a/src/cookieSync.js +++ b/src/cookieSync.js @@ -1,8 +1,12 @@ const ENDPOINT = 'https://prebid.adnxs.com/pbs/v1/cookie_sync'; +/** + * checks to make sure URL is valid. Regex from https://validatejs.org/#validators-url, https://gist.github.com/dperini/729294 + */ +const isValidUrl = new RegExp(/^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\u00a1-\uffff][a-z0-9\u00a1-\uffff_-]{0,62})?[a-z0-9\u00a1-\uffff]\.)+(?:[a-z\u00a1-\uffff]{2,}\.?))(?::\d{2,5})?(?:[/?#]\S*)?$/i); function doBidderSync(type, url, bidder) { - if (!url) { - console.log(`No sync url for bidder "${bidder}": ${url}`); + if (!url || !isValidUrl.test(url)) { + console.log(`No valid sync url for bidder "${bidder}": ${url}`); } else if (type === 'image' || type === 'redirect') { console.log(`Invoking image pixel user sync for bidder: "${bidder}"`); triggerPixel(url); From fbc87919f03a4626aea6c459012269cf1b70eab9 Mon Sep 17 00:00:00 2001 From: Matt Kendall Date: Mon, 10 Dec 2018 16:45:40 -0500 Subject: [PATCH 2/3] update dist file --- dist/load-cookie.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/load-cookie.html b/dist/load-cookie.html index 70b228d3..a017d598 100644 --- a/dist/load-cookie.html +++ b/dist/load-cookie.html @@ -7,7 +7,7 @@ Document From 55191fbd3e44fa15b1a0637bd8c3032d794cbb8d Mon Sep 17 00:00:00 2001 From: Matt Kendall Date: Mon, 10 Dec 2018 16:47:44 -0500 Subject: [PATCH 3/3] add test page --- testpages/hello_world_cookie_sync.html | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 testpages/hello_world_cookie_sync.html diff --git a/testpages/hello_world_cookie_sync.html b/testpages/hello_world_cookie_sync.html new file mode 100644 index 00000000..6fcfa333 --- /dev/null +++ b/testpages/hello_world_cookie_sync.html @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file