New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

posthtml-nonce

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

posthtml-nonce

A posthtml plugin for add nanoid to style & script links

latest
Source
npmnpm
Version
0.2.1
Version published
Maintainers
1
Created
Source

posthtml-nonce

A posthtml plugin create whitelist for specific inline scripts,styles,images,media using a cryptographic nonce

Travis Build Statusnodenpm versionDependency StatusXO code styleCoveralls status

Why?

The HTTP Content-Security-Policy response header allows web site administrators to control resources the user agent is allowed to load for a given page. With a few exceptions, policies mostly involve specifying server origins and script endpoints. This helps guard against cross-site scripting attacks (XSS).

Used in conjunction with the middleware

Install

npm i -S posthtml posthtml-nonce

Note: This project is compatible with node v6+

Usage

import {readFileSync, writeFileSync} from 'fs';
import posthtml from 'posthtml';
import posthtmlNonce from 'posthtml-nonce';

const html = readFileSync('input.html', 'utf8');

posthtml()
  .use(posthtmlNonce({tags: ['links'], nonce: '4f90d13a42'}))
  .process(html)
  .then(result => {
    writeFileSync('output.html', result.html);
  });

Example

input.html

<!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet" href="style.css">
  </head>
  <body>
    <img data-src="logo.svg" alt="">
    <script src="script.js"></script>
  </body>
<html>

output.html

<!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet" href="style.css" nonce="4f90d13a42">
  </head>
  <body>
    <img data-src="logo.svg" alt="">
    <script src="script.js"></script>
  </body>
<html>

will be added nonce attribute with nanoid

Options

tags

Type: Array(required)
Default: []
Description: You can also expand the list by adding the tags you need...

nanoid

Type: String(required)
Default: ``
Description: nanoid

Keywords

html

FAQs

Package last updated on 15 Mar 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts