Skip to content

Commit

Permalink
fix race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
nddipiazza committed Jun 23, 2018
1 parent 2201641 commit 64e1ef8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 22 deletions.
1 change: 1 addition & 0 deletions common.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ var processCookieStr = function(cookiesStr) {
};

var processSetCookieStr = function(str) {
console.log("Processing set cookie string " + str);
return getPrefix()+str;
};
48 changes: 41 additions & 7 deletions content.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,44 @@
var headElement = (document.head||document.documentElement);
var actualCode = `var cookieGetter = document.__lookupGetter__("cookie").bind(document);
var cookieSetter = document.__lookupSetter__("cookie").bind(document);
var injectJs = function(fileName) {
var s = document.createElement('script');
s.src = chrome.extension.getURL(fileName);
headElement.insertBefore(s, headElement.firstElementChild);
var getPrefix = function() {
return "oogi$"
};
injectJs("common.js");
injectJs("inject.js");
var processCookieStr = function(cookiesStr) {
var prefix = getPrefix();
var cookieStrList = cookiesStr.split('; ');
var newStrList = [];
cookieStrList.forEach(function(cookieStr){
if (cookieStr.indexOf(prefix)==0) {
newStrList.push(cookieStr.substring(prefix.length, cookieStr.length));
}
});
return newStrList.join("; ");
};
var processSetCookieStr = function(str) {
console.log("Processing set cookie string " + str);
return getPrefix()+str;
};
Object.defineProperty(document, 'cookie', {
get: function() {
var storedCookieStr = cookieGetter();
console.log("Intercepted a cookie get " + storedCookieStr + " , and returning processed cookie string " + processCookieStr(storedCookieStr));
return processCookieStr(storedCookieStr);
},
set: function(cookieString) {
var newValue = processSetCookieStr(cookieString);
console.log("Intercepted a cookie set " + newValue)
return cookieSetter(newValue);
}
});
console.log("cookie get/set injector completed");
`;

var script = document.createElement('script');
script.textContent = actualCode;
(document.head||document.documentElement).appendChild(script);
script.remove();
15 changes: 0 additions & 15 deletions inject.js

This file was deleted.

0 comments on commit 64e1ef8

Please sign in to comment.