{"id":13463209,"url":"https://github.com/mozilla/eslint-plugin-no-unsanitized","last_synced_at":"2025-05-14T08:05:51.818Z","repository":{"id":31969262,"uuid":"35539361","full_name":"mozilla/eslint-plugin-no-unsanitized","owner":"mozilla","description":"Custom ESLint rule to disallows unsafe innerHTML, outerHTML, insertAdjacentHTML and alike","archived":false,"fork":false,"pushed_at":"2024-11-19T00:21:38.000Z","size":581,"stargazers_count":236,"open_issues_count":31,"forks_count":36,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-05-08T04:32:31.348Z","etag":null,"topics":["eslint-plugin","security"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mozilla.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-05-13T09:12:59.000Z","updated_at":"2025-04-08T17:24:29.000Z","dependencies_parsed_at":"2024-07-05T19:34:33.351Z","dependency_job_id":"0796b09a-1151-4e5f-a2cf-58f0d04c5715","html_url":"https://github.com/mozilla/eslint-plugin-no-unsanitized","commit_stats":{"total_commits":180,"total_committers":26,"mean_commits":6.923076923076923,"dds":0.7055555555555555,"last_synced_commit":"f38af64439c1f5dccb7b595b0ce634cc8f82f1e5"},"previous_names":["mozfreddyb/eslint-plugin-no-unsafe-innerhtml"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mozilla%2Feslint-plugin-no-unsanitized","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mozilla%2Feslint-plugin-no-unsanitized/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mozilla%2Feslint-plugin-no-unsanitized/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mozilla%2Feslint-plugin-no-unsanitized/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mozilla","download_url":"https://codeload.github.com/mozilla/eslint-plugin-no-unsanitized/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253754693,"owners_count":21958896,"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":["eslint-plugin","security"],"created_at":"2024-07-31T13:00:48.111Z","updated_at":"2025-05-14T08:05:51.779Z","avatar_url":"https://github.com/mozilla.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","Plugins","Code"],"sub_categories":["Security","Linters"],"readme":"[![Build Status](https://travis-ci.org/mozilla/eslint-plugin-no-unsanitized.svg?branch=master)](https://travis-ci.org/mozilla/eslint-plugin-no-unsanitized)\n\n# Disallow unsanitized code (no-unsanitized)\n\nThese rules disallow unsafe coding practices that may result into security\nvulnerabilities. We will disallow assignments (e.g., to innerHTML) as well as\ncalls (e.g., to insertAdjacentHTML) without the use of a pre-defined escaping\nfunction. The escaping functions must be called with a template string.\nThe function names are hardcoded as `Sanitizer.escapeHTML` and `escapeHTML`.\nThe plugin also supports the\n[Sanitizer API](https://developer.mozilla.org/en-US/docs/Web/API/HTML_Sanitizer_API)\nand calls to `.setHTML()` are also allowed by default.\n\nThis plugin is built for and used within Mozilla to maintain and improve the security\nof our products and services.\n\n# Rule Details\n\n## method\n\nThe _method_ rule disallows certain function calls.\nE.g., `document.write()` or `insertAdjacentHTML()`.\nSee [docs/rules/method.md](docs/rules/method.md) for more.\n\n## property\n\nThe _property_ rule disallows certain assignment expressions, e.g., to `innerHTML`.\n\nSee [docs/rules/property.md](docs/rules/property.md) for more.\n\n## Examples\n\nHere are a few examples of code that we do not want to allow:\n\n```js\nfoo.innerHTML = input.value;\nbar.innerHTML = \"\u003ca href='\" + url + \"'\u003eAbout\u003c/a\u003e\";\n```\n\nA few examples of allowed practices:\n\n```js\nfoo.innerHTML = 5;\nbar.innerHTML = \"\u003ca href='/about.html'\u003eAbout\u003c/a\u003e\";\nbar.innerHTML = escapeHTML`\u003ca href='${url}'\u003eAbout\u003c/a\u003e`;\n```\n\n# Install\n\nWith **yarn** or **npm**:\n\n```bash\n$ yarn add -D eslint-plugin-no-unsanitized\n$ npm install --save-dev eslint-plugin-no-unsanitized\n```\n\n## Usage\n\n### Flat config\n\n```js\nimport nounsanitized from \"eslint-plugin-no-unsanitized\";\n\nexport default config = [nounsanitized.configs.recommended];\n```\n\nor\n\n```js\nimport nounsanitized from \"eslint-plugin-no-unsanitized\";\n\nexport default config = [\n    {\n        files: [\"**/*.js\"],\n        plugins: { nounsanitized },\n        rules: {\n            \"no-unsanitized/method\": \"error\",\n            \"no-unsanitized/property\": \"error\",\n        },\n    },\n];\n```\n\n### eslintrc\n\nIn your `.eslintrc.json` file enable this rule with the following:\n\n```json\n{\n    \"extends\": [\"plugin:no-unsanitized/recommended-legacy\"]\n}\n```\n\nOr:\n\n```json\n{\n    \"plugins\": [\"no-unsanitized\"],\n    \"rules\": {\n        \"no-unsanitized/method\": \"error\",\n        \"no-unsanitized/property\": \"error\"\n    }\n}\n```\n\n# Documentation\n\nSee [docs/](docs/).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmozilla%2Feslint-plugin-no-unsanitized","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmozilla%2Feslint-plugin-no-unsanitized","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmozilla%2Feslint-plugin-no-unsanitized/lists"}