# cspeasy

> A simple way to setup Content Security Policy even with inline scripts and styles!

Latest version **0.4.0** (published 2018-06-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install cspeasy
pnpm add cspeasy
yarn add cspeasy
bun add cspeasy
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.0 |
| Published | 2018-06-17 |
| First published | 2018-06-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 11.2 KB |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | jamesrichford |

## Links

- npm: https://www.npmjs.com/package/cspeasy
- Repository: https://github.com/jamesadarich/cspeasy
- Homepage: https://github.com/jamesadarich/cspeasy/blob/master/core/README.md
- Issues: https://github.com/jamesadarich/cspeasy/issues
- npm.io page: https://npm.io/package/cspeasy

## Dependencies (2)

- [jsdom](https://npm.io/package/jsdom.md) ^11.11.0
- [crypto-js](https://npm.io/package/crypto-js.md) ^3.1.9-1

## Recent versions

- 0.4.0 (latest) — 2018-06-17
- 0.3.0 — 2018-06-17
- 0.2.0 — 2018-06-17
- 0.1.0 — 2018-06-16

## README

# cspeasy

A simple way to setup Content Security Policy even with inline scripts and styles!

It digests HTML documents so you can have a strong CSP with necessary inline scripts and styles (e.g. Google Analytics).

## Example

```javascript
import { createServer } from "http";
import { readFile } from "fs";
import { ContentSecurityPolicy, Policies } from "../src/main";
import { resolve } from "path";

const server = createServer((req, res) => {
    const csp = new ContentSecurityPolicy({
        defaultSrc: Policies.None,
    });

    readFile(resolve("test/index.html"), null, (error, data) => {
        if (error) {
            throw error;            
        }

        const indexString = data.toString();

        const hashedCsp = csp.addDocument(indexString);

        res.setHeader("Content-Security-Policy", hashedCsp.getHeaderValue());

        res.end(indexString);
    });
});

const port = 3000;

server.listen(port, () => console.log(`listening on ${port}`));
```

---
_Source: https://npm.io/package/cspeasy · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
