Working Skelleton
This commit is contained in:
+21
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015-2018 Evan Hahn
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
Content Security Policy builder
|
||||
===============================
|
||||
[](https://travis-ci.org/helmetjs/content-security-policy-builder)
|
||||
[](http://standardjs.com/)
|
||||
|
||||
Take an object and turn it into a Content Security Policy string. Useful for building Content Security Policy libraries.
|
||||
|
||||
It can handle a lot of things you can you throw at it; `camelCased` or `dash-separated` directives, arrays or strings, et cetera.
|
||||
|
||||
Usage:
|
||||
|
||||
```javascript
|
||||
var builder = require("content-security-policy-builder")
|
||||
|
||||
// default-src 'self' default.com; script-src scripts.com; whatever-src something; object-src
|
||||
builder({
|
||||
directives: {
|
||||
defaultSrc: ["'self'", "default.com"],
|
||||
scriptSrc: "scripts.com",
|
||||
"whatever-src": "something",
|
||||
objectSrc: true
|
||||
}
|
||||
})
|
||||
```
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
module.exports = function (options) {
|
||||
var directives = options.directives
|
||||
|
||||
var keysSeen = {}
|
||||
|
||||
return Object.keys(directives).reduce(function (result, originalKey) {
|
||||
var directive = dashify(originalKey)
|
||||
|
||||
if (keysSeen[directive]) {
|
||||
throw new Error(originalKey + ' is specified more than once')
|
||||
}
|
||||
keysSeen[directive] = true
|
||||
|
||||
var value = directives[originalKey]
|
||||
if (Array.isArray(value)) {
|
||||
value = value.join(' ')
|
||||
} else if (value === true) {
|
||||
value = ''
|
||||
} else if (value === false) {
|
||||
return result
|
||||
}
|
||||
|
||||
if (value) {
|
||||
return result.concat(directive + ' ' + value)
|
||||
} else {
|
||||
return result.concat(directive)
|
||||
}
|
||||
}, []).join('; ')
|
||||
}
|
||||
|
||||
function dashify (str) {
|
||||
return str
|
||||
.replace(/([a-z])([A-Z])/g, '$1-$2')
|
||||
.toLowerCase()
|
||||
}
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
{
|
||||
"raw": "content-security-policy-builder@2.0.0",
|
||||
"scope": null,
|
||||
"escapedName": "content-security-policy-builder",
|
||||
"name": "content-security-policy-builder",
|
||||
"rawSpec": "2.0.0",
|
||||
"spec": "2.0.0",
|
||||
"type": "version"
|
||||
},
|
||||
"/Users/gerrit/Documents/dev/nodejs/rentfor.camp/html/RentForCamp/node_modules/helmet-csp"
|
||||
]
|
||||
],
|
||||
"_from": "content-security-policy-builder@2.0.0",
|
||||
"_id": "content-security-policy-builder@2.0.0",
|
||||
"_inCache": true,
|
||||
"_location": "/content-security-policy-builder",
|
||||
"_nodeVersion": "9.4.0",
|
||||
"_npmOperationalInternal": {
|
||||
"host": "s3://npm-registry-packages",
|
||||
"tmp": "tmp/content-security-policy-builder-2.0.0.tgz_1516725108001_0.698990891687572"
|
||||
},
|
||||
"_npmUser": {
|
||||
"name": "evanhahn",
|
||||
"email": "me@evanhahn.com"
|
||||
},
|
||||
"_npmVersion": "5.6.0",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"raw": "content-security-policy-builder@2.0.0",
|
||||
"scope": null,
|
||||
"escapedName": "content-security-policy-builder",
|
||||
"name": "content-security-policy-builder",
|
||||
"rawSpec": "2.0.0",
|
||||
"spec": "2.0.0",
|
||||
"type": "version"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/helmet-csp"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/content-security-policy-builder/-/content-security-policy-builder-2.0.0.tgz",
|
||||
"_shasum": "8749a1d542fcbe82237281ea9f716ce68b394dd2",
|
||||
"_shrinkwrap": null,
|
||||
"_spec": "content-security-policy-builder@2.0.0",
|
||||
"_where": "/Users/gerrit/Documents/dev/nodejs/rentfor.camp/html/RentForCamp/node_modules/helmet-csp",
|
||||
"author": {
|
||||
"name": "Evan Hahn",
|
||||
"email": "me@evanhahn.com",
|
||||
"url": "https://evanhahn.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/helmetjs/content-security-policy-builder/issues"
|
||||
},
|
||||
"dependencies": {},
|
||||
"description": "Build Content Security Policy directives.",
|
||||
"devDependencies": {
|
||||
"mocha": "^5.0.0",
|
||||
"standard": "^10.0.3"
|
||||
},
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"integrity": "sha512-j+Nhmj1yfZAikJLImCvPJFE29x/UuBi+/MWqggGGc515JKaZrjuei2RhULJmy0MsstW3E3htl002bwmBNMKr7w==",
|
||||
"shasum": "8749a1d542fcbe82237281ea9f716ce68b394dd2",
|
||||
"tarball": "https://registry.npmjs.org/content-security-policy-builder/-/content-security-policy-builder-2.0.0.tgz"
|
||||
},
|
||||
"gitHead": "df00a1af0afda5f6bed57bb7a35af0bd72c12181",
|
||||
"homepage": "https://github.com/helmetjs/content-security-policy-builder#readme",
|
||||
"keywords": [
|
||||
"security",
|
||||
"content",
|
||||
"security",
|
||||
"policy",
|
||||
"csp",
|
||||
"builder"
|
||||
],
|
||||
"license": "MIT",
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "evanhahn",
|
||||
"email": "me@evanhahn.com"
|
||||
}
|
||||
],
|
||||
"name": "content-security-policy-builder",
|
||||
"optionalDependencies": {},
|
||||
"readme": "ERROR: No README data found!",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/helmetjs/content-security-policy-builder.git"
|
||||
},
|
||||
"scripts": {
|
||||
"pretest": "standard --fix",
|
||||
"test": "mocha"
|
||||
},
|
||||
"standard": {
|
||||
"globals": [
|
||||
"describe",
|
||||
"it"
|
||||
]
|
||||
},
|
||||
"version": "2.0.0"
|
||||
}
|
||||
Reference in New Issue
Block a user