Skip to content
This repository has been archived by the owner on Apr 1, 2019. It is now read-only.

Implement SRI #133

Open
oyiptong opened this issue Nov 2, 2015 · 4 comments
Open

Implement SRI #133

oyiptong opened this issue Nov 2, 2015 · 4 comments
Labels

Comments

@oyiptong
Copy link
Contributor

oyiptong commented Nov 2, 2015

Implement Subresource Integrity for the index.html and subsequent pages

@oyiptong
Copy link
Contributor Author

oyiptong commented Nov 2, 2015

here's @dougt's contribution for a build-step that adds the relevant bits to our compiled pages:

var replaceStream = require('replacestream')
  , fs = require('fs')
  , path = require('path')
  , crypto = require('crypto')
  , key = 'big easy key'

 function addIntegrityAttr() {

    var buffer = fs.readFileSync(arguments[1]);

    var hash = crypto.createHash('sha256', key);
    hash.update(buffer)

    return arguments[0] + " integrity=\"sha256-" + hash.digest('hex') + "\"";
}

fs.createReadStream(path.join(__dirname, 'index.html'))
  .pipe(replaceStream(/<script.*src="(.*?)"/g, addIntegrityAttr))
  .pipe(replaceStream(/<link.*href="(.*?)"/g, addIntegrityAttr))
  .pipe(process.stdout);

@marcoscaceres
Copy link
Contributor

@dougt, yeah, something like that would be great.

@franziskuskiefer
Copy link

@oyiptong I think we should use at least sha384 here

@oyiptong
Copy link
Contributor Author

excellent. sha384 it is then.

@k88hudson k88hudson added the ops label Jan 8, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants