Project rename
This commit is contained in:
Generated
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
var isBoolean = require('../../is-boolean')
|
||||
|
||||
module.exports = function (key, value) {
|
||||
if (!isBoolean(value)) {
|
||||
throw new Error('"' + value + '" is not a valid value for ' + key + '. Use `true` or `false`.')
|
||||
}
|
||||
}
|
||||
Generated
Vendored
+20
@@ -0,0 +1,20 @@
|
||||
var config = require('../../config')
|
||||
var checkers = {
|
||||
sourceList: require('./source-list'),
|
||||
pluginTypes: require('./plugin-types'),
|
||||
sandbox: require('./sandbox'),
|
||||
reportUri: require('./report-uri'),
|
||||
requireSriFor: require('./require-sri-for'),
|
||||
boolean: require('./boolean')
|
||||
}
|
||||
|
||||
module.exports = function (key, value, options) {
|
||||
if (options.loose) { return }
|
||||
|
||||
if (!config.directives.hasOwnProperty(key)) {
|
||||
throw new Error('"' + key + '" is an invalid directive. See the documentation for the supported list. Force this by enabling loose mode.')
|
||||
}
|
||||
|
||||
var directiveType = config.directives[key].type
|
||||
checkers[directiveType](key, value, options)
|
||||
}
|
||||
Generated
Vendored
+36
@@ -0,0 +1,36 @@
|
||||
var config = require('../../config')
|
||||
var isFunction = require('../../is-function')
|
||||
|
||||
var notAllowed = ['self', "'self'"].concat(config.unsafes)
|
||||
|
||||
module.exports = function pluginTypesCheck (key, value, options) {
|
||||
if (!Array.isArray(value) && (value !== false)) {
|
||||
throw new Error('"' + value + '" is not a valid value for ' + key + '. Use an array of strings.')
|
||||
}
|
||||
|
||||
if (value.length === 0) {
|
||||
throw new Error(key + ' must have at least one value. To block everything, set ' + key + ' to ["\'none\'"].')
|
||||
}
|
||||
|
||||
value.forEach(function (pluginType) {
|
||||
if (!pluginType) {
|
||||
throw new Error('"' + pluginType + '" is not a valid plugin type. Only non-empty strings are allowed.')
|
||||
}
|
||||
|
||||
if (isFunction(pluginType)) { return }
|
||||
|
||||
pluginType = pluginType.valueOf()
|
||||
|
||||
if ((typeof pluginType !== 'string') || (pluginType.length === 0)) {
|
||||
throw new Error('"' + pluginType + '" is not a valid plugin type. Only non-empty strings are allowed.')
|
||||
}
|
||||
|
||||
if (notAllowed.indexOf(pluginType) !== -1) {
|
||||
throw new Error('"' + pluginType + '" does not make sense in ' + key + '. Remove it.')
|
||||
}
|
||||
|
||||
if (config.mustQuote.indexOf(pluginType) !== -1) {
|
||||
throw new Error('"' + pluginType + '" must be quoted in ' + key + '. Change it to "\'' + pluginType + '\'" in your source list. Force this by enabling loose mode.')
|
||||
}
|
||||
})
|
||||
}
|
||||
Generated
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
var isFunction = require('../../is-function')
|
||||
var isString = require('../../is-string')
|
||||
|
||||
module.exports = function (key, value) {
|
||||
if (value === false) { return }
|
||||
if (isFunction(value)) { return }
|
||||
|
||||
if (!isString(value) || (value.length === 0)) {
|
||||
throw new Error('"' + value + '" is not a valid value for ' + key + '. Use a non-empty string.')
|
||||
}
|
||||
}
|
||||
Generated
Vendored
+20
@@ -0,0 +1,20 @@
|
||||
var isFunction = require('../../is-function')
|
||||
var config = require('../../config')
|
||||
|
||||
module.exports = function requireSriForCheck (key, value) {
|
||||
if (!Array.isArray(value)) {
|
||||
throw new Error('"' + value + '" is not a valid value for ' + key + '. Use an array of strings.')
|
||||
}
|
||||
|
||||
if (value.length === 0) {
|
||||
throw new Error(key + ' must have at least one value. To require nothing, omit the directive.')
|
||||
}
|
||||
|
||||
value.forEach(function (expression) {
|
||||
if (isFunction(expression)) { return }
|
||||
|
||||
if (config.requireSriForValues.indexOf(expression) === -1) {
|
||||
throw new Error('"' + expression + '" is not a valid ' + key + ' value. Remove it.')
|
||||
}
|
||||
})
|
||||
}
|
||||
Generated
Vendored
+23
@@ -0,0 +1,23 @@
|
||||
var isFunction = require('../../is-function')
|
||||
var config = require('../../config')
|
||||
|
||||
module.exports = function sandboxCheck (key, value) {
|
||||
if (value === false) { return }
|
||||
if (value === true) { return }
|
||||
|
||||
if (!Array.isArray(value)) {
|
||||
throw new Error('"' + value + '" is not a valid value for ' + key + '. Use an array of strings or `true`.')
|
||||
}
|
||||
|
||||
if (value.length === 0) {
|
||||
throw new Error(key + ' must have at least one value. To block everything, set ' + key + ' to `true`.')
|
||||
}
|
||||
|
||||
value.forEach(function (expression) {
|
||||
if (isFunction(expression)) { return }
|
||||
|
||||
if (config.sandboxDirectives.indexOf(expression) === -1) {
|
||||
throw new Error('"' + expression + '" is not a valid ' + key + ' directive. Remove it.')
|
||||
}
|
||||
})
|
||||
}
|
||||
Generated
Vendored
+39
@@ -0,0 +1,39 @@
|
||||
var isFunction = require('../../is-function')
|
||||
var config = require('../../config')
|
||||
|
||||
module.exports = function sourceListCheck (key, value, options) {
|
||||
var directiveInfo = config.directives[key]
|
||||
|
||||
if (value === false) { return }
|
||||
|
||||
if (!Array.isArray(value)) {
|
||||
throw new Error('"' + value + '" is not a valid value for ' + key + '. Use an array of strings.')
|
||||
}
|
||||
|
||||
if (value.length === 0) {
|
||||
throw new Error(key + ' must have at least one value. To block everything, set ' + key + ' to ["\'none\'"].')
|
||||
}
|
||||
|
||||
value.forEach(function (sourceExpression) {
|
||||
if (!sourceExpression) {
|
||||
throw new Error('"' + sourceExpression + '" is not a valid source expression. Only non-empty strings are allowed.')
|
||||
}
|
||||
|
||||
if (isFunction(sourceExpression)) { return }
|
||||
|
||||
sourceExpression = sourceExpression.valueOf()
|
||||
|
||||
if ((typeof sourceExpression !== 'string') || (sourceExpression.length === 0)) {
|
||||
throw new Error('"' + sourceExpression + '" is not a valid source expression. Only non-empty strings are allowed.')
|
||||
}
|
||||
|
||||
if ((!directiveInfo.hasUnsafes && (config.unsafes.indexOf(sourceExpression) !== -1)) ||
|
||||
(!directiveInfo.hasStrictDynamic && (config.strictDynamics.indexOf(sourceExpression) !== -1))) {
|
||||
throw new Error('"' + sourceExpression + '" does not make sense in ' + key + '. Remove it.')
|
||||
}
|
||||
|
||||
if (config.mustQuote.indexOf(sourceExpression) !== -1) {
|
||||
throw new Error('"' + sourceExpression + '" must be quoted in ' + key + '. Change it to "\'' + sourceExpression + '\'" in your source list. Force this by enabling loose mode.')
|
||||
}
|
||||
})
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
var checkDirective = require('./check-directive')
|
||||
var dasherize = require('dasherize')
|
||||
|
||||
module.exports = function (options) {
|
||||
if (!isObject(options)) {
|
||||
throw new Error('csp must be called with an object argument. See the documentation.')
|
||||
}
|
||||
|
||||
var directives = options.directives
|
||||
|
||||
var directivesExist = isObject(directives)
|
||||
if (!directivesExist || Object.keys(directives).length === 0) {
|
||||
throw new Error('csp must have at least one directive under the "directives" key. See the documentation.')
|
||||
}
|
||||
|
||||
Object.keys(directives).forEach(function (directiveKey) {
|
||||
checkDirective(dasherize(directiveKey), directives[directiveKey], options)
|
||||
})
|
||||
}
|
||||
|
||||
function isObject (value) {
|
||||
return Object.prototype.toString.call(value) === '[object Object]'
|
||||
}
|
||||
Reference in New Issue
Block a user