{"id":15661961,"url":"https://github.com/jonaskruckenberg/rollup-plugin-sri","last_synced_at":"2025-04-30T15:22:55.587Z","repository":{"id":37807432,"uuid":"265374538","full_name":"JonasKruckenberg/rollup-plugin-sri","owner":"JonasKruckenberg","description":"Add subresource integrity tags to all your html files 🔒","archived":false,"fork":false,"pushed_at":"2023-01-09T03:49:46.000Z","size":1100,"stargazers_count":26,"open_issues_count":9,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-30T15:22:26.670Z","etag":null,"topics":["integrity","rollup-plugin","rollup-plugin-rsi","security","subresource-integrity"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JonasKruckenberg.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["JonasKruckenberg"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":["https://paypal.me/jonaskruckie"]}},"created_at":"2020-05-19T21:44:45.000Z","updated_at":"2025-04-18T06:27:53.000Z","dependencies_parsed_at":"2023-02-08T08:46:21.818Z","dependency_job_id":null,"html_url":"https://github.com/JonasKruckenberg/rollup-plugin-sri","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JonasKruckenberg%2Frollup-plugin-sri","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JonasKruckenberg%2Frollup-plugin-sri/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JonasKruckenberg%2Frollup-plugin-sri/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JonasKruckenberg%2Frollup-plugin-sri/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JonasKruckenberg","download_url":"https://codeload.github.com/JonasKruckenberg/rollup-plugin-sri/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251729807,"owners_count":21634293,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["integrity","rollup-plugin","rollup-plugin-rsi","security","subresource-integrity"],"created_at":"2024-10-03T13:29:41.518Z","updated_at":"2025-04-30T15:22:55.559Z","avatar_url":"https://github.com/JonasKruckenberg.png","language":"TypeScript","funding_links":["https://github.com/sponsors/JonasKruckenberg","https://paypal.me/jonaskruckie"],"categories":[],"sub_categories":[],"readme":"\u003e ## **NOTE**: ‼️ This project will be archived in **2 Weeks**! \n\u003e \n\u003e If you're interested in why or potentially continue maintaining this repo [read here](https://github.com/JonasKruckenberg/rollup-plugin-sri/issues/393)\n\n\u003cbr /\u003e\n\u003cbr /\u003e\n\n# rollup-plugin-sri\n\n\u003e Because web security should not be difficult.\n \n[![Codecov Coverage](https://img.shields.io/codecov/c/github/JonasKruckenberg/rollup-plugin-sri/master.svg?style=flat-square)](https://codecov.io/gh/JonasKruckenberg/rollup-plugin-sri/)\n[![standard-readme compliant](https://img.shields.io/badge/readme%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)\n![npm](https://img.shields.io/npm/v/rollup-plugin-sri?style=flat-square)\n\nThis plugin adds [subresource integrity](https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity) attributes to all resources imported by your html files.\n\n## Table of Contents\n\n- [Install](#install)\n- [Usage](#usage)\n  - [Simple](#simple)\n  - [External resources](#external-resources)\n  - [Multiple hashing algorithms](#multiple-hashing-algorithms)\n  - [Usage with Vite](#usage-with-vite)\n- [Options](#options)\n- [Contributing](#contributing)\n- [License](#license)\n\n## Install\n\nvia npm:\n```\nnpm install --save-dev rollup-plugin-sri\n```\n\nor via yarn:\n```\nyarn add -D rollup-plugin-sri\n```\n\n## Usage\n\nJust use this plugin together with another plugin that outputs an html file, like [@rollup/plugin-html](https://github.com/rollup/plugins/tree/master/packages/html). \u003cbr /\u003e\nIt will then generate `integrity` and `crossorigin` attributes for all script tags and all link rel=\"stylesheet\" tags.\n\n```js\nimport html from '@rollup/plugin-html' // or any other html-plugin\nimport sri from 'rollup-plugin-sri'\n\nexport default {\n  input: 'index.js',\n  output: {\n    file: 'out.js',\n    format: 'es'\n  },\n  plugins: [html(), sri()]\n}\n```\n\n## Examples\n\n### Simple\n\nYou might have a script tag in your html to include a javascript file like this:\n\n```html\n\u003cscript src=\"index.js\"\u003e\u003c/script\u003e\n```\n\nWhich then gets turned into this:\n\n```html\n\u003cscript\n  src=\"index.js\"\n  integrity=\"sha512-nbecVo2rGsF6Q3d4sK/sF4AmMv3eIxXpjk6Larv6iDUWeaRjjYL44RyK45vPO3Aav/ep6qTgbUAebC20uEGq8g== sha384-zFyvltviTuMi40r9uTjP6Cc/kdJy3hboH2SbOT2Q7UaXK8c4+DtTEAG16VM0H4tP\"\n  crossorigin=\"anonymous\"\n\u003e\u003c/script\u003e\n```\n\n### External resources\n\nLet's say you're using Bootstrap on your page, but it get dynamically injected so you can't set the integrity attribute yourself. \u003cbr /\u003e\nThe html will then look something like this:\n\n```html\n\u003clink\n  rel=\"stylesheet\"\n  href=\"https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css\"\n/\u003e\n```\n\nThis plugin will turn it into the following:\n\n```html\n\u003clink\n  rel=\"stylesheet\"\n  href=\"https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css\"\n  integrity=\"sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk\"\n  crossorigin=\"anonymous\"\n/\u003e\n```\n\n### Multiple hashing algorithms\n\nYou can also specify any number of hashing algorithms to be used by the plugin as long as they are supported by your current version of nodejs.\n\n```js\nimport html from '@rollup/plugin-html' // @rollup/plugin-html for example\nimport sri from 'rollup-plugin-sri'\n\nexport default {\n  input: 'index.js',\n  output: {\n    file: 'out.js',\n    format: 'es'\n  },\n  plugins: [\n    html(),\n    sri({\n      algorithms: ['sha1', 'md5', 'sha512']\n    })\n  ]\n}\n```\n\nThis config will generate an output like this:\n\n```html\n\u003cscript\n  src=\"index.js\"\n  integrity=\"sha1-uwq/zzhXJzUJKIrPcWeL6RkTC8I= md5-illu96GKKoep5d+RUptcBw== sha512-k2VO1XnXo7MN/pqEHWCJYyn4D2d5z0FSDRvIrz4WPmw4VTPNhnSMJRvAwz2Llaij45VU35+eO3eQjydVhGggLg==\"\n  crossorigin=\"anonymous\"\n\u003e\u003c/script\u003e\n```\n\n\u003e There are a few things to note though:\n\u003e\n\u003e 1. You can in theory use any hashing algorithm you want, however most browser only support the sha family of hashing algorithms like sha256, sha384 and sha512\n\u003e 2. Browser vendors are actively discouraged from using `md5` and `sha1` as they are not considered to be secure enough.\n\u003e    Most modern browser won't accept them at all.\n\n### Usage with Vite\n\nTo use this plugin together with [vite](https://vitejs.dev) use the configuration below.\n\n```js\nimport { defineConfig } from \"vite\"\nimport sri from \"rollup-plugin-sri\"\n\nexport default defineConfig({\n  plugins: [\n    {\n      enforce: \"post\",\n      ...sri({ publicPath: \"/\" })\n    }\n  ]\n})\n```\n\n\u003e NOTE: Becuase of the way vite works, this plugin only applies SRIs when building for production. To get the same experience in development mode, check out [vite-plugin-sri](https://github.com/small-tech/vite-plugin-sri)!\n\n## Options\n\n\u003e For the most up-to-date version of the options see the autogenerated [docs](./docs/README.md).\n\n### `Optional` active\n\nType: _boolean_ \u003cbr/\u003e\n**`default`** `true`\n\nCan be used to disable the plugin, as subresource integrities might cause issues with hot module reloading.\n\n---\n\n### `Optional` algorithms\n\nType: _Array[*string* \\| *sha256* \\| *sha384* \\| *sha512*]_ \u003cbr/\u003e\n**`default`** `[\"sha384\"]`\n\nA list of hashing algorithms to use when computing the integrity attribute.\nThe hashing algorithm has to be supported by the nodejs version you're running on and by the Browser you're targeting.\nBrowsers will ignore unknown hashing functions.\nStandard hash functions as defined in the [subresource integrity specification](https://w3c.github.io/webappsec-subresource-integrity/#hash-functions) are: `sha256`, `sha384` and `sha512`.\n\n\u003e NOTE: While browser vendors are free to support more algorithms than those stated above,\n\u003e they generally do not accept `sha1` and `md5` hashes.\n\n---\n\n### `Optional` crossorigin\n\nType: _\"anonymous\" | \"use-credentials\"_ \u003cbr/\u003e\n**`default`** `\"anonymous\"`\n\nSpecifies the value for the crossorigin attribute.\nThis attribute has to be set to prevent cross-origin data leakage.\nThe default value `anonymous` should be okay for normal use.\nsee: [the W3C spec](https://www.w3.org/TR/SRI/#cross-origin-data-leakage) for details.\n\n---\n\n### `Optional` selectors\n\nType: _Array[string]_ \u003cbr/\u003e\n**`default`** ` [\"script\",\"link[rel=stylesheet]\"]`\n\nA list of strings you can provide that the plugin will use to match html tags with.\nIt will then try to compute an integrity attribute for the matched tag.\nCurrently it only matches script tags and link with rel=stylesheet as per specification.\nsee [the W3C spec](https://www.w3.org/TR/SRI/#elements) for more information.\nThe selector syntax is the same as jQuery's.\n\n\n### `Optional` publicPath\n\nType: _string_\n**`default`** `\"\"`\n\nCommonly assets will be prefixed with a public path, such as \"/\" or \"/assets\".\nSetting this option to the public path allows plugin-sri to resolve those imports.\n\n## Contributing\n\nFor bug reports or feature requests please create an issue on github.\nWhen working on a feature contribution, please ensure the following things:\n\n- Keep you code clear and readable.\n- Write unit tests for your feature (run `yarn test`).\n- Use the convetional-commits style when writing commit messages.\n- Use appropriate commit types, When adding tests use `test:` when adding a feature use `feat:` etc.\n- Split up the files you commit logically not by workday or something else, for example all test belonging to a new feature should be in their own commit and not bunched together with other changes or tests for other features.\n\n## Sponsoring\n\nAre you using imagetools in your company, in a commercial project or just feeling generous? \u003cbr\u003e\nConsider [sponsoring me on GitHub](https://github.com/sponsors/JonasKruckenberg) to support the development and get your companies logo featured!\n\n## License\n\n[MIT © Jonas Kruckenberg.](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonaskruckenberg%2Frollup-plugin-sri","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonaskruckenberg%2Frollup-plugin-sri","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonaskruckenberg%2Frollup-plugin-sri/lists"}