Project rename

This commit is contained in:
2019-03-24 08:28:57 +01:00
parent 1728e0e6e1
commit 7926230faf
7262 changed files with 0 additions and 0 deletions
@@ -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`.')
}
}
@@ -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)
}
@@ -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.')
}
})
}
@@ -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.')
}
}
@@ -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.')
}
})
}
@@ -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.')
}
})
}
@@ -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
View File
@@ -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]'
}