# inline-csp-hash

> Plugin to generate hash for inline scripts and styles for CSP

Latest version **1.1.16** (published 2022-05-12) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install inline-csp-hash
pnpm add inline-csp-hash
yarn add inline-csp-hash
bun add inline-csp-hash
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.1.16 |
| Published | 2022-05-12 |
| First published | 2019-03-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 4.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Volodymyr Kolesnykov |
| Maintainers | wwa |
| Keywords | csp, content security policy, gulp, hash, inline |

## Links

- npm: https://www.npmjs.com/package/inline-csp-hash
- Repository: https://github.com/sjinks/inline-csp-hash.it
- Homepage: https://github.com/sjinks/inline-csp-hash.it#readme
- Issues: https://github.com/sjinks/inline-csp-hash.it/issues
- npm.io page: https://npm.io/package/inline-csp-hash

## Dependencies (2)

- [cheerio](https://npm.io/package/cheerio.md) ^1.0.0-rc.3
- [through2](https://npm.io/package/through2.md) ^4.0.2

## Alternatives

- [@gemini-wallet/core](https://npm.io/package/@gemini-wallet/core.md) — 515.6K weekly downloads
- [utility](https://npm.io/package/utility.md) — 416.6K weekly downloads
- [@primno/dpapi](https://npm.io/package/@primno/dpapi.md) — 7.2K weekly downloads
- [pi-readseek](https://npm.io/package/pi-readseek.md) — 3.7K weekly downloads
- [@emilia-protocol/verify](https://npm.io/package/@emilia-protocol/verify.md) — 1.1K weekly downloads

## Recent versions

- 1.1.16 (latest) — 2022-05-12
- 1.1.15 — 2021-04-08
- 1.1.14 — 2020-10-19
- 1.1.12 — 2020-10-19
- 1.1.11 — 2020-07-28
- 1.1.10 — 2020-07-22
- 1.1.9 — 2020-07-16
- 1.1.8 — 2020-07-02
- 1.1.7 — 2020-04-02
- 1.1.6 — 2019-11-29
- 1.1.5 — 2019-10-08
- 1.1.4 — 2019-08-27
- 1.1.3 — 2019-07-16
- 1.1.2 — 2019-07-06
- 1.1.1 — 2019-06-18
- … 3 more at https://npm.io/package/inline-csp-hash/versions

## README

# inline-csp-hash

![Build and Test CI](https://github.com/sjinks/inline-csp-hash/workflows/Build%20and%20Test%20CI/badge.svg)
[![npm version](https://img.shields.io/npm/v/inline-csp-hash.svg)](https://www.npmjs.com/package/inline-csp-hash)

Plugin to generate hash for inline scripts and styles for CSP.

This plugin is insipred by [hash-csp](https://github.com/chrahunt/hash-csp), and operates mostly the same way.

## Installation

```bash
npm install inline-csp-hash --save
```

## Usage

```javascript
const gulp = require('gulp');
const hashstream = require('inline-csp-hash');

gulp.task('inline-hash', () => {
  return gulp.src('src/*.html')
    .pipe(hashstream({
      what: 'script',
      replace_cb: (s, hashes) => s.replace(/script-src 'self'[^;]*/, "script-src 'self' " + hashes.join(" "))
    }))
    .pipe(hashstream({
      what: 'style',
      replace_cb: (s, hashes) => s.replace(/style-src 'self'[^;]*/, "style-src 'self' " + hashes.join(" "))
    }))
    .pipe(gulp.dest('dist/'))
  ;
});
```

## Options

* what: `script` (default) or `style`: which tags to process (scripts and styles are processed separately because they are controlled by different CSP directives: `script-src` and `style-src`)
* hash: `sha256` (default), `sha384`, or `sha512`: hash algorithm to use. SHA family is the only one according to [the specification](https://w3c.github.io/webappsec-csp/2/#source-list-valid-hashes)
* replace_cb: callback to inject gathered hashes into the source file

## Tests

Have [mocha](https://mochajs.org/) installed and run `npm test`

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