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

feat: Unblock manifest v3 usage by fixing incompatible CSP automation #148

Merged
merged 1 commit into from
Oct 31, 2023
Merged
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
21 changes: 18 additions & 3 deletions lib/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ function syncManifestWithPackageJson ({ manifestSync }, packageJson, manifest) {
})
}

const defaultCsp = "script-src 'self' 'unsafe-eval'; object-src 'self'"

module.exports = (api, pluginOptions, packageJson) => async (content) => {
const manifest = JSON.parse(content)
const keyFile = api.resolve('key.pem')
Expand All @@ -26,15 +28,28 @@ module.exports = (api, pluginOptions, packageJson) => async (content) => {

syncManifestWithPackageJson(pluginOptions, packageJson, manifest)

manifest.content_security_policy =
manifest.content_security_policy || "script-src 'self' 'unsafe-eval'; object-src 'self'"
if (manifest.manifest_version === 3) {
manifest.content_security_policy = Object.assign(
{
extension_pages: defaultCsp
},
manifest.content_security_policy
)
} else {
manifest.content_security_policy =
manifest.content_security_policy || defaultCsp
}

// validate manifest

// If building for production (going to web store) abort early.
// The browser extension store will hash your signing key and apply CSP policies.
if (isProduction) {
manifest.content_security_policy = manifest.content_security_policy.replace(/'unsafe-eval'/, '')
if (manifest.manifest_version === 3) {
manifest.content_security_policy.extension_pages = manifest.content_security_policy.extension_pages.replace(/'unsafe-eval'/, '')
} else {
manifest.content_security_policy = manifest.content_security_policy.replace(/'unsafe-eval'/, '')
}

// validate minimum options

Expand Down