angular-template-sanitizer-security-review
Statically review Angular templates and components for injection via DomSanitizer bypass calls (bypassSecurityTrustHtml, bypassSecurityTrustUrl, bypassSecurityTrustResourceUrl), unsanitized [innerHTML] bindings, and dynamically bound iframe security attributes such as [attr.sandb
Install
npx skills add https://github.com/VincentChuWaiChow/vanguard-frontier-agentic/tree/master/skills/frontend/angular-template-sanitizer-security-review
claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install vincentchuwaichow-vanguard-frontier-agentic@llmmart
git clone https://github.com/VincentChuWaiChow/vanguard-frontier-agentic.git
The skills CLI installs just this skill, for any of its supported agents. Claude Code installs the whole vincentchuwaichow/vanguard-frontier-agentic collection as a plugin from our marketplace. Git is the plain clone.
Skill manifest
Angular Template Sanitizer Security Review
Purpose
Review Angular templates, components, and their data-flow for the documented injection classes Angular's own sanitizer architecture is built to catch, and that are only unsafe when application code deliberately or accidentally routes around it: DomSanitizer bypass calls (bypassSecurityTrustHtml, bypassSecurityTrustUrl, bypassSecurityTrustResourceUrl) fed by user-reachable input, unsanitized [innerHTML] bindings, and dynamically bound iframe security attributes such as [attr.sandbox] that Angular's own NG0910 check exists to reject. This skill exists so the review stays anchored to these documented, concrete sinks instead of drifting into a general "Angular code review" — it does not re-litigate change detection, signals architecture, or component design in every response.
When to use
Use this skill when the user asks to:
- review whether a
bypassSecurityTrustHtml,bypassSecurityTrustUrl, orbypassSecurityTrustResourceUrlcall is safe, - assess whether an
[innerHTML]binding is safe, - review an
<iframe>embed for a dynamically bound security attribute ([attr.sandbox],[sandbox],[attr.allow],[attr.credentialless]) or an NG0910 error, - perform a pre-launch security review of Angular templates that render user- or third-party-supplied content.
Do not use this skill for:
- Angular architecture review with no security angle (signals usage, change-detection strategy, component decomposition quality) — use
angular-architecture-signals-reviewinstead, - SSR/hydration-specific defects (
TransferStateleakage, hydration mismatches) — useangular-ssr-hydration-reviewinstead, - a bug that requires live traffic reproduction (a captured XSS payload in a running app, a browser-based exploit proof) to confirm exploitation — static analysis proves the structural risk, not that it has already been exploited in production.
Context7 Documentation Protocol
- Resolve the Angular library ID with
resolve-library-id(matched result:/angular/angular) before citing any sanitizer-mechanism or NG0910 claim. /angular/angularis Angular's own source-and-docs repository (high reputation, corroborated againstpackages/platform-browser/src/security/dom_sanitization_service.ts,packages/core/src/sanitization/html_sanitizer.ts,packages/core/src/render3/instructions/shared.ts, andadev/src/content/reference/errors/NG0910.md). Usequery-docsagainst it to confirm low-level sanitizer mechanics directly from source: thatbypassSecurityTrustHtml(and its URL/resource-URL siblings) mark a value trusted sosanitize()skips the HTML/URL sanitizer and returns the value unchanged, that property bindings like[innerHTML]accept a compiler-added sanitizer function that only risky properties receive, and that text interpolation instead callsrenderer.setValue()on a text node — a path that never parses HTML and needs no sanitizer.- Before flagging a
[attr.sandbox]/[sandbox]/[attr.allow]/[attr.credentialless]binding, confirm Angular's own NG0910 check: these attributes are documented as required to be static (fixed at element-creation time) because they configure the iframe's security model beforesrc/srcdocload — a dynamic binding either throws NG0910 in dev or, if that check is suppressed, lets a runtime value weaken the sandbox. - Read the component's imports first to confirm
DomSanitizer(from@angular/platform-browser) is actually in use before assuming a bypass call exists — do not assume a project uses the bypass APIs without confirming the import and call site. - If Context7 is unavailable, fall back to the
official_docsURLs in this skill'smetadata.jsonand label the claimdocumentation-based, unverified against current release.
Lean operating rules
- Injection findings default to HIGH severity. This is a security-scoped skill: do not downgrade an untraced
bypassSecurityTrustHtml/bypassSecurityTrustUrl/bypassSecurityTrustResourceUrlcall or an unsanitized[innerHTML]binding to MEDIUM just because it has not been observed exploited yet — the risk is in the structure, not in whether someone has already hit it. - Trace every finding to a concrete file:line and a concrete data-flow path. A finding that says "this bypass call might be unsafe" or "this innerHTML might be risky" without showing the specific origin (route param, query string, request body, or a third-party API response that itself echoes user input) and the specific sink is not a valid finding — it is a guess.
- Do not approve any
bypassSecurityTrustHtml,bypassSecurityTrustUrl, orbypassSecurityTrustResourceUrlcall whose input includes user-reachable data unless the trace shows the value was validated or sanitized on that exact path before the bypass call — the bypass APIs are intentional escape hatches from Angular's compiler-driven sanitization, not accidental gaps, so their mere presence is not evidence of prior review. - Do not approve an
[innerHTML]binding fed by user-reachable input unless a named sanitizer call (e.g.,DomSanitizer.sanitize(SecurityContext.HTML, ...), or a project-specific equivalent) is visibly present on that exact data-flow path. A sanitizer import existing elsewhere in the codebase does not clear this bar — trace the specific path under review. - Flag any
[attr.sandbox],[sandbox],[attr.allow], or[attr.credentialless]binding on an<iframe>as a finding regardless of whether NG0910 is currently thrown in the reviewed environment — a suppressed or bypassed dev-mode check does not make the underlying dynamic-security-attribute pattern safe in production. - Check dynamic
[href]/[src]bindings fed throughbypassSecurityTrustUrl/bypassSecurityTrustResourceUrlfor scheme validation (an allowlist rejectingjavascript:and other non-http(s)schemes) on the traced path before the bypass call — the bypass call itself performs no validation. - Never execute, build, or run application code, and never send live requests, as part of this review; this is a static-review skill (Read/Grep/Glob only).
- Load only the reference needed for the concern in scope.
References
Load these only when needed:
- Review workflow and findings contract — use for the step-by-step review procedure, the sanitizer-bypass/innerHTML/iframe decision tree, and the required output shape.
- DomSanitizer bypass calls and innerHTML — load only when the review scope includes a
bypassSecurityTrustHtml/bypassSecurityTrustUrl/bypassSecurityTrustResourceUrlcall or an[innerHTML]binding. Includes the OWASP XSS grounding reference; load that citation only when a finding is actually present. - Dynamic iframe security attributes — load only when the review scope includes an
<iframe>element with a boundsandbox,allow, orcredentiallessattribute, or a reported NG0910 error.
Response minimum
Return, at minimum:
- the component(s), template binding(s), and/or
DomSanitizercall site(s) in scope, - ranked findings with file:line evidence, defect category (
xss,url-injection, oriframe-sandbox-escape), the concrete data-flow trace (origin-to-sink path naming every hop), and a fix sketch matching Angular's documented pattern, - for every bypass call or
[innerHTML]finding, an explicit statement of whether validation or sanitization is present on the traced path — never approve on the assumption one exists elsewhere, - evidence level per finding (
repo evidence,documentation-based, orinference), with structural risk findings explicitly labeled as structural risk, not as confirmed-exploited, - verdict (approve / approve-with-notes / block),
- open questions or scope the review could not cover (e.g., "confirming actual exploitation requires a live payload test in a running browser session, not static review").
Files (vanguard-frontier-agentic)
-
references
-
iframe-security-attributes.md 4.9 KB
# Dynamic Iframe Security Attributes Use this reference only when the review scope includes an `<iframe>` element with a bound `sandbox`, `allow`, `credentialless`, `csp`, `referrerPolicy`, or `fetchPriority` attribute, or a reported NG0910 error. ## What people get wrong The naive assumption is: > "Angular throws NG0910 if I bind these attributes dynamically, so if my app runs without that error, my iframe binding must be fine." Wrong in two ways. First, the check can be suppressed or not exercised in the exact code path under review (a conditional branch not hit during development, or an older Angular version without the check). Second, even when the error is correctly thrown and "fixed" by refactoring around it, the underlying intent — a *dynamic*, potentially user-influenced sandbox/allow value — is still the actual security concern, independent of whether the specific Angular version enforces it at compile/runtime. ## Officially grounded rules Angular's own documentation (`documentation-based`, `adev/src/content/reference/errors/NG0910.md`, confirmed via Context7 `/angular/angular`) states directly: - **Angular throws NG0910 when it detects a binding on specific security-related `<iframe>` attributes**: `sandbox`, `allow`, `allowFullscreen`, `referrerPolicy`, `csp`, `fetchPriority`, or `credentialless`. These attributes configure the iframe's security model and must be applied before the `src`/`srcdoc` attributes load content, so Angular requires them to be static — their values fixed at element-creation time and never bound as a property (`[sandbox]="..."`) or attribute (`[attr.sandbox]="..."`) binding, including via a directive's host bindings. - **The recommended fix is a static attribute**, e.g. `sandbox="allow-scripts"`, or Angular's `@if`/`@switch` control-flow blocks to conditionally render entire `<iframe>` elements with different static attribute values, rather than binding the attribute's value dynamically on one persistent element. ## Non-negotiable design rules ### 1. Flag the pattern regardless of whether NG0910 currently fires A dynamically bound security-sensitive iframe attribute is the finding — not the NG0910 error message itself. If the error is suppressed (an older Angular version, a downgraded compiler check, or code that technically avoids triggering the exact check Angular implements) but the underlying dynamic-binding pattern is present, it is still a finding: the sandbox's actual value can still be influenced by whatever expression it is bound to. ### 2. Check reachability of the bound expression A `[attr.sandbox]` bound to a hardcoded, non-configurable constant expression evaluated once at compile time is a lower-severity finding (still worth fixing for forward-compatibility with future Angular checks) than one bound to a value that traces back to user-reachable input (a query parameter, a per-tenant config value editable by end users, or similar) — the latter is a HIGH finding because an attacker-influenced value can directly weaken the iframe sandbox. ### 3. Use static attributes or conditional rendering, not dynamic binding The correct fix is either a static attribute value or Angular's `@if`/`@switch` blocks rendering distinct `<iframe>` elements per case — not attempting to bind the attribute dynamically through a workaround (e.g., manual DOM manipulation via `ElementRef` to set the attribute outside Angular's binding system), which reintroduces the same risk outside Angular's own safety check. ## Minimal safe implementation pattern ```html <!-- Static attribute, fixed at element-creation time. --> <iframe sandbox="allow-scripts" [src]="trustedEmbedUrl"></iframe> ``` ```html <!-- Conditional rendering of distinct static configurations. --> @if (isTrustedPartner) { <iframe sandbox="allow-scripts allow-same-origin" [src]="trustedEmbedUrl"></iframe> } @else { <iframe sandbox="allow-scripts" [src]="trustedEmbedUrl"></iframe> } ``` Anti-pattern (dynamic binding — do not approve): ```html <!-- userSandbox may originate from a per-tenant config value; even if NG0910 is not currently thrown in this environment, the sandbox's effective value can be influenced by that input at runtime. --> <iframe [attr.sandbox]="userSandbox" [src]="trustedEmbedUrl"></iframe> ``` ## Verification targets - Grep `<iframe>` elements for `[sandbox]`, `[attr.sandbox]`, `[allow]`, `[attr.allow]`, `[credentialless]`, `[attr.credentialless]`, `[csp]`, `[attr.csp]`, `[referrerPolicy]`, `[attr.referrerPolicy]`, `[fetchPriority]`, and `[attr.fetchPriority]`. - For each match, trace the bound expression backward to determine whether it is a fixed compile-time constant or reachable from user-influenced input (query params, tenant config editable by end users, form state). - Grep for `ElementRef`-based manual attribute manipulation on iframe elements, which can reintroduce the same dynamic-binding risk outside Angular's compiler-enforced static-attribute check. -
sanitizer-bypass-and-innerhtml.md 8 KB
# DomSanitizer Bypass Calls and [innerHTML] Bindings Use this reference only when the review scope includes a `bypassSecurityTrustHtml`, `bypassSecurityTrustUrl`, or `bypassSecurityTrustResourceUrl` call, or an `[innerHTML]` binding. The OWASP XSS citation below is loaded only when a finding is actually present — do not cite it preemptively in a review that has no finding. ## What people get wrong The naive assumption is: > "I called `bypassSecurityTrustHtml`, so I must have already decided this content is safe — the method name itself is my proof of review." Wrong. The bypass method's name documents *intent* to skip sanitization, not that the argument was actually checked. The recurring real-world failure is a bypass call added to silence Angular's sanitizer error during development, with the "we'll add validation later" step never landing, or a bypass call whose argument source changes in a later refactor (a static string swapped for a computed value fed by an API response) without anyone re-reviewing the call site. ## Officially grounded rules Angular's own source (`repo evidence` via Context7 `/angular/angular`, `packages/platform-browser/src/security/dom_sanitization_service.ts`) confirms the mechanism directly: - **`bypassSecurityTrustHtml()` disables Angular's XSS sanitization for the value it wraps.** It marks a string as trusted `SafeHtml`, which causes `sanitize()` to skip the HTML sanitizer entirely and return the value as-is. `bypassSecurityTrustUrl()` and `bypassSecurityTrustResourceUrl()` do the equivalent for URL and resource-URL contexts. - **Property bindings like `[innerHTML]` accept a compiler-added sanitizer function.** `setDomProperty()` (in `packages/core/src/render3/instructions/shared.ts`) only calls a sanitizer when one is present — "it is assumed that the sanitizer is only added when the compiler determines that the property is risky." Without a sanitizer function reaching that call (which happens whenever a `Safe*` value from a bypass call is passed, since `sanitize()` unwraps it unchanged), the raw value is set directly via `renderer.setProperty()`. - **Text interpolation is a structurally different, safer path.** `updateTextNode()` calls `renderer.setValue()` on a text node — a text node never parses HTML, so interpolated content cannot execute as markup or script regardless of its contents. This is why interpolation needs no sanitizer at all, and why it is the default recommendation whenever raw HTML rendering is not actually required. - **`_sanitizeHtml()` (`packages/core/src/sanitization/html_sanitizer.ts`) is the actual sanitizer** invoked when no bypass has occurred: it parses the HTML into an inert DOM tree, strips disallowed elements/attributes against an allowlist, and repeats parsing to catch mutation-XSS (mXSS) auto-correction attacks. This is the protection a bypass call routes around entirely. ## Non-negotiable design rules ### 1. Trace the full origin-to-sink path before judging a bypass call or [innerHTML] binding Do not evaluate `sanitizer.bypassSecurityTrustHtml(someVar)` or `[innerHTML]="someVar"` in isolation. Follow `someVar` backward: is it a literal string in the component? An `@Input()`? A value derived from a service call? An API response that itself echoes content any user (not necessarily the current one) previously submitted? The finding depends on where that trace terminates, not on the call/binding syntax alone. ### 2. The bypass call's existence is not evidence the argument was validated A `bypassSecurityTrustHtml`/`bypassSecurityTrustUrl`/`bypassSecurityTrustResourceUrl` call is an intentional escape hatch by design — its presence proves a developer wanted to skip sanitization, not that they checked the value first. Only a validation or sanitization step visibly present *before* the bypass call on that exact path clears the finding. ### 3. A sanitizer call elsewhere in the codebase does not clear a specific [innerHTML] finding If the trace reveals user-reachable input reaching an `[innerHTML]` binding, the only thing that clears the finding is a named sanitizer call (e.g., `DomSanitizer.sanitize(SecurityContext.HTML, ...)`, or a project-specific equivalent such as DOMPurify) visibly present on that exact path. "This codebase has a sanitize utility used elsewhere" is not evidence the specific path under review calls it. ### 4. Third-party API responses are not automatically trusted An API response is not "safe by default" just because it did not come directly from the current request's form input. If the API itself stores and echoes content that any user previously submitted (a comment system, a CMS with contributor accounts, a product-review feed), that response is user-reachable input for this review's purposes. ### 5. URL-context bypasses need scheme validation, not HTML sanitization `bypassSecurityTrustUrl`/`bypassSecurityTrustResourceUrl` are a distinct injection surface from `bypassSecurityTrustHtml` — do not conflate the fixes. The correct control before a URL-context bypass is scheme validation (an allowlist accepting only `http:`/`https:`/`mailto:` as appropriate, rejecting `javascript:` and other schemes), not HTML sanitization. ## Minimal safe implementation patterns ```ts import { Component, Input } from '@angular/core'; @Component({ selector: 'app-comment', // Text interpolation never sets innerHTML and needs no sanitizer. template: `<div>{{ userComment }}</div>`, }) export class CommentComponent { @Input() userComment = ''; } ``` ```html <!-- A named sanitizer call sits directly on the path between the untrusted field and the binding. --> <div [innerHTML]="sanitizer.sanitize(userBio)"></div> ``` Anti-pattern (untraced bypass call — do not approve): ```ts // userComment comes from a profile API that echoes user-submitted text. // No validation anywhere between the API response and this bypass call. this.trustedComment = this.sanitizer.bypassSecurityTrustHtml(this.userComment); ``` ## Adversarial checklist Before clearing a bypass call or `[innerHTML]` binding, answer these: - What is the literal origin of the bound value — a template literal, an `@Input()`, a service call result, or an API response? - Does any point along that trace involve content any user (current or otherwise) previously submitted? - Is there a named sanitizer or validation call visible on the exact path traced, or only "we sanitize somewhere in this codebase"? - Could a later code change (a refactor that swaps the data source, or a new field added to an existing API response) reach this same call or binding without re-triggering a security review? If any answer is unclear or reveals a gap, the finding is HIGH — do not soften it to "worth double-checking." ## OWASP grounding (load only when a finding is present) Cross-Site Scripting (XSS) is the general vulnerability class that an unvalidated bypass call or unsanitized `[innerHTML]` binding produces: an attacker-controlled or attacker-influenced string is rendered as live HTML/script in another user's browser session. The OWASP XSS reference and OWASP Top Ten (both listed in this skill's `official_docs`) provide the vendor-neutral grounding for why this defect class is treated as HIGH severity by default — it typically enables session/token theft, credential harvesting via injected forms, or full account takeover in the victim's authenticated context. Cite these only in the specific finding write-up for a confirmed or suspected defect, not as boilerplate in every review. ## Verification targets - Grep component and template source for `bypassSecurityTrustHtml`, `bypassSecurityTrustUrl`, `bypassSecurityTrustResourceUrl`, `bypassSecurityTrustScript`, and `bypassSecurityTrustStyle`. - Grep templates for `[innerHTML]` and enumerate every match. - For each match, grep backward through the component's `@Input()`s, service injections, and any imported store/composable for the value's origin. - Grep for a `DomSanitizer.sanitize(` call (or an equivalent project-specific sanitizer utility) and confirm its call site is on the traced path, not merely present in the file or module. -
workflow-and-output.md 5.6 KB
# Review Workflow and Findings Contract Use this reference for the step-by-step review procedure and the required output shape. Load the other two references only for the specific defect class the component or template under review actually raises. ## Prerequisites - Read the component's imports to confirm whether `DomSanitizer` (from `@angular/platform-browser`) is in use. Do not assume a bypass call exists without confirming the import and the call site. - Identify the Angular major version in use (`package.json` — `@angular/core`) — sanitizer internals and the NG0910 check are current-Angular behavior; note explicitly if reviewing a much older major where behavior may differ, and label the claim accordingly. ## Workflow 1. **Locate every `DomSanitizer` bypass call.** Grep for `bypassSecurityTrustHtml`, `bypassSecurityTrustUrl`, `bypassSecurityTrustResourceUrl`, `bypassSecurityTrustScript`, and `bypassSecurityTrustStyle`. For each, trace the argument backward through props/`@Input()`s, computed getters, service calls, and API responses to its origin. 2. **Locate every `[innerHTML]` binding.** For each, trace its bound expression the same way. Determine whether the origin includes user-reachable input (route params, query strings, request bodies, or a third-party API response that itself echoes user input) and whether a named sanitizer call (`DomSanitizer.sanitize(SecurityContext.HTML, ...)` or an equivalent) sits on that exact path. 3. **Locate every dynamically bound iframe security attribute.** Grep for `[attr.sandbox]`, `[sandbox]`, `[attr.allow]`, `[allow]`, `[attr.credentialless]`, `[credentialless]`, `[attr.csp]`, `[attr.referrerPolicy]`, and `[attr.fetchPriority]` on `<iframe>` elements (including via a directive's host bindings). See `references/iframe-security-attributes.md` for the decision tree. 4. **Locate every dynamic `[href]`/`[src]` binding fed by `bypassSecurityTrustUrl`/`bypassSecurityTrustResourceUrl`.** Check for scheme validation (an allowlist rejecting `javascript:` and other non-`http(s)` schemes) on the path before the bypass call. 5. **Produce ranked findings** using the output contract below. ## Decision tree - A bypass call's traced argument includes user-reachable input and no validation/sanitization occurs on that exact path before the call → **HIGH** finding, XSS or URL-injection depending on the bypass method. Do not accept "we validate elsewhere" — the trace must show the check on the specific path reviewed. - A bypass call's traced argument is fully origin-controlled with no user-reachable input anywhere in the trace (e.g., a static, developer-authored HTML fragment with no user-submission path) → not a finding, but state this explicitly in the output rather than silently omitting the call site. - An `[innerHTML]` binding's traced source includes user-reachable input and no sanitizer call is present on that exact path → **HIGH** finding, XSS. - An `[innerHTML]` binding's traced source is fully origin-controlled → not a finding, stated explicitly. - Any security-sensitive iframe attribute (`sandbox`, `allow`, `allowFullscreen`, `referrerPolicy`, `csp`, `fetchPriority`, `credentialless`) is bound dynamically (property or `attr.` binding) rather than set as a static attribute → **MEDIUM-to-HIGH** finding depending on whether the bound value can be influenced by user-reachable input, regardless of whether NG0910 is currently thrown in the environment reviewed. - A dynamic `[href]`/`[src]` fed through a bypass call has no scheme allowlist on the path before the bypass → **MEDIUM-to-HIGH** finding depending on reachability (public unauthenticated surface vs. requiring an authenticated session to trigger). ## Output contract Every response from this skill must return: 1. **Scope** — the component(s), template binding(s), and/or `DomSanitizer` call site(s) reviewed. 2. **Ranked findings** — each with file:line, defect category (`xss`, `url-injection`, or `iframe-sandbox-escape`), the concrete data-flow trace naming every hop from origin to sink, and a fix sketch matching Angular's documented pattern. 3. **Validation/sanitizer status per finding** — an explicit statement of whether validation or sanitization is present on the traced path; never infer one exists. 4. **Evidence level per finding** — `repo evidence`, `documentation-based`, or `inference`. Label structural risk findings as structural risk explicitly — do not imply confirmed exploitation without live evidence. 5. **Verdict** — approve / approve-with-notes / block. 6. **Open questions or out-of-scope items** — e.g., "confirming actual exploitation requires a live payload test in a running browser session, not static review," or "hydration-mismatch risk in this same file is out of scope — recommend `angular-ssr-hydration-review` if relevant." ## When to push back Push back if the user asks to: - approve a bypass call because "we validate elsewhere in the app" without a validation/sanitizer call visible on the specific traced path — that is not evidence, it is an assumption, - treat a bound `[attr.sandbox]`/`[sandbox]` as acceptable because "NG0910 didn't fire in our environment" — a suppressed or unhit dev-mode check does not make the dynamic-binding pattern safe in production, - downgrade an untraced `[innerHTML]` finding to informational because "it's probably fine" — this skill's default is HIGH for exactly this class of unproven claim, - skip the review because "DomSanitizer bypass calls are always intentional, so they must already be safe" — the bypass APIs are intentional escape hatches from sanitization, not proof the argument was validated before the call.
-
-
metadata.json 1.6 KB
{ "id": "angular-template-sanitizer-security-review", "name": "Angular Template Sanitizer Security Review", "type": "skill", "provider": "frontend", "harnesses": [ "claude-code", "cursor", "codex", "gemini", "kiro", "other" ], "summary": "Reviews Angular templates and components for injection via DomSanitizer bypass calls (bypassSecurityTrustHtml, bypassSecurityTrustUrl, bypassSecurityTrustResourceUrl), unsanitized [innerHTML] bindings, and dynamically bound iframe security attributes such as [attr.sandbox], grounding claims via Context7 and Angular's own sanitizer and NG0910 documentation.", "source_type": "original", "official_docs": [ "https://angular.dev/best-practices/security", "https://angular.dev/errors/NG0910", "https://owasp.org/www-project-top-ten/", "https://owasp.org/www-community/attacks/xss/" ], "security_notes": "This skill's entire scope is security-critical: DomSanitizer bypass calls and unsanitized [innerHTML] bindings are XSS vectors, and dynamically bound iframe security attributes are a sandbox-escape vector Angular's own NG0910 check exists to reject. Every finding defaults to HIGH severity unless proven otherwise with concrete validation/sanitizer evidence on the traced path. Static-review-only skill: it reads and greps components and templates but never executes, builds, or runs application code, and never sends live requests.", "last_verified": "2026-07-03", "path": "skills/frontend/angular-template-sanitizer-security-review", "author": "github: VincentChuWaiChow", "version": "0.1.0" } -
SKILL.md 8.4 KB
--- name: angular-template-sanitizer-security-review description: Statically review Angular templates and components for injection via DomSanitizer bypass calls (bypassSecurityTrustHtml, bypassSecurityTrustUrl, bypassSecurityTrustResourceUrl), unsanitized [innerHTML] bindings, and dynamically bound iframe security attributes such as [attr.sandbox], grounded in Angular's own sanitizer and NG0910 documentation. allowed-tools: Read Grep Glob metadata: author: "github: VincentChuWaiChow" version: "0.1.0" updated: "2026-07-03" category: security --- # Angular Template Sanitizer Security Review ## Purpose Review Angular templates, components, and their data-flow for the documented injection classes Angular's own sanitizer architecture is built to catch, and that are only unsafe when application code deliberately or accidentally routes around it: `DomSanitizer` bypass calls (`bypassSecurityTrustHtml`, `bypassSecurityTrustUrl`, `bypassSecurityTrustResourceUrl`) fed by user-reachable input, unsanitized `[innerHTML]` bindings, and dynamically bound iframe security attributes such as `[attr.sandbox]` that Angular's own NG0910 check exists to reject. This skill exists so the review stays anchored to these documented, concrete sinks instead of drifting into a general "Angular code review" — it does not re-litigate change detection, signals architecture, or component design in every response. ## When to use Use this skill when the user asks to: - review whether a `bypassSecurityTrustHtml`, `bypassSecurityTrustUrl`, or `bypassSecurityTrustResourceUrl` call is safe, - assess whether an `[innerHTML]` binding is safe, - review an `<iframe>` embed for a dynamically bound security attribute (`[attr.sandbox]`, `[sandbox]`, `[attr.allow]`, `[attr.credentialless]`) or an NG0910 error, - perform a pre-launch security review of Angular templates that render user- or third-party-supplied content. Do not use this skill for: - Angular architecture review with no security angle (signals usage, change-detection strategy, component decomposition quality) — use `angular-architecture-signals-review` instead, - SSR/hydration-specific defects (`TransferState` leakage, hydration mismatches) — use `angular-ssr-hydration-review` instead, - a bug that requires live traffic reproduction (a captured XSS payload in a running app, a browser-based exploit proof) to confirm exploitation — static analysis proves the structural risk, not that it has already been exploited in production. ## Context7 Documentation Protocol - Resolve the Angular library ID with `resolve-library-id` (matched result: `/angular/angular`) before citing any sanitizer-mechanism or NG0910 claim. - `/angular/angular` is Angular's own source-and-docs repository (high reputation, corroborated against `packages/platform-browser/src/security/dom_sanitization_service.ts`, `packages/core/src/sanitization/html_sanitizer.ts`, `packages/core/src/render3/instructions/shared.ts`, and `adev/src/content/reference/errors/NG0910.md`). Use `query-docs` against it to confirm low-level sanitizer mechanics directly from source: that `bypassSecurityTrustHtml` (and its URL/resource-URL siblings) mark a value trusted so `sanitize()` skips the HTML/URL sanitizer and returns the value unchanged, that property bindings like `[innerHTML]` accept a compiler-added sanitizer function that only risky properties receive, and that text interpolation instead calls `renderer.setValue()` on a text node — a path that never parses HTML and needs no sanitizer. - Before flagging a `[attr.sandbox]`/`[sandbox]`/`[attr.allow]`/`[attr.credentialless]` binding, confirm Angular's own NG0910 check: these attributes are documented as required to be static (fixed at element-creation time) because they configure the iframe's security model before `src`/`srcdoc` load — a dynamic binding either throws NG0910 in dev or, if that check is suppressed, lets a runtime value weaken the sandbox. - Read the component's imports first to confirm `DomSanitizer` (from `@angular/platform-browser`) is actually in use before assuming a bypass call exists — do not assume a project uses the bypass APIs without confirming the import and call site. - If Context7 is unavailable, fall back to the `official_docs` URLs in this skill's `metadata.json` and label the claim `documentation-based, unverified against current release`. ## Lean operating rules - Injection findings default to HIGH severity. This is a security-scoped skill: do not downgrade an untraced `bypassSecurityTrustHtml`/`bypassSecurityTrustUrl`/`bypassSecurityTrustResourceUrl` call or an unsanitized `[innerHTML]` binding to MEDIUM just because it has not been observed exploited yet — the risk is in the structure, not in whether someone has already hit it. - Trace every finding to a concrete file:line and a concrete data-flow path. A finding that says "this bypass call might be unsafe" or "this innerHTML might be risky" without showing the specific origin (route param, query string, request body, or a third-party API response that itself echoes user input) and the specific sink is not a valid finding — it is a guess. - Do not approve any `bypassSecurityTrustHtml`, `bypassSecurityTrustUrl`, or `bypassSecurityTrustResourceUrl` call whose input includes user-reachable data unless the trace shows the value was validated or sanitized on that exact path before the bypass call — the bypass APIs are intentional escape hatches from Angular's compiler-driven sanitization, not accidental gaps, so their mere presence is not evidence of prior review. - Do not approve an `[innerHTML]` binding fed by user-reachable input unless a named sanitizer call (e.g., `DomSanitizer.sanitize(SecurityContext.HTML, ...)`, or a project-specific equivalent) is visibly present on that exact data-flow path. A sanitizer import existing elsewhere in the codebase does not clear this bar — trace the specific path under review. - Flag any `[attr.sandbox]`, `[sandbox]`, `[attr.allow]`, or `[attr.credentialless]` binding on an `<iframe>` as a finding regardless of whether NG0910 is currently thrown in the reviewed environment — a suppressed or bypassed dev-mode check does not make the underlying dynamic-security-attribute pattern safe in production. - Check dynamic `[href]`/`[src]` bindings fed through `bypassSecurityTrustUrl`/`bypassSecurityTrustResourceUrl` for scheme validation (an allowlist rejecting `javascript:` and other non-`http(s)` schemes) on the traced path before the bypass call — the bypass call itself performs no validation. - Never execute, build, or run application code, and never send live requests, as part of this review; this is a static-review skill (Read/Grep/Glob only). - Load only the reference needed for the concern in scope. ## References Load these only when needed: - [Review workflow and findings contract](references/workflow-and-output.md) — use for the step-by-step review procedure, the sanitizer-bypass/innerHTML/iframe decision tree, and the required output shape. - [DomSanitizer bypass calls and innerHTML](references/sanitizer-bypass-and-innerhtml.md) — load only when the review scope includes a `bypassSecurityTrustHtml`/`bypassSecurityTrustUrl`/`bypassSecurityTrustResourceUrl` call or an `[innerHTML]` binding. Includes the OWASP XSS grounding reference; load that citation only when a finding is actually present. - [Dynamic iframe security attributes](references/iframe-security-attributes.md) — load only when the review scope includes an `<iframe>` element with a bound `sandbox`, `allow`, or `credentialless` attribute, or a reported NG0910 error. ## Response minimum Return, at minimum: - the component(s), template binding(s), and/or `DomSanitizer` call site(s) in scope, - ranked findings with file:line evidence, defect category (`xss`, `url-injection`, or `iframe-sandbox-escape`), the concrete data-flow trace (origin-to-sink path naming every hop), and a fix sketch matching Angular's documented pattern, - for every bypass call or `[innerHTML]` finding, an explicit statement of whether validation or sanitization is present on the traced path — never approve on the assumption one exists elsewhere, - evidence level per finding (`repo evidence`, `documentation-based`, or `inference`), with structural risk findings explicitly labeled as structural risk, not as confirmed-exploited, - verdict (approve / approve-with-notes / block), - open questions or scope the review could not cover (e.g., "confirming actual exploitation requires a live payload test in a running browser session, not static review").
Comments (0)
Sign in to join the conversation.
Reviews (0)
No reviews yet.
No comments yet.