Skip to content

docs: add security and sanitization reference to developer skill - #70134

Open
aminesbdev wants to merge 2 commits into
angular:mainfrom
aminesbdev:docs/add-security-skill
Open

docs: add security and sanitization reference to developer skill#70134
aminesbdev wants to merge 2 commits into
angular:mainfrom
aminesbdev:docs/add-security-skill

Conversation

@aminesbdev

Copy link
Copy Markdown
Contributor

Adds a new reference file for context-based sanitization, bypassing security with DomSanitizer, the Safe Pipe pattern, and Trusted Types to the developer skill.

@pullapprove
pullapprove Bot requested a review from kirjs August 9, 2026 11:19
@angular-robot angular-robot Bot added the area: docs Related to the documentation label Aug 9, 2026
@ngbot ngbot Bot added this to the Backlog milestone Aug 9, 2026
@aminesbdev
aminesbdev force-pushed the docs/add-security-skill branch from 11eaa61 to c1ff3df Compare August 13, 2026 12:01
Comment on lines +56 to +58
## The Safe Pipe Pattern

To avoid repeating `DomSanitizer` calls in TypeScript components, use a **standalone pipe** to bypass security directly within templates.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we've recommended this pattern.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, even the name wouldn't be right; I wouldn't call it safeHTML because it doesn't sanitize, it just bypasses it.

@Pipe({
  name: 'safeHtml',
  standalone: true,
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps recommending DomPurify as a alternative?

@JeanMeche

Copy link
Copy Markdown
Member

I would need to see some metrics on what this skill would actually brings.

@aminesbdev
aminesbdev force-pushed the docs/add-security-skill branch from 51916dc to 554b134 Compare August 18, 2026 16:50
@aminesbdev

Copy link
Copy Markdown
Contributor Author

I would need to see some metrics on what this skill would actually brings.

@JeanMeche Thanks for the feedback — totally fair ask. Here are the metrics from a local benchmark I ran.

Methodology

I built a lightweight eval harness (inspired by skillgrade) that tests agents with and without this security skill on two tasks:

Task Anti-Pattern Expected Fix
fix-unsafe-bypass Raw input passed directly to bypassSecurityTrustHtml() Pre-sanitize with DOMPurify.sanitize() + memoize with computed()
fix-dom-manipulation Direct ElementRef.nativeElement.innerHTML = assignment Migrate to [innerHTML] template binding (Angular auto-sanitizes)

Setup:

  • 3 models tested: gpt-4o-mini, gpt-4o, gpt-5.6-sol (reasoning)
  • 5 trials per condition (with/without skill)
  • 5 deterministic static checks per task (no LLM-as-judge, fully reproducible)
  • OpenAI Chat Completions API, temperature=0.2

Results

01-header

Task 1: fix-unsafe-bypass

02-comparison
Model Without Skill With Skill Δ computed() pass rate
gpt-4o-mini 80% 100% +20% 0% → 100%
gpt-4o 88% 100% +12% 40% → 100%
gpt-5.6-sol 🧠 100% 100% 0% 100% → 100%

Task 2: fix-dom-manipulation

All 3 models score 100% with and without skill — this task is already well-understood by current LLMs, confirming the skill targets only patterns agents don't know.

Per-Check Breakdown

03-checks

The check that differentiates: uses-computed. Without the skill, models use plain arrow functions or methods instead of Angular's computed() signal to memoize the sanitized value — causing unnecessary re-sanitization on every change detection cycle.

Key Finding

04-insight

The skill lets gpt-4o-mini (cheapest model) match the output quality of gpt-5.6-sol (most expensive reasoning model). Without it, standard models consistently miss the computed() signal pattern — a best practice that only reasoning-tier models infer on their own.

The skill doesn't help where it's not needed (task 2 has 100% baseline), and it provides measurable lift exactly where agents struggle (task 1's DomPurify + computed pattern). Zero regression on any model.

Happy to run with more trials or different models if needed.

@@ -0,0 +1,109 @@
# Security and Sanitization

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the title is too broad in general, and the file name is too; if we're talking about security, the topic is much broader.

Example

We could mention HTTP level vulnerabilities, SSR with SSRF, among others mentioned in

https://angular.dev/best-practices/security

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An initial step could be to focus solely on general sanitization, as explained in the file.

@aminesbdev aminesbdev Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I agreed that 'security' is too broad a title for a file that only covers the sanitization pipeline. I've renamed the file to sanitization.md and updated the title to HTML Sanitization. I've also added a scope notice at the top of the file explicitly pointing readers to angular.dev/best-practices/security for HTTP-level vulnerabilities (CSRF, SSRF), CSP, authentication, and the rest of the Angular security model.

@aminesbdev aminesbdev Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly the approach I took, the file is now scoped strictly to sanitization (the [innerHTML] pipeline, DomSanitizer, DOMPurify, and Trusted Types). The rename to sanitization.md and the updated scope notice make that boundary explicit.

@aminesbdev
aminesbdev force-pushed the docs/add-security-skill branch from 554b134 to a85ebc3 Compare August 19, 2026 04:31
@aminesbdev
aminesbdev requested a review from SkyZeroZx August 19, 2026 04:33
private readonly sanitizer = inject(DomSanitizer);
readonly videoId = input.required<string>();

// Use a computed signal to safely derive the resource URL

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not correct, we could not guarantee it, I think we could rephrase it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! I've removed the word 'safely' from the comment to make it clear that the computed pattern itself does not guarantee safety, and added a reminder that the input must be strictly validated before bypassing security. Fixed and pushed.

@aminesbdev
aminesbdev force-pushed the docs/add-security-skill branch from a85ebc3 to 4ee9792 Compare August 19, 2026 05:58
@aminesbdev
aminesbdev requested a review from SkyZeroZx August 19, 2026 05:59
Comment thread skills/dev-skills/angular-developer/references/sanitization.md Outdated
Co-authored-by: Jaime Burgos <73321943+SkyZeroZx@users.noreply.github.com>
@aminesbdev
aminesbdev requested a review from SkyZeroZx August 19, 2026 15:29
@@ -0,0 +1,111 @@
# HTML Sanitization

> **Scope**: This reference covers Angular's built-in HTML sanitization pipeline and patterns for rendering untrusted HTML safely. It does **not** cover the full Angular security model.

@SkyZeroZx SkyZeroZx Aug 19, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not cover the full Angular security model.
For HTTP-level vulnerabilities (CSRF, SSRF), authentication, Content Security Policy, and other security topics, refer to the Angular Security Guide.

I also wonder if this is necessary considering the file is called "sanitization" and we're primarily talking about HTML. I'm not sure if it will contribute much or not. Let's see what others say.

And it also feels somewhat repeated regarding SKILL.md that says

When rendering dynamic or untrusted HTML content, consult the sanitization reference. For the full Angular security model (CSRF, SSRF, HTTP-level vulnerabilities, CSP), refer to the Angular Security Guide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: docs Related to the documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants