{"id":31776337,"url":"https://github.com/abogical/posthtml-sri","last_synced_at":"2026-05-18T09:02:55.517Z","repository":{"id":79876115,"uuid":"328169506","full_name":"Abogical/posthtml-sri","owner":"Abogical","description":"PostHTML subresource integrity plugin | Mirror of https://gitlab.com/Abogical/posthtml-sri","archived":false,"fork":false,"pushed_at":"2024-10-27T22:16:01.000Z","size":1486,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-10T05:28:26.921Z","etag":null,"topics":["npm-package","posthtml","posthtml-plugin","subresource-integrity"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/posthtml-sri","language":"TypeScript","has_issues":false,"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/Abogical.png","metadata":{"files":{"readme":"readme.md","changelog":"changelog.md","contributing":"contributing.md","funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2021-01-09T14:09:55.000Z","updated_at":"2025-06-20T23:14:20.000Z","dependencies_parsed_at":null,"dependency_job_id":"bc554152-b23e-41e8-9750-fecbdd99b078","html_url":"https://github.com/Abogical/posthtml-sri","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Abogical/posthtml-sri","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Abogical%2Fposthtml-sri","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Abogical%2Fposthtml-sri/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Abogical%2Fposthtml-sri/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Abogical%2Fposthtml-sri/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Abogical","download_url":"https://codeload.github.com/Abogical/posthtml-sri/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Abogical%2Fposthtml-sri/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33172173,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-18T05:43:36.989Z","status":"ssl_error","status_checked_at":"2026-05-18T05:43:19.133Z","response_time":71,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["npm-package","posthtml","posthtml-plugin","subresource-integrity"],"created_at":"2025-10-10T05:27:13.180Z","updated_at":"2026-05-18T09:02:55.489Z","avatar_url":"https://github.com/Abogical.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# posthtml-sri\n\nPostHTML plugin that calculates and adds [subresource integrity (SRI)] attributes if they are not set.\n\nBefore:\n\n```html\n\u003chtml\u003e\n\t\u003chead\u003e\n\t\t\u003cscript\n\t\t\tsrc=\"https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.bundle.min.js\"\n\t\t\tcrossorigin=\"anonymous\"\n\t\t\u003e\u003c/script\u003e\n\t\t\u003clink\n\t\t\trel=\"stylesheet\"\n\t\t\thref=\"https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css\"\n\t\t\tcrossorigin=\"anonymous\"\n\t\t/\u003e\n\t\t\u003cscript src='./base.js' integrity='sha512-MYHASH'\u003e\u003c/script\u003e\n\t\u003c/head\u003e\n\u003c/html\u003e\n```\n\nAfter:\n\n```html\n\u003chtml\u003e\n\t\u003chead\u003e\n\t\t\u003cscript src=\"https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.bundle.min.js\" crossorigin=\"anonymous\" integrity=\"sha512-iceXjjbmB2rwoX93Ka6HAHP+B76IY1z0o3h+N1PeDtRSsyeetU3/0QKJqGyPJcX63zysNehggFwMC/bi7dvMig==\"\u003e\u003c/script\u003e\n\t\t\u003clink rel=\"stylesheet\" href=\"https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css\" crossorigin=\"anonymous\" integrity=\"sha512-oc9+XSs1H243/FRN9Rw62Fn8EtxjEYWHXRvjS43YtueEewbS6ObfXcJNyohjHqVKFPoXXUxwc+q1K7Dee6vv9g==\"\u003e\n\t\t\u003cscript src='./base.js' integrity='sha512-MYHASH'\u003e\u003c/script\u003e\n\t\u003c/head\u003e\n\u003c/html\u003e\n```\n\n## Install\n\n```bash\nnpm i posthtml-sri\n```\n\n## Usage\n\n### Example\n\n```js\nconst fs = require('fs');\nconst posthtml = require('posthtml');\nconst posthtmlSri = require('posthtml-sri');\n\nposthtml()\n\t.use(\n\t\tposthtmlSri({\n\t\t\t/* options */\n\t\t})\n\t)\n\t.process(html /*, options */)\n\t.then(result =\u003e fs.writeFileSync('./after.html', result.html));\n```\n\n## Options\n\n### `basePath`\n\nBase path to look for local assets. Asset paths in the HTML are prepended with this option to find and hash the local file.\n\n\u003e Make sure that the local assets the HTML uses are processed first (i.e. transpiled, minified, etc.) before using this plugin to hash them correctly.\n\nBefore:\n```html\n\u003chtml\u003e\n\t\u003chead\u003e\n\t\t\u003cscript src=\"script.js\"\u003e\u003c/script\u003e\n\t\t\u003clink rel=\"stylesheet\" href=\"style.css\" /\u003e\n\t\u003c/head\u003e\n\u003c/html\u003e\n```\n\nAdd option:\n\n```js\nconst fs = require('fs');\nconst posthtml = require('posthtml');\nconst posthtmlSri = require('posthtml-sri');\n\nposthtml()\n\t.use(posthtmlSri({ basePath: 'assets' }))\n\t.process(html)\n\t.then(result =\u003e fs.writeFileSync('./after.html', result.html));\n```\n\nAfter:\n\n```html\n\u003chtml\u003e\n\t\u003chead\u003e\n\t\t\u003cscript src=\"script.js\" integrity=\"sha512-MUS7Gdcgr3In98ODhITyPjXWdWE9dezoOcyopcyYXzpFz2LrOApCRupkTwgiaS31+DhQacgbQ5T1hlGWPiBNGQ==\"\u003e\u003c/script\u003e\n\t\t\u003clink rel=\"stylesheet\" href=\"style.css\" integrity=\"sha512-CVazCeMWuNKPH6VzeuYxVGC3JKXVQB/wqncMrpHoS3wJclPNeKN+SxO/zz1A9U3s2zczk/Yx1iZEJ6+CwJW81A==\"\u003e\n\t\u003c/head\u003e\n\u003c/html\u003e\n```\n\n### `algorithms`\n\nArray of hash algorithms to use. By default, it follows the [ssri] default, currently `['sha512']`.\n\nBefore:\n\n```html\n\u003chtml\u003e\n\t\u003chead\u003e\n\t\t\u003cscript\n\t\t\tsrc=\"https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.bundle.min.js\"\n\t\t\tcrossorigin=\"anonymous\"\n\t\t\u003e\u003c/script\u003e\n\t\t\u003clink\n\t\t\trel=\"stylesheet\"\n\t\t\thref=\"https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css\"\n\t\t\tcrossorigin=\"anonymous\"\n\t\t/\u003e\n\t\u003c/head\u003e\n\u003c/html\u003e\n```\n\nAdd option:\n\n```js\nconst fs = require('fs');\nconst posthtml = require('posthtml');\nconst posthtmlSri = require('posthtml-sri');\n\nposthtml()\n\t.use(posthtmlSri({ algorithms: ['sha512', 'sha384'] }))\n\t.process(html)\n\t.then(result =\u003e fs.writeFileSync('./after.html', result.html));\n```\n\nAfter:\n\n```html\n\u003chtml\u003e\n\t\u003chead\u003e\n\t\t\u003cscript src=\"https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.bundle.min.js\" crossorigin=\"anonymous\" integrity=\"sha512-iceXjjbmB2rwoX93Ka6HAHP+B76IY1z0o3h+N1PeDtRSsyeetU3/0QKJqGyPJcX63zysNehggFwMC/bi7dvMig== sha384-ho+j7jyWK8fNQe+A12Hb8AhRq26LrZ/JpcUGGOn+Y7RsweNrtN/tE3MoK7ZeZDyx\"\u003e\u003c/script\u003e\n\t\t\u003clink rel=\"stylesheet\" href=\"https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css\" crossorigin=\"anonymous\" integrity=\"sha512-oc9+XSs1H243/FRN9Rw62Fn8EtxjEYWHXRvjS43YtueEewbS6ObfXcJNyohjHqVKFPoXXUxwc+q1K7Dee6vv9g== sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2\"\u003e\n\t\u003c/head\u003e\n\u003c/html\u003e\n```\n\n## `cache`\n\nA regular object mapping paths/URLs to integrity values. If an `src`\nis found in the cache, the cached value will be reused. Only exact\nmatches are considered. By default, it uses a new empty object.\n\n## `fetch`\n\nA function that takes a URL and returns a `Response`. Defaults to\n[Node.js' native fetch function].\n\n[subresource integrity (sri)]: https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity\n[ssri]: https://www.npmjs.com/package/ssri\n[Node.js' native fetch function]: https://nodejs.org/en/blog/announcements/v21-release-announce#stable-fetchwebstreams\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabogical%2Fposthtml-sri","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fabogical%2Fposthtml-sri","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabogical%2Fposthtml-sri/lists"}