Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/validate urls #47

Merged
merged 3 commits into from
Dec 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/load-cookie.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<title>Document</title>
<script type="text/javascript">
// cookie-sync start
!function(o){var n={};function r(e){if(n[e])return n[e].exports;var t=n[e]={i:e,l:!1,exports:{}};return o[e].call(t.exports,t,t.exports,r),t.l=!0,t.exports}r.m=o,r.c=n,r.d=function(e,t,o){r.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:o})},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,o){"use strict";var u=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var o=arguments[t];for(var n in o)Object.prototype.hasOwnProperty.call(o,n)&&(e[n]=o[n])}return e},a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};function n(e,t,o){var n;t?"image"===e||"redirect"===e?(console.log('Invoking image pixel user sync for bidder: "'+o+'"'),n=t,(new Image).src=n):"iframe"==e||console.log('User sync type "'+e+'" not supported for bidder: "'+o+'"'):console.log('No sync url for bidder "'+o+'": '+t)}!function(e,t,o){var n=3<arguments.length&&void 0!==arguments[3]?arguments[3]:{};try{var r=void 0,s=n.method||(o?"POST":"GET"),c="object"===(void 0===t?"undefined":a(t))?t:{success:function(){console.log("xhr success")},error:function(e){console.log("xhr error",null,e)}};if("function"==typeof t&&(c.success=t),(r=new window.XMLHttpRequest).onreadystatechange=function(){if(4===r.readyState){var e=r.status;200<=e&&e<300||304===e?c.success(r.responseText,r):c.error(r.statusText,r)}},r.ontimeout=function(){console.log("xhr timeout after ",r.timeout,"ms")},"GET"===s&&o){var i=parseURL(e,n);u(i.search,o),e=formatURL(i)}r.open(s,e),r.timeout=3e3,n.withCredentials&&(r.withCredentials=!0),n.preflight&&r.setRequestHeader("X-Requested-With","XMLHttpRequest"),r.setRequestHeader("Content-Type",n.contentType||"text/plain"),"POST"===s&&o?r.send(o):r.send()}catch(e){console.log("xhr construction",e)}}("https://prebid.adnxs.com/pbs/v1/cookie_sync",function(e){var t=JSON.parse(e);"OK"!==t.status&&"no_cookie"!==t.status||t.bidder_status&&t.bidder_status.forEach(function(e){e.no_cookie&&n(e.usersync.type,e.usersync.url,e.bidder)})},"{}")}]);
!function(o){var n={};function r(e){if(n[e])return n[e].exports;var t=n[e]={i:e,l:!1,exports:{}};return o[e].call(t.exports,t,t.exports,r),t.l=!0,t.exports}r.m=o,r.c=n,r.d=function(e,t,o){r.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:o})},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,o){"use strict";var i=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var o=arguments[t];for(var n in o)Object.prototype.hasOwnProperty.call(o,n)&&(e[n]=o[n])}return e},f="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r=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 n(e,t,o){var n;t&&r.test(t)?"image"===e||"redirect"===e?(console.log('Invoking image pixel user sync for bidder: "'+o+'"'),n=t,(new Image).src=n):"iframe"==e||console.log('User sync type "'+e+'" not supported for bidder: "'+o+'"'):console.log('No valid sync url for bidder "'+o+'": '+t)}!function(e,t,o){var n=3<arguments.length&&void 0!==arguments[3]?arguments[3]:{};try{var r=void 0,s=n.method||(o?"POST":"GET"),u="object"===(void 0===t?"undefined":f(t))?t:{success:function(){console.log("xhr success")},error:function(e){console.log("xhr error",null,e)}};if("function"==typeof t&&(u.success=t),(r=new window.XMLHttpRequest).onreadystatechange=function(){if(4===r.readyState){var e=r.status;200<=e&&e<300||304===e?u.success(r.responseText,r):u.error(r.statusText,r)}},r.ontimeout=function(){console.log("xhr timeout after ",r.timeout,"ms")},"GET"===s&&o){var c=parseURL(e,n);i(c.search,o),e=formatURL(c)}r.open(s,e),r.timeout=3e3,n.withCredentials&&(r.withCredentials=!0),n.preflight&&r.setRequestHeader("X-Requested-With","XMLHttpRequest"),r.setRequestHeader("Content-Type",n.contentType||"text/plain"),"POST"===s&&o?r.send(o):r.send()}catch(e){console.log("xhr construction",e)}}("https://prebid.adnxs.com/pbs/v1/cookie_sync",function(e){var t=JSON.parse(e);"OK"!==t.status&&"no_cookie"!==t.status||t.bidder_status&&t.bidder_status.forEach(function(e){e.no_cookie&&n(e.usersync.type,e.usersync.url,e.bidder)})},"{}")}]);
// end
</script>
</head>
Expand Down
8 changes: 6 additions & 2 deletions src/cookieSync.js
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
7 changes: 7 additions & 0 deletions testpages/hello_world_cookie_sync.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!DOCTYPE html>
<html>
<head></head>
<body>
<iframe src = '/dist/load-cookie.html'></iframe>
</body>
</html>