search

goog.html.SafeUrl

Provided By
All Implemented Interfaces

A string that is safe to use in URL context in DOM APIs and HTML documents.

A SafeUrl is a string-like object that carries the security type contract that its value as a string will not cause untrusted script execution when evaluated as a hyperlink URL in a browser.

Values of this type are guaranteed to be safe to use in URL/hyperlink contexts, such as assignment to URL-valued DOM properties, in the sense that the use will not result in a Cross-Site-Scripting vulnerability. Similarly, SafeUrls can be interpolated into the URL context of an HTML template (e.g., inside a href attribute). However, appropriate HTML-escaping must still be applied.

Note that, as documented in goog.html.SafeUrl.unwrap, this type's contract does not guarantee that instances are safe to interpolate into HTML without appropriate escaping.

Note also that this type's contract does not imply any guarantees regarding the resource the URL refers to. In particular, SafeUrls are not safe to use in a context where the referred-to resource is interpreted as trusted code, e.g., as the src of a script tag.

Instances of this type must be created via the factory methods (goog.html.SafeUrl.fromConstant, goog.html.SafeUrl.sanitize), etc and not by invoking its constructor. The constructor intentionally takes an extra parameter that cannot be constructed outside of this file and the type is immutable; hence only a default instance corresponding to the empty string can be obtained via constructor invocation.

new SafeUrl( value, token )

Parameters
valuestring
tokenObject

package-internal implementation detail.

See Also

goog.html.SafeUrl#fromConstant

goog.html.SafeUrl#from

goog.html.SafeUrl#sanitize

Instance Methods

Instance Properties

Static Functions

Static Properties