refactor repo to keep non-addon needed code out of the bundled extensions (tests, src data, etc.)
This commit is contained in:
parent
a37f31836d
commit
fbdba9fca7
39 changed files with 6173 additions and 36 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -2,5 +2,4 @@ node_modules/
|
||||||
.DS_Store
|
.DS_Store
|
||||||
*.swp
|
*.swp
|
||||||
|
|
||||||
content_scripts/dist/*.js
|
dist
|
||||||
web-ext-artifacts/
|
|
||||||
|
|
|
@ -133,7 +133,7 @@
|
||||||
// run in the page.
|
// run in the page.
|
||||||
const cspDynamicPolicyHeaders = details.responseHeaders
|
const cspDynamicPolicyHeaders = details.responseHeaders
|
||||||
.filter(httpHeadersLib.isHeaderCSP)
|
.filter(httpHeadersLib.isHeaderCSP)
|
||||||
.filter(httpHeadersLib.isCSPHeaderSettingStrictDynamic);
|
.filter(httpHeadersLib.isCSPHeaderSettingScriptSrc);
|
||||||
|
|
||||||
if (cspDynamicPolicyHeaders.length === 1) {
|
if (cspDynamicPolicyHeaders.length === 1) {
|
||||||
const [ignore, scriptHash] = proxyBlockLib.generateScriptPayload(
|
const [ignore, scriptHash] = proxyBlockLib.generateScriptPayload(
|
||||||
|
@ -141,12 +141,12 @@
|
||||||
standardsToBlock,
|
standardsToBlock,
|
||||||
shouldLog
|
shouldLog
|
||||||
);
|
);
|
||||||
|
|
||||||
const newCSPValue = httpHeadersLib.createCSPInstructionWithHashAllowed(
|
const newCSPValue = httpHeadersLib.createCSPInstructionWithHashAllowed(
|
||||||
cspDynamicPolicyHeaders[0].value,
|
cspDynamicPolicyHeaders[0].value,
|
||||||
"sha256-" + scriptHash
|
"sha256-" + scriptHash
|
||||||
);
|
);
|
||||||
|
|
||||||
if (newCSPValue !== false) {
|
if (newCSPValue !== false) {
|
||||||
cspDynamicPolicyHeaders[0].value = newCSPValue;
|
cspDynamicPolicyHeaders[0].value = newCSPValue;
|
||||||
}
|
}
|
||||||
|
@ -155,20 +155,15 @@
|
||||||
// If there is already a set-cookie instruction being issued,
|
// If there is already a set-cookie instruction being issued,
|
||||||
// don't overwrite it, but add our cookie to the end of it. Otherwise,
|
// don't overwrite it, but add our cookie to the end of it. Otherwise,
|
||||||
// create a new set-cookie instruction header.
|
// create a new set-cookie instruction header.
|
||||||
const webAPIStandardsCookie = `${constants.cookieName}=${encodedOptions}`;
|
const pathForCookie = window.URI(details.url).pathname();
|
||||||
const setCookieHeaders = details.responseHeaders.filter(httpHeadersLib.isSetCookie);
|
details.responseHeaders.push({
|
||||||
|
name: "Set-Cookie",
|
||||||
|
value: `${constants.cookieName}=${encodedOptions};path=${pathForCookie}`
|
||||||
|
});
|
||||||
|
|
||||||
if (setCookieHeaders.length > 0) {
|
details.responseHeaders.forEach((header) => {
|
||||||
|
console.log(header.name + ": " + header.value);
|
||||||
setCookieHeaders[0].value += "; " + webAPIStandardsCookie;
|
});
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
details.responseHeaders.push({
|
|
||||||
name: "Set-Cookie",
|
|
||||||
value: webAPIStandardsCookie
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
responseHeaders: details.responseHeaders
|
responseHeaders: details.responseHeaders
|
Before Width: | Height: | Size: 106 KiB After Width: | Height: | Size: 106 KiB |
|
@ -14,8 +14,14 @@
|
||||||
const rootElm = doc.head || doc.documentElement;
|
const rootElm = doc.head || doc.documentElement;
|
||||||
|
|
||||||
const cookieValue = cookies2.get(standardsCookieName);
|
const cookieValue = cookies2.get(standardsCookieName);
|
||||||
|
console.log(document.cookie);
|
||||||
|
cookies2.remove(standardsCookieName, {path: window.document.location.pathname});
|
||||||
|
console.log(document.cookie);
|
||||||
|
|
||||||
|
if (!cookieValue) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const [standardsToBlock, shouldLog] = cookieEncodingLib.fromCookieValue(cookieValue);
|
const [standardsToBlock, shouldLog] = cookieEncodingLib.fromCookieValue(cookieValue);
|
||||||
cookies2.remove(standardsCookieName);
|
|
||||||
|
|
||||||
const [scriptToInject, scriptHash] = proxyBlockLib.generateScriptPayload(
|
const [scriptToInject, scriptHash] = proxyBlockLib.generateScriptPayload(
|
||||||
standards,
|
standards,
|
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 4.9 KiB After Width: | Height: | Size: 4.9 KiB |
|
@ -18,7 +18,7 @@
|
||||||
* in all other cases.
|
* in all other cases.
|
||||||
*/
|
*/
|
||||||
const isSetCookie = function (header) {
|
const isSetCookie = function (header) {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
header &&
|
header &&
|
||||||
header.name &&
|
header.name &&
|
||||||
|
@ -26,6 +26,15 @@
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const isNotHTTPOnlySetCookie = function (header) {
|
||||||
|
|
||||||
|
return (
|
||||||
|
header &&
|
||||||
|
header.value &&
|
||||||
|
header.value.toLowerCase().indexOf("httponly") === -1
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a boolean description of whether the given header
|
* Returns a boolean description of whether the given header
|
||||||
* (in the structure defined by the WebExtension WebRequest API)
|
* (in the structure defined by the WebExtension WebRequest API)
|
||||||
|
@ -63,12 +72,12 @@
|
||||||
* true if the given object is a CSP header that defines a
|
* true if the given object is a CSP header that defines a
|
||||||
* "strict-dynamic" policy, and false in all other cases.
|
* "strict-dynamic" policy, and false in all other cases.
|
||||||
*/
|
*/
|
||||||
const isCSPHeaderSettingStrictDynamic = function (header) {
|
const isCSPHeaderSettingScriptSrc = function (header) {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
header &&
|
header &&
|
||||||
header.name &&
|
header.value &&
|
||||||
header.value.indexOf("'strict-dynamic'") !== -1
|
header.value.indexOf("script-src") !== -1
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -98,7 +107,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
const preSrcScript = cspInstruction.substring(0, indexOfScriptSrc);
|
const preSrcScript = cspInstruction.substring(0, indexOfScriptSrc);
|
||||||
const postScriptSrc = cspInstruction.substring(indexOfScriptSrc + 10);
|
const postScriptSrc = cspInstruction.substring(indexOfScriptSrc + 11);
|
||||||
const newInstruction = preSrcScript + "script-src '" + scriptHash + "' " + postScriptSrc;
|
const newInstruction = preSrcScript + "script-src '" + scriptHash + "' " + postScriptSrc;
|
||||||
|
|
||||||
return newInstruction;
|
return newInstruction;
|
||||||
|
@ -106,8 +115,9 @@
|
||||||
|
|
||||||
window.WEB_API_MANAGER.httpHeadersLib = {
|
window.WEB_API_MANAGER.httpHeadersLib = {
|
||||||
isSetCookie,
|
isSetCookie,
|
||||||
|
isNotHTTPOnlySetCookie,
|
||||||
isHeaderCSP,
|
isHeaderCSP,
|
||||||
isCSPHeaderSettingStrictDynamic,
|
isCSPHeaderSettingScriptSrc,
|
||||||
createCSPInstructionWithHashAllowed
|
createCSPInstructionWithHashAllowed
|
||||||
};
|
};
|
||||||
}());
|
}());
|
|
@ -5,7 +5,7 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
window.WEB_API_MANAGER = {
|
window.WEB_API_MANAGER = {
|
||||||
constants: {
|
constants: {
|
||||||
cookieName: "wam-temp-cookie",
|
cookieName: "__wamtc",
|
||||||
shouldLogKey: "shouldLogKey"
|
shouldLogKey: "shouldLogKey"
|
||||||
}
|
}
|
||||||
};
|
};
|
|
@ -16,7 +16,7 @@
|
||||||
// just to make it easier to write and deploy (ie vim highlights
|
// just to make it easier to write and deploy (ie vim highlights
|
||||||
// it just like any other JS).
|
// it just like any other JS).
|
||||||
const proxyBlockingFunction = function () {
|
const proxyBlockingFunction = function () {
|
||||||
console.log("well it runs");
|
|
||||||
const settings = window.WEB_API_MANAGER_PAGE;
|
const settings = window.WEB_API_MANAGER_PAGE;
|
||||||
const shouldLog = settings.shouldLog;
|
const shouldLog = settings.shouldLog;
|
||||||
const standardsToBlock = settings.toBlock;
|
const standardsToBlock = settings.toBlock;
|
||||||
|
@ -177,7 +177,6 @@
|
||||||
// it when we're done, and before the page scripts can start running.
|
// it when we're done, and before the page scripts can start running.
|
||||||
delete window.WEB_API_MANAGER_PAGE;
|
delete window.WEB_API_MANAGER_PAGE;
|
||||||
|
|
||||||
console.log("well its done");
|
|
||||||
// Last, remove the script tag containing this code from the document,
|
// Last, remove the script tag containing this code from the document,
|
||||||
// so that the structure of the page looks like what the page author
|
// so that the structure of the page looks like what the page author
|
||||||
// expects / intended.
|
// expects / intended.
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
// If there are no currently saved domain rules, then create
|
// If there are no currently saved domain rules, then create
|
||||||
// a stubbed out one, using an empty blocking rule set.
|
// a stubbed out one, using an empty blocking rule set.
|
||||||
if (!loadedValues ||
|
if (!loadedValues ||
|
||||||
!loadedValues.domainRules ||
|
!loadedValues.domainRules ||
|
||||||
Object.keys(loadedValues.domainRules).length === 0) {
|
Object.keys(loadedValues.domainRules).length === 0) {
|
||||||
|
|
0
lib/vendor/URI.js → add-on/lib/vendor/URI.js
vendored
0
lib/vendor/URI.js → add-on/lib/vendor/URI.js
vendored
|
@ -34,7 +34,7 @@
|
||||||
"lib/vendor/js.cookie.js",
|
"lib/vendor/js.cookie.js",
|
||||||
"lib/vendor/sjcl.js",
|
"lib/vendor/sjcl.js",
|
||||||
"lib/init.js",
|
"lib/init.js",
|
||||||
"data/standards.js",
|
"lib/standards.js",
|
||||||
"lib/pack.js",
|
"lib/pack.js",
|
||||||
"lib/cookieencoding.js",
|
"lib/cookieencoding.js",
|
||||||
"lib/proxyblock.js",
|
"lib/proxyblock.js",
|
||||||
|
@ -49,7 +49,7 @@
|
||||||
"lib/vendor/sjcl.js",
|
"lib/vendor/sjcl.js",
|
||||||
"lib/vendor/URI.js",
|
"lib/vendor/URI.js",
|
||||||
"lib/init.js",
|
"lib/init.js",
|
||||||
"data/standards.js",
|
"lib/standards.js",
|
||||||
"lib/pack.js",
|
"lib/pack.js",
|
||||||
"lib/defaults.js",
|
"lib/defaults.js",
|
||||||
"lib/storage.js",
|
"lib/storage.js",
|
|
@ -35,5 +35,5 @@ gulp.task('default', function () {
|
||||||
|
|
||||||
const renderedStandardsModule = builtScriptComment + `window.WEB_API_MANAGER.standards = ${JSON.stringify(combinedStandards)};`;
|
const renderedStandardsModule = builtScriptComment + `window.WEB_API_MANAGER.standards = ${JSON.stringify(combinedStandards)};`;
|
||||||
|
|
||||||
fs.writeFileSync("data/standards.js", renderedStandardsModule);
|
fs.writeFileSync("add-on/lib/standards.js", renderedStandardsModule);
|
||||||
});
|
});
|
||||||
|
|
6125
package-lock.json
generated
6125
package-lock.json
generated
File diff suppressed because it is too large
Load diff
11
package.json
11
package.json
|
@ -1,11 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "web-api-manager",
|
"name": "web-api-manager",
|
||||||
"version": "0.9.1",
|
"version": "0.9.2",
|
||||||
"description": "Tools to generate Web API managing browser extensions for Firefox and Chrome.",
|
"description": "Tools to generate Web API managing browser extensions for Firefox and Chrome.",
|
||||||
"author": "Peter Snyder <psnyde2@uic.edu> (https://www.cs.uic.edu/~psnyder/)",
|
"author": "Peter Snyder <psnyde2@uic.edu> (https://www.cs.uic.edu/~psnyder/)",
|
||||||
"license": "GPL-3.0",
|
"license": "GPL-3.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"gulp": "^3.9.1"
|
"gulp": "^3.9.1",
|
||||||
|
"web-ext": "^2.2.2"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/snyderp/web-api-manager",
|
"homepage": "https://github.com/snyderp/web-api-manager",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
|
@ -21,5 +22,9 @@
|
||||||
"privacy",
|
"privacy",
|
||||||
"security"
|
"security"
|
||||||
],
|
],
|
||||||
"contributors": []
|
"contributors": [],
|
||||||
|
"scripts": {
|
||||||
|
"bundle": "web-ext -s add-on -a dist build --overwrite-dest",
|
||||||
|
"firefox": "web-ext -s add-on run"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue