diff options
author | Kat Marchán <kzm@sykosomatic.org> | 2018-02-08 20:09:38 +0300 |
---|---|---|
committer | Rebecca Turner <me@re-becca.org> | 2018-02-20 05:32:06 +0300 |
commit | 81da938ab6efb881123cdcb44f7f84551924c988 (patch) | |
tree | d3bcdc907066681360b476a95e535183c5b2c39b /node_modules/ssri | |
parent | dc3059522758470adc225f0651be72c274bd29ef (diff) |
ssri@5.2.1
Diffstat (limited to 'node_modules/ssri')
-rw-r--r-- | node_modules/ssri/CHANGELOG.md | 15 | ||||
-rw-r--r-- | node_modules/ssri/README.md | 22 | ||||
-rw-r--r-- | node_modules/ssri/index.js | 29 | ||||
-rw-r--r-- | node_modules/ssri/package.json | 22 |
4 files changed, 65 insertions, 23 deletions
diff --git a/node_modules/ssri/CHANGELOG.md b/node_modules/ssri/CHANGELOG.md index bc65681c6..177c1763b 100644 --- a/node_modules/ssri/CHANGELOG.md +++ b/node_modules/ssri/CHANGELOG.md @@ -2,6 +2,21 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +<a name="5.2.1"></a> +## [5.2.1](https://github.com/zkat/ssri/compare/v5.2.0...v5.2.1) (2018-02-06) + + + +<a name="5.2.0"></a> +# [5.2.0](https://github.com/zkat/ssri/compare/v5.1.0...v5.2.0) (2018-02-06) + + +### Features + +* **match:** add integrity.match() ([3c49cc4](https://github.com/zkat/ssri/commit/3c49cc4)) + + + <a name="5.1.0"></a> # [5.1.0](https://github.com/zkat/ssri/compare/v5.0.0...v5.1.0) (2018-01-18) diff --git a/node_modules/ssri/README.md b/node_modules/ssri/README.md index f2fc035da..e03ad0018 100644 --- a/node_modules/ssri/README.md +++ b/node_modules/ssri/README.md @@ -21,6 +21,7 @@ Integrity](https://w3c.github.io/webappsec/specs/subresourceintegrity/) hashes. * [`Integrity#concat`](#integrity-concat) * [`Integrity#toString`](#integrity-to-string) * [`Integrity#toJSON`](#integrity-to-json) + * [`Integrity#match`](#integrity-match) * [`Integrity#pickAlgorithm`](#integrity-pick-algorithm) * [`Integrity#hexDigest`](#integrity-hex-digest) * Integrity Generation @@ -218,6 +219,27 @@ const integrity = '"sha512-9KhgCRIx/AmzC8xqYJTZRrnO8OW2Pxyl2DIMZSBOr0oDvtEFyht3x JSON.stringify(ssri.parse(integrity)) === integrity ``` +#### <a name="integrity-match"></a> `> Integrity#match(sri, [opts]) -> Hash | false` + +Returns the matching (truthy) hash if `Integrity` matches the argument passed as +`sri`, which can be anything that [`parse`](#parse) will accept. `opts` will be +passed through to `parse` and [`pickAlgorithm()`](#integrity-pick-algorithm). + +##### Example + +```javascript +const integrity = 'sha512-9KhgCRIx/AmzC8xqYJTZRrnO8OW2Pxyl2DIMZSBOr0oDvtEFyht3xpp71j/r/pAe1DM+JI/A+line3jUBgzQ7A==' + +ssri.parse(integrity).match(integrity) +// Hash { +// digest: '9KhgCRIx/AmzC8xqYJTZRrnO8OW2Pxyl2DIMZSBOr0oDvtEFyht3xpp71j/r/pAe1DM+JI/A+line3jUBgzQ7A==' +// algorithm: 'sha512' +// } + +ssri.parse(integrity).match('sha1-deadbeef') +// false +``` + #### <a name="integrity-pick-algorithm"></a> `> Integrity#pickAlgorithm([opts]) -> String` Returns the "best" algorithm from those available in the integrity object. diff --git a/node_modules/ssri/index.js b/node_modules/ssri/index.js index 853ee7f45..ba1bb6d1b 100644 --- a/node_modules/ssri/index.js +++ b/node_modules/ssri/index.js @@ -93,6 +93,19 @@ class Integrity { hexDigest () { return parse(this, {single: true}).hexDigest() } + match (integrity, opts) { + const other = parse(integrity, opts) + const algo = other.pickAlgorithm(opts) + return ( + this[algo] && + other[algo] && + this[algo].find(hash => + other[algo].find(otherhash => + hash.digest === otherhash.digest + ) + ) + ) || false + } pickAlgorithm (opts) { const pickAlgorithm = (opts && opts.pickAlgorithm) || getPrioritizedHash const keys = Object.keys(this) @@ -205,9 +218,8 @@ function checkData (data, sri, opts) { sri = parse(sri, opts) if (!Object.keys(sri).length) { return false } const algorithm = sri.pickAlgorithm(opts) - const digests = sri[algorithm] || [] const digest = crypto.createHash(algorithm).update(data).digest('base64') - return digests.find(hash => hash.digest === digest) || false + return parse({algorithm, digest}).match(sri, opts) } module.exports.checkStream = checkStream @@ -254,17 +266,8 @@ function integrityStream (opts) { const newSri = parse(hashes.map((h, i) => { return `${algorithms[i]}-${h.digest('base64')}${optString}` }).join(' '), opts) - const match = ( - // Integrity verification mode - opts.integrity && - newSri[algorithm] && - digests && - digests.find(hash => { - return newSri[algorithm].find(newhash => { - return hash.digest === newhash.digest - }) - }) - ) + // Integrity verification mode + const match = goodSri && newSri.match(sri, opts) if (typeof opts.size === 'number' && streamSize !== opts.size) { const err = new Error(`stream size mismatch when checking ${sri}.\n Wanted: ${opts.size}\n Found: ${streamSize}`) err.code = 'EBADSIZE' diff --git a/node_modules/ssri/package.json b/node_modules/ssri/package.json index 4a7f965e8..f0de2e211 100644 --- a/node_modules/ssri/package.json +++ b/node_modules/ssri/package.json @@ -1,8 +1,8 @@ { "_from": "ssri@latest", - "_id": "ssri@5.1.0", + "_id": "ssri@5.2.1", "_inBundle": false, - "_integrity": "sha512-TevC8fgxQKTfQ1nWtM9GNzr3q5rrHNntG9CDMH1k3QhSZI6Kb+NbjLRs8oPFZa2Hgo7zoekL+UTvoEk7tsbjQg==", + "_integrity": "sha512-y4PjOWlAuxt+yAcXitQYOnOzZpKaH3+f/qGV3OWxbyC2noC9FA9GNC9uILnVdV7jruA1aDKr4OKz3ZDBcVZwFQ==", "_location": "/ssri", "_phantomChildren": {}, "_requested": { @@ -18,11 +18,13 @@ "_requiredBy": [ "#USER", "/", + "/cacache", "/pacote", + "/pacote/cacache", "/pacote/make-fetch-happen" ], - "_resolved": "https://registry.npmjs.org/ssri/-/ssri-5.1.0.tgz", - "_shasum": "2cbf1df36b74d0fc91fcf89640a4b3e1d10b1899", + "_resolved": "https://registry.npmjs.org/ssri/-/ssri-5.2.1.tgz", + "_shasum": "8b6eb873688759bd3c75a88dee74593d179bb73c", "_spec": "ssri@latest", "_where": "/Users/zkat/Documents/code/npm", "author": { @@ -42,15 +44,15 @@ } }, "dependencies": { - "safe-buffer": "^5.1.0" + "safe-buffer": "^5.1.1" }, "deprecated": false, "description": "Standard Subresource Integrity library -- parses, serializes, generates, and verifies integrity metadata according to the SRI spec.", "devDependencies": { - "nyc": "^10.3.2", - "standard": "^9.0.2", - "standard-version": "^4.1.0", - "tap": "^10.3.3", + "nyc": "^11.4.1", + "standard": "^10.0.3", + "standard-version": "^4.3.0", + "tap": "^11.1.0", "weallbehave": "^1.2.0", "weallcontribute": "^1.0.8" }, @@ -88,5 +90,5 @@ "update-coc": "weallbehave -o . && git add CODE_OF_CONDUCT.md && git commit -m 'docs(coc): updated CODE_OF_CONDUCT.md'", "update-contrib": "weallcontribute -o . && git add CONTRIBUTING.md && git commit -m 'docs(contributing): updated CONTRIBUTING.md'" }, - "version": "5.1.0" + "version": "5.2.1" } |