class
Components::Elements::Svg
- Components::Elements::Svg
- Components::Elements::ContainerElement
- Components::Elements::HTMLElement
- Reference
- Object
Overview
Represents the
Defined in:
components/elements/embedded/media.crConstructors
-
.new(**attrs)
SafeHTML v1 (docs/SAFE_HTML_V1.md §3.6):
<svg>is HTML5 foreign-content -- the tokenizer switches into the SVG namespace for everything inside it, but a<script>element inside that namespace is still recognized and STILL EXECUTES (<svg><script>alert(1)</script></svg>is a well-known, browser-verified XSS payload class, inline in an ordinary HTML document, not just a standalone.svgfile).
Instance methods inherited from class Components::Elements::ContainerElement
<<(child : ContainerElement) : ContainerElement<<(child : VoidElement | String | RawHTML) : self <<, add_child(child : HTMLElement | String | RawHTML) : self add_child, add_children(*children : HTMLElement | String | RawHTML) : self add_children, add_raw_html(html : String) : self add_raw_html, build(&block : self -> Nil) : self build, children_count : Int32 children_count, clear : self clear, empty? : Bool empty?, render : String render
Constructor methods inherited from class Components::Elements::ContainerElement
new(tag_name : String, **attrs)
new
Instance methods inherited from class Components::Elements::HTMLElement
[](name : String) : String | Nil
[],
add_class(class_names : String) : self
add_class,
add_style(styles : String) : self
add_style,
attributes : Hash(String, String)
attributes,
can_have_children? : Bool
can_have_children?,
children : Array(HTMLElement | String | RawHTML)
children,
has_class?(class_name : String) : Bool
has_class?,
remove_attribute(name : String) : self
remove_attribute,
remove_class(class_names : String) : self
remove_class,
render : String
render,
set_attribute(name : String, value : String | Nil) : self
set_attribute,
set_safe_style(style : SafeStyleValue) : self
set_safe_style,
set_safe_url_attribute(name : String, url : SafeURL) : self
set_safe_url_attribute,
tag_name : String
tag_name,
to_s(io : IO) : Nil
to_s,
void_element? : Bool
void_element?
Constructor methods inherited from class Components::Elements::HTMLElement
new(tag_name : String, **attrs)
new
Constructor Detail
SafeHTML v1 (docs/SAFE_HTML_V1.md §3.6): <svg> is HTML5
foreign-content -- the tokenizer switches into the SVG namespace for
everything inside it, but a <script> element inside that
namespace is still recognized and STILL EXECUTES
(<svg><script>alert(1)</script></svg> is a well-known,
browser-verified XSS payload class, inline in an ordinary HTML
document, not just a standalone .svg file). A previous version of
this class overrode render_children to pass String children
through completely unescaped ("SVG content is not escaped like
HTML") -- that is exactly as dangerous as <script> accepting a
plain-String child, just reached through a different element. There
is no legitimate reason a String child of Svg needs to bypass
escaping: real hand-authored SVG markup (<path d="..."> and
friends) is built the same way any other raw/vouched markup is in
this shard -- RawHTML.new(...) / add_raw_html(...) (already a
documented, greppable raw door, see docs/SAFE_HTML_V1.md §4) -- not
by relying on Svg silently treating every String as markup.
Removing the override restores the inherited, safe
ContainerElement#render_children behavior: HTMLElement/RawHTML
children render as before, and a String child is HTML-escaped
like a text node on every other element.