Security rules

NGB010: Overly permissive iframe

Inspects iframes declared in Angular templates, in index.html, and created with document.createElement("iframe").

Property Value
Rule ID NGB010
Category iframe & cross-window communication
Default severity medium
CWE CWE-1021, CWE-250
Built-in presets recommended: warn, strict: error

Confidence is reported per finding (high, medium, low) and is independent of severity. See Reading findings.

What it checks

Inspects iframes declared in Angular templates, in index.html, and created with document.createElement("iframe"). Reports sandboxes that combine allow-scripts with allow-same-origin, sandboxes that let dynamic content escape (allow-top-navigation, allow-popups-to-escape-sandbox), powerful permission delegation (allow="camera; microphone; payment …" or *) to dynamically chosen sources, and — with low confidence — unsandboxed iframes whose src is bound to a dynamic value.

Why it matters

An iframe inherits nothing by default, but allow delegates powerful browser features, and an ineffective sandbox gives untrusted framed content script access. With both allow-scripts and allow-same-origin, same-origin content can simply remove the sandbox attribute from its own frame.

Detection behavior and supported patterns

  • Template elements <iframe sandbox="…" allow="…" [src]="…"> (inline and external templates)
  • index.html iframes (static attributes)
  • const f = document.createElement("iframe") with f.sandbox = … / f.setAttribute("sandbox" | "allow", …) / f.allow = … / f.src = …
  • A static, constant src without sandbox is NOT reported; dynamic [src] without sandbox is reported with low confidence

Example

TypeScript
<iframe [src]="widgetUrl" sandbox="allow-scripts allow-same-origin" allow="camera; microphone"></iframe>

Safer alternative

TypeScript
<iframe [src]="widgetUrl" sandbox="allow-scripts" allow="camera https://video.example.com"></iframe>

Remediation

Use the narrowest sandbox that works (start from sandbox="" and add tokens) and never combine allow-scripts with allow-same-origin for content you do not fully control. Delegate powerful features only to fixed, trusted origins (allow="payment https://pay.example.com").

False-positive considerations

  • Trusted first-party content embedded from a dynamic but allowlisted URL is reported with low confidence when unsandboxed.

Known limitations

  • Dynamic [attr.sandbox] / [sandbox] bindings cannot be assessed and produce an informational diagnostic instead of a finding.
  • Whether the framed content is trusted is not known statically; only the shape of the configuration is assessed.
  • Iframes created via Renderer2.createElement or third-party components are not covered.

References

Run it

Shell
ngbastion explain NGB010