Skip to main content

no-angularjs-ng-bind-html-without-sanitize

Disallow AngularJS ng-bind-html usage when sanitization is not explicit.

Targeted pattern scopeโ€‹

AngularJS templates using ng-bind-html without explicit sanitize context.

What this rule reportsโ€‹

ng-bind-html usage in template strings that do not indicate sanitize support.

Why this rule existsโ€‹

Unsafe HTML binding in AngularJS can lead to reflected or stored XSS.

โŒ Incorrectโ€‹

const template = `<div ng-bind-html="unsafeHtml"></div>`;

โœ… Correctโ€‹

const template = `<div ng-bind-html="trustedHtml" ngSanitize></div>`;

ESLint flat config exampleโ€‹

import sdl from "eslint-plugin-sdl-2";

export default [
{
plugins: { sdl },

rules: {
"sdl/no-angularjs-ng-bind-html-without-sanitize": "error",
},
},
];

When not to use itโ€‹

Disable only if the project has explicit AngularJS sanitization controls and a reviewed HTML trust pipeline.

Package documentationโ€‹

Further readingโ€‹

Rule catalog ID: R030