<!-- Copyright (c) 2026 defconxt. All rights reserved. -->
<!-- Licensed under AGPL-3.0 — see LICENSE file for details. -->
<!-- NERF is a trademark of defconxt. -->
---
name: implementing-trusted-types
description: >-
  Implement Trusted Types API to prevent DOM-based XSS by enforcing type-safe assignments to dangerous DOM sinks like innerHTML, document.write, and eval.
domain: cybersecurity
subdomain: browser-security
tags:
  - trusted-types
  - dom-xss
  - csp
  - type-safety
version: "1.0"
author: defconxt
license: AGPL-3.0
metadata:
  mitre-attack: ["T1059.007"]
  frameworks: ["OWASP", "W3C"]
  tools: ["devtools", "semgrep", "csp-evaluator"]
---

# Implementing Trusted Types

## Overview

Implement Trusted Types API to prevent DOM-based XSS by enforcing type-safe assignments to dangerous DOM sinks like innerHTML, document.write, and eval.

## Prerequisites

| Tool / Requirement | Details |
|---|---|
| `devtools` | Security tooling |
| `semgrep` | Security tooling |
| `csp-evaluator` | Security tooling |
| CSP with trusted-types directive, JavaScript refactoring capability | Environment requirement |

## Quick Reference

```bash
# Quick start commands
node scripts/agent.js --help
semgrep --config p/trusted-types ./src
```

## Workflow

### Step 1: Audit DOM Sinks

```bash
semgrep --config p/trusted-types ./src
```

### Step 2: Enable Report-Only Mode

```bash
node scripts/agent.js deploy --url https://target.com --mode report-only
```

### Step 3: Create Trusted Type Policies

```bash
node scripts/agent.js generate --url https://target.com --policy default
```

## Detection

```yaml
title: Trusted Types Detection
id: c3518ac1-3ac5-4352-8cf2-a4ac6f3abe79
status: experimental
description: Detects suspicious activity related to implementing trusted types techniques in browser security context
logsource:
  category: proxy
  product: windows
detection:
  selection:
    cs_uri_query: "*script*"
  condition: selection
level: medium
tags:
  - attack.t1059.007
  - attack.initial_access
falsepositives:
  - Browser security extensions performing routine URL reputation checks
```


**Detection Opportunities**

| Indicator | Source | Detection Logic |
|---|---|---|
| Trusted Types Detection | windows/proxy | Sigma rule (medium) |
| ATT&CK Coverage | MITRE ATT&CK | T1059.007 |

## Verification

- **Verify TT deployment**: `node scripts/agent.js verify --url https://target.com`
- **Confirm sink coverage**: `node scripts/agent.js audit --url https://target.com`

## References

- MITRE ATT&CK: T1059.007
- Frameworks: OWASP, W3C
- Tools: devtools, semgrep, csp-evaluator
