Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
This tool generates a JSON manifest of file hashes & sub-resource integrity data.
npm install --save-dev grunt-sri
Add the following to your Gruntfile.js
:
module.exports = function (grunt) {
"use strict";
grunt.loadNpmTasks("grunt-sri");
grunt.initConfig({
"sri": {
// Use the default settings for *everything* in ./public/css
"bobsDefaultTask": {
"src": [
"public/**/*.css"
]
},
// Create a second manifest with custom settings
"janesCustomTask": {
"options": {
"algorithms": ["sha256"],
"dest": "./public/sri-directives.json",
"targetProp": "payload"
},
"files": [
{
src: "public/css/example.css",
type: "text/css",
id: "cssfile1"
},
{
src: "public/css/other.css"
}
]
}
}
});
grunt.registerTask("default", ["sri"]);
};
Run the command grunt
. The manifest file will be created.
"./payload.json"
false
(overwrite)["sha256", "sha512"]
null
false
Metadata is stored in JSON format.
./payload.json
.Example:
{
"@cssfile1": {
"path": "public/css/example.css",
"type": "text/css",
"integrity": "type:text/css sha256-XXXX sha512-XXXXXXXX",
"hashes": {
"sha256": "XXXX",
"sha512": "XXXXXXXX"
}
}
}
Data from the manifest can be loaded into markup.
Use the integrity
property for SRI integrity attributes, a hash from hashes
as a URL parameter for client-side caching, etc.
// In production, consider compiling JSON to PHP assoc arrays
$payload = json_decode(file_get_contents("./payload.json"), true);
$sri = function (id) {
return $payload["payload"][id];
}
$element = "<link
href='/style.css?cache={ sri("@cssfile1")["hashes"]["sha256"] }'
integrity='{ $sri("@cssfile1")["integrity"] }'
rel='stylesheet'>";
Note: Node apps should use subresource or handlebars-helper-sri, which don't require a build step.
// ES6
var payload = require("./payload.json");
var sri = (id) => payload.payload[id];
var element = `<link
href='/style.css?cache=${ sri("@cssfile1").hashes.sha256 }'
integrity='${ sri("@cssfile1").integrity }'
rel='stylesheet'>`;
This tool follows SemVer from v0.1.0, as SRI is now a W3C recommendation.
Changes to the V1 SRI spec will be tracked with minor releases.
FAQs
Client-side caching & SRI generation for Grunt
The npm package grunt-sri receives a total of 787 weekly downloads. As such, grunt-sri popularity was classified as not popular.
We found that grunt-sri demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.