+13
-14
@@ -1,21 +0,20 @@ | ||
| const path = require('path'); | ||
| const exec = require('child_process').exec; | ||
| const crypto = require('crypto'); | ||
| function getSRIHash(filePath) { | ||
| const algorithm = 'sha384'; | ||
| return new Promise(function(resolve, reject) { | ||
| function getSRIString(data) { | ||
| return getIntegrity(algorithm, getSRIHash(data)); | ||
| } | ||
| exec(getCommand(filePath), function(err, stdout, stderr) { | ||
| if (err) { reject(err); } | ||
| else { resolve(stdout); } | ||
| }); | ||
| }); | ||
| function getIntegrity(algorithm, hash) { | ||
| return `${algorithm}-${hash}`; | ||
| } | ||
| function getCommand(filePath) { | ||
| return `cat ${path.join(__dirname, filePath)} | openssl dgst -sha384 -binary | openssl enc -base64 -A` | ||
| function getSRIHash(data) { | ||
| return crypto | ||
| .createHash(algorithm) | ||
| .update(data, 'utf8') | ||
| .digest('base64'); | ||
| } | ||
| module.exports = getSRIHash; | ||
| module.exports = { getSRIString }; |
+1
-1
| { | ||
| "name": "sri", | ||
| "version": "1.0.0", | ||
| "version": "1.1.0", | ||
| "description": "Subresource Integrity hash generator", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
+2
-4
@@ -16,7 +16,5 @@ # sri | ||
| ```javascript | ||
| const getSRIHash = require('sri'); | ||
| const sri = require('sri'); | ||
| getSRIHash('file.js') | ||
| .then((hash) => console.log(hash)) | ||
| .catch((error) => console.error(error)); | ||
| const sriString = sri.getSRIString('file.js'); // sha384-J5Dqvq3... | ||
| ``` |
+13
-11
@@ -1,14 +0,16 @@ | ||
| const getSRIHash = require('../index'); | ||
| const sri = require('../index'); | ||
| const fs = require('fs'); | ||
| const path = require('path'); | ||
| const expected = 'bFHdtDIrMJABoPy41E4hepGKnrLYuQ60YjPufbnrIQFU0da1u62PDdnK+aVeB3gr'; | ||
| const expected = 'sha384-J5Dqvq3qATcLhtSkdquOAC/pjNfj8c+oSP55YxlmhCRpAmMfdBuTMJZodkLMhw2r'; | ||
| getSRIHash('./index.js') | ||
| .then(function(hash) { | ||
| fs.readFile(path.join(__dirname, '../index.js'), 'utf8', function(err, data) { | ||
| if (hash !== expected) { | ||
| throw Error(`Wrong hash: ${hash}`); | ||
| } else { | ||
| console.log(`Passed: ${hash}`); | ||
| } | ||
| }) | ||
| .catch(function(err) { console.log(err); }); | ||
| const sriString = sri.getSRIString(data); | ||
| if (sriString !== expected) { | ||
| throw Error(`Wrong hash: ${sriString}`); | ||
| } else { | ||
| console.log(`Passed: ${sriString}`); | ||
| } | ||
| }); |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Obfuscated code
Supply chain riskObfuscated files are intentionally packed to hide their behavior. This could be a sign of malware.
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
27
8%0
-100%0
-100%2455
-1.88%20
-9.09%2
100%