new WpwCspWebPlugin(policy, additionalOpts)
Setup for our plugin
.Setup for our plugin
| Name | Type | Description |
|---|---|---|
policy | object | the policy object - see defaultPolicy above for the structure |
additionalOpts | object | additional config options - see defaultAdditionalOpts above for options available |
- Source
Methods
apply(compiler)
Hooks into webpack to collect assets and hash them, build the policy, and add it into our HTML template
.Hooks into webpack to collect assets and hash them, build the policy, and add it into our HTML template
| Name | Type | Description |
|---|---|---|
compiler | WebpackCompiler |
- Source
buildPolicy(policyObj) → {string}
| Name | Type | Description |
|---|---|---|
policyObj | any |
- Source
- Type:
- string
createNonce() → {string}
Create a random nonce which we will set onto our assets
.Create a random nonce which we will set onto our assets
- Source
- Type:
- string
getShas(cheerio, policyName, selector) → {Array.<string>}
| Name | Type | Description |
|---|---|---|
cheerio | object | cheerio instance |
policyName | string | 'script-src' | 'style-src' |
selector | string | cheerio selector string |
- Source
- Type:
- Array.<string>
hash(str) → {string}
| Name | Type | Description |
|---|---|---|
str | string | the string to hash |
- Source
- the returned hash with the hashing method prepended e.g. sha256-123456abcdef
- Type:
- string
isEnabled(pluginData) → {boolean}
Checks to see whether the plugin is enabled. this.opts.enabled can be a function or bool here
| Name | Type | Description |
|---|---|---|
pluginData | the pluginData from compilation |
- Source
- whether the plugin is enabled or not
- Type:
- boolean
mergeOptions(compilation, pluginData, compileCb)
| Name | Type | Description |
|---|---|---|
compilation | object | |
pluginData | object | data from HtmlWebpackPlugin |
compileCb | function | callback to continue webpack compilation |
- Source
processCsp(compilation, pluginData, compileCb)
| Name | Type | Description |
|---|---|---|
compilation | WebpackCompilation | |
pluginData | any | |
compileCb | any |
- Source
setNonce(cheerio, policyName, selector) → {Array.<string>}
| Name | Type | Description |
|---|---|---|
cheerio | object | cheerio instance |
policyName | string | one of 'script-src' and 'style-src' |
selector | string | a Cheerio selector string for getting the hashable elements for this policy |
- Source
- Type:
- Array.<string>
validatePolicy(compilation)
Validate the policy by making sure that all static sources have been wrapped in apostrophes
i.e.
Validate the policy by making sure that all static sources have been wrapped in apostrophes
i.e. policy should contain 'self' instead of self
| Name | Type | Description |
|---|---|---|
compilation | object | the webpack compilation object |
- Source