From 2e19d8b30b104293dc98aa6b5669a60f8a17de9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Murat=20G=C3=B6zel?= Date: Tue, 19 May 2020 23:23:26 +0300 Subject: [PATCH] updated description and readme. --- README.md | 40 +++++++++++++++++++++++++++++++++------- package.json | 4 ++-- 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 283bbc5..a4dda8f 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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:') @@ -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') @@ -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') +` + +` ``` +## 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 🐬 diff --git a/package.json b/package.json index 834a36f..c8a6e65 100644 --- a/package.json +++ b/package.json @@ -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",