InterviewHubPRO
Section Overview
Q164

Question 164 of 283

Part 7: Change Detection, Security (XSS/Sanitizer) & Interceptors (151 - 176)

58%
Angular & Signals (283 Qs)•Part 7: Change Detection, Security (XSS/Sanitizer) & Interceptors (151 - 176)

What are the various security contexts in Angular?

Angular defines the following security contexts for sanitization,

  1. HTML: It is used when interpreting a value as HTML such as binding to innerHtml.
  2. Style: It is used when binding CSS into the style property.
  3. URL: It is used for URL properties such as <a href>.
  4. Resource URL: It is a URL that will be loaded and executed as code such as <script src>.

Practical Code Example

typescript
// Angular Security Contexts:
import { SecurityContext } from '@angular/core';
// SecurityContext.HTML
// SecurityContext.STYLE
// SecurityContext.SCRIPT
// SecurityContext.URL
// SecurityContext.RESOURCE_URL