safehtmlgithub.com/google/safehtml/uncheckedconversions Index | Files

package uncheckedconversions

import "github.com/google/safehtml/uncheckedconversions"

Package uncheckedconversions provides functions to create values of package safehtml types from plain strings. Use of these functions could potentially result in instances of safe HTML types that violate their type contracts, and hence result in security vulnerabilties.

Avoid use of the functions in this file whenever possible; instead prefer to create instances of package safehtml types using inherently safe builders or template systems.

Example appropriate uses include:

Index

Functions

func HTMLFromStringKnownToSatisfyTypeContract

func HTMLFromStringKnownToSatisfyTypeContract(s string) safehtml.HTML

HTMLFromStringKnownToSatisfyTypeContract converts a string into a HTML.

func IdentifierFromStringKnownToSatisfyTypeContract

func IdentifierFromStringKnownToSatisfyTypeContract(s string) safehtml.Identifier

IdentifierFromStringKnownToSatisfyTypeContract converts a string into a Identifier.

func ScriptFromStringKnownToSatisfyTypeContract

func ScriptFromStringKnownToSatisfyTypeContract(s string) safehtml.Script

ScriptFromStringKnownToSatisfyTypeContract converts a string into a Script.

Users of this function must ensure themselves that the string does not contain unsafe script. Note in particular that '<' is dangerous, even when inside JavaScript strings, and so should always be forbidden or JavaScript escaped in user controlled input. For example, if "</script><script>evil</script>" were interpolated inside a JavaScript string,it would break out of the context of the original script element and "evil" would execute. Also note that within an HTML script (raw text) element, HTML character references, such as "&lt;" are not allowed. See http://www.w3.org/TR/html5/scripting-1.html#restrictions-for-contents-of-script-elements.

func StyleFromStringKnownToSatisfyTypeContract

func StyleFromStringKnownToSatisfyTypeContract(s string) safehtml.Style

StyleFromStringKnownToSatisfyTypeContract converts a string into a Style.

Users of thie function must ensure themselves that the string:

The string may, however, contain literal single or double quotes (for example, in the "content" property). Therefore, the entire style string must be escaped when used in a style attribute.

The following example values comply with Style's type contract:

width: 1em;
height:1em;
width: 1em;height: 1em;
background:url('http://url');

In addition, the empty string is safe for use in a style attribute.

The following example values do NOT comply with this type's contract:

background: red    --- missing a trailing semi-colon
background:        --- missing a value and a trailing semi-colon
1em                --- missing an attribute name, which provides context
                       for the value

See also http://www.w3.org/TR/css3-syntax/.

func StyleSheetFromStringKnownToSatisfyTypeContract

func StyleSheetFromStringKnownToSatisfyTypeContract(s string) safehtml.StyleSheet

StyleSheetFromStringKnownToSatisfyTypeContract converts a string into a StyleSheet.

Users of this function must ensure themselves that the string does not contain unsafe script. Note in particular that '<' is dangerous, even when inside CSS strings, and so should always be forbidden or CSS-escaped in user controlled input. For example, if "</style><script>evil</script>" were interpolated inside a CSS string, it would break out of the context of the original style element and "evil" would execute. Also note that within an HTML style (raw text) element, HTML character references, such as "&lt;", are not allowed.See http://www.w3.org/TR/html5/scripting-1.html#restrictions-for-contents-of-script-elements (Similar considerations apply to the style element.)

func TrustedResourceURLFromStringKnownToSatisfyTypeContract

func TrustedResourceURLFromStringKnownToSatisfyTypeContract(s string) safehtml.TrustedResourceURL

TrustedResourceURLFromStringKnownToSatisfyTypeContract converts a string into a TrustedResourceURL.

func URLFromStringKnownToSatisfyTypeContract

func URLFromStringKnownToSatisfyTypeContract(s string) safehtml.URL

URLFromStringKnownToSatisfyTypeContract converts a string into a URL.

Source Files

uncheckedconversions.go

Version
v0.1.0 (latest)
Published
Apr 30, 2022
Platform
linux/amd64
Imports
2 packages
Last checked
3 weeks ago

Tools for package owners.