You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 10c5a06
Browse filesBrowse the repository at this point in the historyBrowse files
docs: fix NG05201 error page trigger and add it to the overview
The NG05201 page said the error is thrown when binding an untrusted value
to a resource URL attribute such as `<iframe [src]>`, but template and
host bindings are checked by core and throw NG0904. NG05201 only comes
from calling `DomSanitizer.sanitize()` with `SecurityContext.RESOURCE_URL`.
Rewrite the page around the direct `sanitize()` call, link to NG0904 for
bindings, align its structure with the NG0904 page, and add NG05201 to
the errors overview.
Angular throws this error when you bind a value to an attribute that loads an external resource — like `<iframe src>`, or `<link href>` — and that value hasn't been explicitly marked as trusted.
3
+
Angular throws this error, with the message `unsafe value used in a resource URL context`, when `DomSanitizer.sanitize()` is called with `SecurityContext.RESOURCE_URL`and a value that hasn't been explicitly marked as trusted.
4
4
5
-
Resource URLs are treated differently from regular URLs. Angular can sanitize a plain URL (stripping `javascript:` schemes and so on), but it can't make an arbitrary resource URL safe because these attributescause the browser to fetch and execute external content. So Angular rejects untrusted values rather than trying to sanitize them.
5
+
Resource URLs are treated differently from regular URLs. Angular can sanitize a plain URL, but it can't make an arbitrary resource URL safe because resource URL attributes, like `<iframe src>` or `<link href>`, cause the browser to fetch and execute external content. So `sanitize()` rejects untrusted values rather than trying to sanitize them.
6
6
7
-
The attributes that trigger this check are:
8
-
9
-
| Element | Attribute(s) |
10
-
| ---------- | ------------------ |
11
-
|`<base>`|`href`|
12
-
|`<embed>`|`src`|
13
-
|`<frame>`|`src`|
14
-
|`<iframe>`|`src`|
15
-
|`<link>`|`href`|
16
-
|`<object>`|`codebase`, `data`|
7
+
Binding an untrusted value to one of these attributes in a template or host binding throws [NG0904](errors/NG0904) instead.
17
8
18
9
## Debugging the error
19
10
20
-
This error can also be thrown when calling `DomSanitizer.sanitize()` directly with `SecurityContext.RESOURCE_URL` and a plain string:
`sanitize()` cannot make an arbitrary string safe in a resource URL context. Either use `bypassSecurityTrustResourceUrl` if the value is fully under your control, or bind the value to a regular URL attribute that Angular can sanitize.
27
-
28
-
Look for a binding to one of the attributes above or a direct `sanitize()` call:
11
+
Look for a `sanitize()` call that uses `SecurityContext.RESOURCE_URL`. The error is thrown for any plain string, even a static-looking URL:
CRITICAL: `bypassSecurityTrustResourceUrl` is an escape hatch, not a sanitizer. Never pass user-supplied URLs through it — that would allow an attacker to load arbitrary content, including malicious scripts. Only use it when the value is fully under your control.
52
41
53
-
`bypassSecurityTrustResourceUrl` is an escape hatch, not a sanitizer. Never pass user-supplied URLs through it — that would allow an attacker to load arbitrary content, including malicious scripts. Only use it when the value is fully under your control.
42
+
For more information, see the [Security guide](best-practices/security#trusting-safe-values).
0 commit comments