class
Components::Elements::Iframe
- Components::Elements::Iframe
- Components::Elements::ContainerElement
- Components::Elements::HTMLElement
- Reference
- Object
Overview
Represents the
Included Modules
Defined in:
components/elements/embedded/media.crConstructors
-
.new(**attrs)
SafeHTML v1 (docs/SAFE_HTML_V1.md §3.5, §3.7):
.srcdocis an HTML-DOCUMENT-VALUED attribute, not a plain string one. -
.srcdoc(html : String, reason : String, **attrs) : Iframe
The typed, reasoned door for
.srcdoc— mirrorsScript.static(js, reason:)/SafeURL.unsafe(url, reason:).
Instance Method Summary
-
#set_attribute(name : String, value : String | Nil) : self
SafeHTML v1 (docs/SAFE_HTML_V1.md §3.5): reject a bare-
String.srcdochere — this is the chokepoint both the constructor-kwarg path (HTMLElement#initializecalls#set_attributeonce per kwarg) and the direct#set_attributepath funnel through, so one check closes both, matching howUrlAttributeValidationclosessrc/hreffor the very same two paths. - #set_srcdoc(html : String, reason : String) : self
Instance methods inherited from module Components::Elements::UrlAttributeValidation
set_attribute(name : String, value : String | Nil) : self
set_attribute
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.5, §3.7): .srcdoc is an
HTML-DOCUMENT-VALUED attribute, not a plain string one. The browser
HTML-entity-decodes the (correctly-escaped-for-the-outer-document)
attribute value and then feeds the decoded result to a fresh HTML
parser as the entire source document for the iframe's nested
browsing context. HTMLElement#escape_attribute protects the
outer document's parse (so the attribute stays well-formed) but
does nothing to stop a <script> inside that re-parsed nested
document from executing — value-escaping is the wrong tool for this
sink, exactly as it is for javascript: URLs, just one layer
removed. This makes .srcdoc exactly as dangerous as <script>
body content (see Elements::Script), just carried in an attribute
instead of element children — so it gets the identical treatment:
a bare String is banned unconditionally, with a loud, reasoned,
typed door as the only way through.
document_sink_attribute?/vouch_document_attribute (declared on
HTMLElement, §3.7) are the GENERAL mechanism this used to
implement locally with its own @vouched_srcdoc ivar and a
one-off render_attributes override. That override only ever
re-checked the exact key "srcdoc" — a case/whitespace-varied
direct mutation (iframe.attributes["SRCDOC"] = "...") landed in a
different Hash entry and sailed past it unchecked. Declaring
document_sink_attribute? here instead means HTMLElement
render_attributes' single authority checks EVERY live attribute by
normalized name, closing that gap without Iframe needing its own
render-time backstop at all.
The typed, reasoned door for .srcdoc — mirrors Script.static(js, reason:) / SafeURL.unsafe(url, reason:). Builds a fresh Iframe
with .srcdoc set from the vouched HTML. Any other constructor kwarg
(src, title, sandbox, loading, ...) is still accepted and
still validated normally.
Instance Method Detail
SafeHTML v1 (docs/SAFE_HTML_V1.md §3.5): reject a bare-String
.srcdoc here — this is the chokepoint both the constructor-kwarg
path (HTMLElement#initialize calls #set_attribute once per
kwarg) and the direct #set_attribute path funnel through, so one
check closes both, matching how UrlAttributeValidation closes
src/href for the very same two paths. Name comparison is
normalized (strip.downcase) so SRCDOC, Srcdoc, and
" srcdoc" are all caught too — real HTML attribute names are
ASCII-case-insensitive and tolerant of incidental whitespace from
hand-built call sites, exactly like UrlAttributeValidation's own
normalization. This is fail-FAST, call-time defense-in-depth — the
render-time authority (document_sink_attribute? + HTMLElement #validate_rendered_attribute!, §3.7) is what's actually unbypassable.
The typed, reasoned door for setting .srcdoc on an already-built
Iframe — the shape most call sites need (an Iframe constructed
first via ordinary kwargs, .srcdoc attached after), mirroring the
already-existing instance-level typed setters
#set_safe_url_attribute / #set_safe_style. reason: is
mandatory, matching every other vouching door in this shard.