mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-13 02:49:58 +00:00
Remove lax CSP/eval from production builds
This commit is contained in:
13
ext/build.js
13
ext/build.js
@@ -8,6 +8,8 @@ const package = require("./package.json");
|
|||||||
const appPackage = require("../app/package.json");
|
const appPackage = require("../app/package.json");
|
||||||
|
|
||||||
|
|
||||||
|
const INCLUDE_PATH = path.resolve(__dirname, "src");
|
||||||
|
|
||||||
const DIST_PATH = path.join(__dirname, "../dist/ext");
|
const DIST_PATH = path.join(__dirname, "../dist/ext");
|
||||||
const UNPACKED_PATH = path.join(DIST_PATH, "unpacked");
|
const UNPACKED_PATH = path.join(DIST_PATH, "unpacked");
|
||||||
|
|
||||||
@@ -36,11 +38,12 @@ if (argv.package) {
|
|||||||
|
|
||||||
// Import webpack config and specify env values
|
// Import webpack config and specify env values
|
||||||
const webpackConfig = require("./webpack.config.js")({
|
const webpackConfig = require("./webpack.config.js")({
|
||||||
|
includePath: INCLUDE_PATH
|
||||||
/**
|
/**
|
||||||
* If watching files, output directly to dist. Unpacked
|
* If watching files, output directly to dist. Unpacked
|
||||||
* directory is used as a staging area for web-ext builds.
|
* directory is used as a staging area for web-ext builds.
|
||||||
*/
|
*/
|
||||||
outputPath: argv.package
|
, outputPath: argv.package
|
||||||
? UNPACKED_PATH
|
? UNPACKED_PATH
|
||||||
: DIST_PATH
|
: DIST_PATH
|
||||||
|
|
||||||
@@ -50,10 +53,18 @@ const webpackConfig = require("./webpack.config.js")({
|
|||||||
, applicationName: appPackage.__applicationName
|
, applicationName: appPackage.__applicationName
|
||||||
, applicationVersion: appPackage.__applicationVersion
|
, applicationVersion: appPackage.__applicationVersion
|
||||||
, mirroringAppId: argv.mirroringAppId
|
, mirroringAppId: argv.mirroringAppId
|
||||||
|
|
||||||
|
// eval source map needs special CSP
|
||||||
|
, contentSecurityPolicy: argv.mode === "production"
|
||||||
|
? "default-src 'self'"
|
||||||
|
: "script-src 'self' 'unsafe-eval'; object-src 'self'"
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add mode to config
|
// Add mode to config
|
||||||
webpackConfig.mode = argv.mode;
|
webpackConfig.mode = argv.mode;
|
||||||
|
webpackConfig.devtool = argv.mode === "production"
|
||||||
|
? "source-map"
|
||||||
|
: "eval";
|
||||||
|
|
||||||
|
|
||||||
// Clean
|
// Clean
|
||||||
|
|||||||
@@ -3,13 +3,12 @@
|
|||||||
, "description": "__MSG_extensionDescription__"
|
, "description": "__MSG_extensionDescription__"
|
||||||
, "version": "EXTENSION_VERSION"
|
, "version": "EXTENSION_VERSION"
|
||||||
|
|
||||||
, "applications": {
|
, "browser_specific_settings": {
|
||||||
"gecko": {
|
"gecko": {
|
||||||
"id": "EXTENSION_ID"
|
"id": "EXTENSION_ID"
|
||||||
, "strict_min_version": "64.0"
|
, "strict_min_version": "64.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
, "browser_action": {
|
, "browser_action": {
|
||||||
"default_popup": "popup/index.html"
|
"default_popup": "popup/index.html"
|
||||||
}
|
}
|
||||||
@@ -24,15 +23,13 @@
|
|||||||
, "run_at": "document_start"
|
, "run_at": "document_start"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
, "content_security_policy": "CONTENT_SECURITY_POLICY"
|
||||||
, "content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'"
|
|
||||||
, "default_locale": "en"
|
, "default_locale": "en"
|
||||||
, "manifest_version": 2
|
, "manifest_version": 2
|
||||||
|
|
||||||
, "options_ui": {
|
, "options_ui": {
|
||||||
"page": "options/index.html"
|
"page": "options/index.html"
|
||||||
}
|
}
|
||||||
|
|
||||||
, "permissions": [
|
, "permissions": [
|
||||||
"menus"
|
"menus"
|
||||||
, "nativeMessaging"
|
, "nativeMessaging"
|
||||||
@@ -42,7 +39,6 @@
|
|||||||
, "webRequestBlocking"
|
, "webRequestBlocking"
|
||||||
, "<all_urls>"
|
, "<all_urls>"
|
||||||
]
|
]
|
||||||
|
|
||||||
, "web_accessible_resources": [
|
, "web_accessible_resources": [
|
||||||
"shim/bundle.js"
|
"shim/bundle.js"
|
||||||
, "vendor/webcomponents-lite.min.js"
|
, "vendor/webcomponents-lite.min.js"
|
||||||
|
|||||||
@@ -278,6 +278,7 @@ onMessage(message => {
|
|||||||
state.sessionRequestInProgress = false;
|
state.sessionRequestInProgress = false;
|
||||||
sessionErrorCallback(new Error_(ErrorCode.CANCEL));
|
sessionErrorCallback(new Error_(ErrorCode.CANCEL));
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,21 +4,18 @@ const path = require("path");
|
|||||||
const webpack = require("webpack");
|
const webpack = require("webpack");
|
||||||
const CopyWebpackPlugin = require("copy-webpack-plugin");
|
const CopyWebpackPlugin = require("copy-webpack-plugin");
|
||||||
|
|
||||||
|
|
||||||
const includePath = path.resolve(__dirname, "src");
|
|
||||||
|
|
||||||
module.exports = (env) => ({
|
module.exports = (env) => ({
|
||||||
entry: {
|
entry: {
|
||||||
"main" : `${includePath}/main.js`
|
"main" : `${env.includePath}/main.js`
|
||||||
, "popup/bundle" : `${includePath}/popup/index.jsx`
|
, "popup/bundle" : `${env.includePath}/popup/index.jsx`
|
||||||
, "options/bundle" : `${includePath}/options/index.jsx`
|
, "options/bundle" : `${env.includePath}/options/index.jsx`
|
||||||
, "shim/bundle" : `${includePath}/shim/index.js`
|
, "shim/bundle" : `${env.includePath}/shim/index.js`
|
||||||
, "content" : `${includePath}/content.js`
|
, "content" : `${env.includePath}/content.js`
|
||||||
, "contentSetup" : `${includePath}/contentSetup.js`
|
, "contentSetup" : `${env.includePath}/contentSetup.js`
|
||||||
, "mediaCast" : `${includePath}/mediaCast.js`
|
, "mediaCast" : `${env.includePath}/mediaCast.js`
|
||||||
, "mirroringCast" : `${includePath}/mirroringCast.js`
|
, "mirroringCast" : `${env.includePath}/mirroringCast.js`
|
||||||
, "messageRouter" : `${includePath}/messageRouter.js`
|
, "messageRouter" : `${env.includePath}/messageRouter.js`
|
||||||
, "compat/youtube" : `${includePath}/compat/youtube.js`
|
, "compat/youtube" : `${env.includePath}/compat/youtube.js`
|
||||||
}
|
}
|
||||||
, output: {
|
, output: {
|
||||||
filename: "[name].js"
|
filename: "[name].js"
|
||||||
@@ -37,7 +34,7 @@ module.exports = (env) => ({
|
|||||||
// Copy static assets
|
// Copy static assets
|
||||||
, new CopyWebpackPlugin([
|
, new CopyWebpackPlugin([
|
||||||
{
|
{
|
||||||
from: includePath
|
from: env.includePath
|
||||||
, to: env.outputPath
|
, to: env.outputPath
|
||||||
, ignore: [ "*.js", "*.jsx" ]
|
, ignore: [ "*.js", "*.jsx" ]
|
||||||
, transform (content, path) {
|
, transform (content, path) {
|
||||||
@@ -49,7 +46,8 @@ module.exports = (env) => ({
|
|||||||
.replace("EXTENSION_VERSION", env.extensionVersion)
|
.replace("EXTENSION_VERSION", env.extensionVersion)
|
||||||
.replace("MIRRORING_APP_ID", env.mirroringAppId)
|
.replace("MIRRORING_APP_ID", env.mirroringAppId)
|
||||||
.replace("APPLICATION_NAME", env.applicationName)
|
.replace("APPLICATION_NAME", env.applicationName)
|
||||||
.replace("APPLICATION_VERSION", env.applicationVersion));
|
.replace("APPLICATION_VERSION", env.applicationVersion)
|
||||||
|
.replace("CONTENT_SECURITY_POLICY", env.contentSecurityPolicy));
|
||||||
}
|
}
|
||||||
|
|
||||||
return content;
|
return content;
|
||||||
@@ -57,12 +55,11 @@ module.exports = (env) => ({
|
|||||||
}
|
}
|
||||||
, {
|
, {
|
||||||
// Copy vendor dir
|
// Copy vendor dir
|
||||||
from: path.join(includePath, "vendor")
|
from: path.join(env.includePath, "vendor")
|
||||||
, to: path.join(env.outputPath, "vendor")
|
, to: path.join(env.outputPath, "vendor")
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
]
|
]
|
||||||
, mode: "development"
|
|
||||||
, module: {
|
, module: {
|
||||||
rules: [
|
rules: [
|
||||||
{
|
{
|
||||||
@@ -70,7 +67,7 @@ module.exports = (env) => ({
|
|||||||
, resolve: {
|
, resolve: {
|
||||||
extensions: [ ".js", ".jsx" ]
|
extensions: [ ".js", ".jsx" ]
|
||||||
}
|
}
|
||||||
, include: `${includePath}`
|
, include: `${env.includePath}`
|
||||||
, use: {
|
, use: {
|
||||||
loader: "babel-loader"
|
loader: "babel-loader"
|
||||||
, options: {
|
, options: {
|
||||||
|
|||||||
Reference in New Issue
Block a user