Skip to content

Commit

Permalink
updated description and readme.
Browse files Browse the repository at this point in the history
  • Loading branch information
muratgozel committed May 19, 2020
1 parent 9c0b293 commit 2e19d8b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
40 changes: 33 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# csp-dev
Content security policy builder and parser. 🚨
Spec compliant content security policy builder and parser. 🚨

![NPM](https://img.shields.io/npm/l/csp-dev)
[![npm version](https://badge.fury.io/js/csp-dev.svg)](https://badge.fury.io/js/csp-dev)
Expand All @@ -12,12 +12,12 @@ npm i -D csp-dev
```

## Use
Build:
### Build Policy
```js
const ContentSecurityPolicy = require('csp-dev')

const builder = new ContentSecurityPolicy()
builder.newDirective('script-src', ['self', 'unsafe-inline', 'nonce-2726c7f26c', '*.trusted.com'])
builder.newDirective('script-src', ['self', 'unsafe-inline', 'nonce-2726c7f26c', '*.test.com'])
builder.newDirective('default-src', 'self')
builder.newDirective('style-src', 'data:')

Expand All @@ -27,12 +27,12 @@ const builder2 = new ContentSecurityPolicy()
builder2.load({
'default-src': ['self'],
'script-src': [
'self', 'unsafe-inline', 'nonce-2726c7f26c', '*.trusted.com'
'self', 'unsafe-inline', 'nonce-2726c7f26c', '*.test.com'
],
'style-src': ['data:']
})
```
Parse:
### Parse Policy Data
```js
const ContentSecurityPolicy = require('csp-dev')

Expand All @@ -45,11 +45,37 @@ const parser = new ContentSecurityPolicy(data)

parser.valid() // true|false
```
Share:
### Share
Share data as **json**, spec compliant csp **string** or **html** meta tag:
```js
parser.share('json'|'string')
parser.share('json')
`
{
'default-src': ['self'],
'script-src': [
'self', 'unsafe-inline', 'nonce-2726c7f26c', '*.test.com'
],
'style-src': ['data:']
}
`

parser.share('string')
`
default-src 'self'; script-src 'self' 'unsafe-inline' 'nonce-2726c7f26c' *.test.com; style-src data:
`

parser.share('html')
`
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self' 'unsafe-inline' 'nonce-2726c7f26c' *.test.com; style-src data:">
`
```

## Tests
See `spec` folder for tests. I'll expand the test suite as I update the library. You can run tests by `npm run test`

## Notes
The reporting feature of csp hasn't been implemented. I didn't get fully understand but I think there is no accepted standart for it for now.

---

Thanks for watching 🐬
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "csp-dev",
"version": "1.0.0",
"description": "Content security policy builder and parser. 🚨",
"version": "1.0.1",
"description": "Spec compliant content security policy builder and parser. 🚨",
"main": "src/index.js",
"scripts": {
"test": "NODE_ENV=test jasmine",
Expand Down

0 comments on commit 2e19d8b

Please sign in to comment.