From db812732a0d448dc2fa29d77b2928a481cf9f2ba Mon Sep 17 00:00:00 2001 From: Evan Carothers Date: Wed, 26 Oct 2016 11:23:21 -0400 Subject: [PATCH] fix for window.location.protocol checks (moved err to iframe page) --- dev/xdomain_cookie.dev.js | 4 ---- dev/xdomain_cookie.html | 4 ++++ src/xdomain_cookie.html | 4 ++++ src/xdomain_cookie.js | 4 ---- src/xdomain_cookie.min.js | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/dev/xdomain_cookie.dev.js b/dev/xdomain_cookie.dev.js index 44abb1f..783324a 100644 --- a/dev/xdomain_cookie.dev.js +++ b/dev/xdomain_cookie.dev.js @@ -19,10 +19,6 @@ _secure_only = !!secure_only, //should cookies be written as HTTPS-only cookies _debug = !!debug; - if(_secure_only && window.window.location.protocol !== 'https:'){ - return console.error("xDomainCookie - ERROR, secure_only flag set but page is not loaded over HTTPS:"); - } - function _log(){ if(!_debug) return; arguments[0] = ":XDC_PAGE: "+arguments[0]; diff --git a/dev/xdomain_cookie.html b/dev/xdomain_cookie.html index 3e87b7c..9f03c0c 100644 --- a/dev/xdomain_cookie.html +++ b/dev/xdomain_cookie.html @@ -58,6 +58,10 @@ if(!('msg_type' in data) || data.msg_type !== 'xdsc_write') return; //data is not a xdomainc-cookie payload if(!('namespace' in data) || data.namespace !== _namespace) return; //wrong namespace for msg + if(data.secure_only && window.location.protocol !== 'https:'){ + console.error("xDomainCookie - ERROR, secure_only flag set but page is not loaded over HTTPS:"); + } + var expires_days = parseInt(data.expires_days,10); _set_local_cookie( data.cookie_name, data.cookie_val, expires_days, data.secure_only ); //ping down to page again to update values of xdomain cookie data diff --git a/src/xdomain_cookie.html b/src/xdomain_cookie.html index 3e87b7c..9f03c0c 100644 --- a/src/xdomain_cookie.html +++ b/src/xdomain_cookie.html @@ -58,6 +58,10 @@ if(!('msg_type' in data) || data.msg_type !== 'xdsc_write') return; //data is not a xdomainc-cookie payload if(!('namespace' in data) || data.namespace !== _namespace) return; //wrong namespace for msg + if(data.secure_only && window.location.protocol !== 'https:'){ + console.error("xDomainCookie - ERROR, secure_only flag set but page is not loaded over HTTPS:"); + } + var expires_days = parseInt(data.expires_days,10); _set_local_cookie( data.cookie_name, data.cookie_val, expires_days, data.secure_only ); //ping down to page again to update values of xdomain cookie data diff --git a/src/xdomain_cookie.js b/src/xdomain_cookie.js index 5ef3364..02407a9 100644 --- a/src/xdomain_cookie.js +++ b/src/xdomain_cookie.js @@ -21,10 +21,6 @@ _secure_only = !!secure_only, //should cookies be written as HTTPS-only cookies _debug = !!debug; - if(_secure_only && window.window.location.protocol !== 'https:'){ - return console.error("xDomainCookie - ERROR, secure_only flag set but page is not loaded over HTTPS:"); - } - function _log(){ if(!_debug) return; arguments[0] = ":XDC_PAGE: "+arguments[0]; diff --git a/src/xdomain_cookie.min.js b/src/xdomain_cookie.min.js index 55d2625..efae502 100644 --- a/src/xdomain_cookie.min.js +++ b/src/xdomain_cookie.min.js @@ -1,3 +1,3 @@ /* Version 1.0.6 xdomain-cookies (http://contently.github.io/xdomain-cookies/) from Contently (https://github.com/contently) */ -!function(exports){"use strict";var xDomainCookie=function(iframe_path,namespace,xdomain_only,iframe_load_timeout_ms,secure_only,debug){function _log(){_debug&&(arguments[0]=":XDC_PAGE: "+arguments[0],console.log.apply(console,arguments))}function _inbound_postmessage(event){_log("_inbound_postmessage",event.origin,event.data);var origin=event.origin||event.originalEvent.origin;if(origin===iframe_path&&"string"==typeof event.data){var data=null;try{data=JSON.parse(event.data)}catch(e){}"object"!=typeof data||data instanceof Array||"msg_type"in data&&"xdsc_read"===data.msg_type&&"namespace"in data&&data.namespace===_namespace&&(_xdomain_cookie_data=data.cookies,_iframe_ready=!0,_fire_pending_callbacks())}}function _iframe_load_error_occured(){_log("_iframe_load_error_occured"),_iframe_load_error=!0,_fire_pending_callbacks()}function _on_iframe_ready_or_error(cb){_callbacks.push(cb),_fire_pending_callbacks()}function _fire_pending_callbacks(){if(_iframe_load_error||_iframe_ready)for(;_callbacks.length>0;)_callbacks.pop()(_iframe_load_error)}function _set_cookie_in_iframe(cookie_name,cookie_value,expires_days){var data={namespace:_namespace,msg_type:"xdsc_write",cookie_name:cookie_name,cookie_val:cookie_value,expires_days:expires_days,secure_only:_secure_only};_log("_set_cookie_in_iframe",data),document.getElementById("xdomain_cookie_"+_id).contentWindow.postMessage(JSON.stringify(data),iframe_path)}function _get_local_cookie(cookie_name){for(var name=cookie_name+"=",ca=document.cookie.split(";"),i=0;i0;)_callbacks.pop()(_iframe_load_error)}function _set_cookie_in_iframe(cookie_name,cookie_value,expires_days){var data={namespace:_namespace,msg_type:"xdsc_write",cookie_name:cookie_name,cookie_val:cookie_value,expires_days:expires_days,secure_only:_secure_only};_log("_set_cookie_in_iframe",data),document.getElementById("xdomain_cookie_"+_id).contentWindow.postMessage(JSON.stringify(data),iframe_path)}function _get_local_cookie(cookie_name){for(var name=cookie_name+"=",ca=document.cookie.split(";"),i=0;i