Skip to content

Security ​

The threat model: every place ferrovue writes data that may come from a reader, what it guarantees there, the code that enforces it, the tests that hold it, and what it inherits from Vue.

ferrovue's promise is that the HTML it writes is the HTML Vue's server renderer writes. That makes Vue's own escaping the baseline: wherever Vue escapes, ferrovue escapes the same characters the same way, and wherever Vue writes a value as it is, so does ferrovue. A gap in that promise is a cross-site scripting hole in every site that uses ferrovue; SECURITY.md says how to report one. escaping is the user's guide to the same rules; this page is the map for a reviewer.

Trust boundaries ​

Trusted, written by the application's developers and checked in with it:

  • the components: .vue files, the .ts files they import types and constants from, and so every element name, attribute name, static attribute value, class and style property name, useHead key and <RouterLink> route name a template holds;
  • ferrovue.config.json, the routes file, the store definitions and the locale files (messages are compiled into Rust at build time), each inside the project or a directory it shares (see files outside the project);
  • the application's Rust: the page around the components, slot closures, Rust twins and helpers, the TrustedHtml types and their sanitisers, the futures that fill HtmlStream holes, and the ids given to state_script_into and PageRecord.

Untrusted, and safe to fill from a request, a database or another user:

  • every prop value, at every depth: strings, numbers, lists, dictionaries (keys too), optional and nullable values;
  • Pinia store state;
  • the route: the location given to Router::at, and so the path, its parameters, the query and the hash; a <RouterLink>'s to built from props;
  • the locale name passed to the generated i18n(locale), and every value given to $t;
  • every value given to useHead and useSeoMeta;
  • the input of BasicHtml::new, InlineHtml::new and Sanitised::new;
  • the margin and query of a Hydrate, and a <Teleport>'s to.

Untrusted data is safe in the sense Vue's server renderer gives: it cannot leave the text node or quoted attribute value it is written into, and it cannot add an element or an attribute. It can still be a hostile value where the context gives values meaning: a URL, CSS, an event handler. Those cases are listed under what ferrovue inherits from Vue.

Files outside the project ​

The compiler reads the components, the stores, the locale files, the routes file and the pages folder from the directories ferrovue.config.json names, and compiles their text into the binary. A symbolic link among them, or a ../ path in the configuration, could lead to any file on the machine that builds it, so a pull request that adds locales/en.json as a link to a file elsewhere would ship that file's text. The compiler takes the real path of each such file and directory, and refuses one outside the project's root (FV1125) unless it lies in a directory sharedDirectories lists:

json
{ "components": "src/components", "out": "src/generated", "sharedDirectories": ["../shared/locales"] }

That is how the packages of a monorepo share locale files or components: list the shared directory, and review a change to that list as a change to what the build reads. A page in a pages folder that is a link is skipped, as vue-router's file-based routing reads only files.

The .ts files a component imports types and constants from are found as TypeScript finds them, through tsconfig.json's paths and packages, and are not checked: an import is visible in the component that writes it, where a link is not.

CoderefuseOutsideProject and listDir in packages/ferrovue/src/files.ts; readRoutes in plugins/router.ts; fileRoutes in file-routes.ts
Tests"refuses a file that leads out of the project" in packages/ferrovue/test/configuration.test.ts

Where data is written ​

Text ​

Written{{ }}, v-text, a component's text props, messages from $t, the route's fields, store state
Guarantee", &, ', < and > are written as entities (&quot;, &amp;, &#39;, &lt;, &gt;), every other character as it is: Vue's escapeHtml. Numbers and booleans are written as JavaScript writes them and hold none of the five
Codeescape_into in crates/ferrovue-core/src/lib.rs; the compiler emits it for every string (display in packages/ferrovue/src/attrs.ts)
Testscrates/ferrovue-core/tests/vectors/escape.json (recorded from @vue/shared) and a 20,000-case property against a byte-by-byte reference (crates/ferrovue-core/src/tests.rs); escaped_text_holds_no_markup_and_reads_back_whole (crates/ferrovue/tests/properties.rs); the conformance components' hostile fixtures; the fuzzer, whose FERROVUE_FUZZ_PLANT=1 self-check replaces one escape_into with a plain push and must be caught

Text inside <textarea>, <title> or <noscript> is escaped the same way. Text inside a <script> or <style>, which a template can only reach through <component :is>, is escaped too and stays code: see below.

Attribute values ​

WrittenBound attributes (:title, :href), static ones beside them, class and style in all their shapes, attributes falling through to a child's root ($attrs, useAttrs(), inheritAttrs: false), boolean and enumerated attributes, <RouterLink>'s href and classes
GuaranteeEvery value is double-quoted and escaped with escape_into. A boolean attribute (disabled, checked, hidden given a boolean, and the rest of Vue's list) is written as its name alone or left out. class is normalised (trimmed, empty names dropped, an object's true names joined) and escaped as a whole. Static values are the template's, written as Vue's compiler writes them
CoderenderAttr and renderDynamicAttr in packages/ferrovue/src/attrs.ts; crates/ferrovue/src/attrs.rs (attr_into, dynamic_attr_into, style_into) for merged and fallthrough attributes; crates/ferrovue/src/attrs.rs
Testscrates/ferrovue/tests/vectors/attrs.json (ssrRenderAttrs(mergeProps(…))) and class.json, recorded from Vue; the Attrs, Fallthrough and Fall* components' hostile fixtures; Unsanitised (below)

Attribute names ​

WrittenEvery attribute name a template binds, the names that fall through to a child's root, the names of an element <component :is> renders from virtual nodes
GuaranteeNo attribute name comes from data. The compiler takes names from the template alone: a name chosen at run time (:[name]) is refused (FV0408), and so is v-bind of anything but an object literal (FV0410); $attrs holds the names some parent's template wrote. A bound name Vue's server renderer would skip as unsafe (one holding >, /, =, ", ', tab, line feed, form feed, carriage return or space) is refused at compile time (FV0404)
CodeobjectAttrs, mergeProps and attrEntries in packages/ferrovue/src/attrs.ts; packages/ferrovue/src/fallthrough.ts
Defence in depthThe runtime that writes fallthrough attributes repeats Vue's rules for names given to Attrs by Rust code: it drops key, ref, innerHTML, textContent, ref_key, ref_for, names starting . and listeners (on followed by anything but a lower-case letter), lowers the case, maps className, htmlFor, acceptCharset and httpEquiv, writes a boolean attribute as its name, and drops a name holding any of the unsafe characters above (dynamic_attr_into in crates/ferrovue/src/attrs.rs)
Testsattrs.json holds names with each unsafe character, NUL, U+00A0, on, onx and onClick; refusals.test.ts refuses :x'y, :[name] and v-bind="props.extra"; TagCasing holds the case rules of virtual nodes to Vue

CSS ​

Written:style objects, arrays and strings, merged with a static style, v-show's display:none, styles falling through
GuaranteeProperty names come from the template (computed names are refused, FV1008, and so are numeric and :-prefixed ones, FV1009) and are escaped; values are escaped. A string merged with other styles is parsed into declarations as Vue's normalizeStyle parses it and written back escaped. Its comments are stripped in one pass over the string, however many unclosed /* it holds. v-bind() in a <style> block is refused (FV1006), so no prop reaches CSS custom properties
Codepackages/ferrovue/src/styles.ts; style_into, parse_style and style_text_into in crates/ferrovue/src/attrs.rs
TestsStyles and Shown fixtures (hostile included), attrs.json's styles, Unsanitised

Island props: data-props and data-hydrate ​

WrittenAn island's wrapper, <div data-island="Name" data-props='{…}' data-hydrate="…">
Guaranteedata-props is the props as JSON (serde_json, with NaN and Infinity as bare tokens), written in single quotes with each & as &amp; and each ' as &#39; as it is written, so it is one attribute value whatever the props hold: inside a single-quoted value only ' ends it and only & starts a reference. Props serde_json refuses write an empty value in a release build and panic in a debug one. data-island is the component's name, a constant, escaped as well. data-hydrate is Hydrate::attribute, escaped. The client reads data-props with JSON.parse and a reviver for the non-finite tokens (parseJson in packages/ferrovue/src/client.ts), and never evaluates it. On a page rendered in an IslandKey's scope, each wrapper carries the key in data-island-key and the page holds it in a script, so mountIslands mounts no island copied into user HTML (islands only the server wrote)
Codeisland_into in crates/ferrovue/src/html/island.rs; IslandKey in crates/ferrovue/src/html.rs and pageIslandKey in packages/ferrovue/src/client.ts; escaped_into in crates/ferrovue/src/json.rs; with the dioxus feature, to_element in crates/ferrovue/src/dioxus.rs hands the same values to Dioxus as attributes, which it escapes
Testsisland_props_cannot_leave_their_attribute, the_island_name_is_escaped_too, a_hostile_media_query_or_root_margin_cannot_leave_its_attribute and the island key's tests (crates/ferrovue/src/html/tests.rs); mounts only the islands that carry the page's key when the page holds one (packages/ferrovue/test/islands.test.ts); written_escaped_is_what_escaping_the_json_gives (json.rs); the Dioxus tests in tests/conformance.rs

The state script and the page record ​

Writtenstate_script_into (Pinia state) and PageRecord::script_into (the layout's props and every page part's component and props): <script type="application/json" id="…">…</script>; Loads::script_into (each loader's key and result): <script type="application/json" data-fv-loads>…</script>
GuaranteeThe JSON has <, >, &, U+2028 and U+2029 written as \u escapes, so no value can end the element, open a comment or be read as markup inside it, and the body reads back as the JSON given. The id is escaped. The type is application/json, which no browser runs, so the page needs no nonce for it. A value serde_json refuses is null in the record, which stays readable. The client reads each from the first <script> with its id (hydrateState, mountPage, readPage), so an element of user HTML given the same id is passed over
Codejson_script_into and json_escaped_into in crates/ferrovue/src/page.rs; Recorded::to_json in crates/ferrovue/src/page.rs; Loads::script_into in crates/ferrovue/src/loaders.rs; state_script in dioxus.rs
Testscrates/ferrovue/src/page/tests.rs; the_record_cannot_be_closed_by_a_prop_and_reads_back_whole (crates/ferrovue/src/page/tests.rs); the_state_script_is_one_element_whose_body_reads_back and the_loads_script_is_one_element_whose_body_reads_back (properties.rs); the_payload_holds_each_result_read_once_in_order_and_cannot_close_its_script (crates/ferrovue/src/loaders/tests.rs); pages/hostile.json in the conformance suite; reads the state from a script, passing over another element or an SVG script with its id (packages/ferrovue/test/client.test.ts) and reads the record from a script, passing over another element with its id (packages/ferrovue/test/page.test.ts)

The page head ​

WrittenHead::render: <title>, <meta>, <link>, <base>, <style>, <script>, <noscript>, and the <html> and <body> attributes
GuaranteeExactly what unhead's renderSSRHead writes, which escapes less than Vue does. A title is escaped as text (&, <, >, ", ' and /). An attribute value is double-quoted with only " escaped. Attribute names other than data- ones are lowered, and names are dropped when empty or holding JavaScript whitespace, ", ', <, >, /, =, a control character or DEL; __proto__, constructor and prototype keys are dropped. A script whose type ends in json, or is importmap or speculationrules, has < written as <. Any other script, style or noscript content is written as it is, with only its own closing tag (</script, </style, </noscript, in any case) written as <\/…
Codetag_into, props_into, invalid_attr_name, sanitize and replace_close_tag_into in crates/ferrovue/src/head.rs
Testscrates/ferrovue/tests/vectors/head.json: 460 heads recorded from unhead, hand-written ones with markup-breaking values, hostile attribute names and <!--<script> in scripts, and 400 drawn at random from hostile values (packages/ferrovue/test/head-inputs.ts); the HeadPage, HeadLater and HeadNest hostile fixtures, hydrated by unhead's client

Where unhead escapes less than a browser needs, the browser reads back something other than the value: a&amp;b in an attribute is read as a&b. The fixtures in UNHEAD_REWRITES (packages/ferrovue/test/conformance-cases.ts) are those where unhead's client then rewrites the tag as it hydrates. A value still cannot leave its attribute, since " is escaped, or its <style>, <script> or <noscript>, since the closing tag is.

WrittenThe href of each link, its active classes, aria-current
GuaranteeThe href is what vue-router's router.resolve(to).href gives, escaped as escape_into escapes, whether it is built or written in place. With { name, params }, each parameter is encoded as vue-router encodes it (/, ?, # and characters outside a URI percent-encoded); a query built with query_into encodes keys and values (&, #, +, = in a key, a space as +); a hash is encoded. A string to, and the path of { path }, are kept as written and resolved against the current path when they do not start with /
Codelink, link_named, link_path and the _into writers of each in crates/ferrovue-router/src/lib.rs, encode_into and split_url in crates/ferrovue-router/src/url.rs; packages/ferrovue/src/plugins/router-link.ts
Testscrates/ferrovue-router/tests/vectors/router.json (recorded from vue-router: hostile parameters, queries and hashes, javascript:alert(1), https://example.com/ and //evil.example/x as a string to); crates/ferrovue-router/tests/properties.rs; the Nav and Menu hostile fixtures (Menu/hostile-quotes with ' and & in every parameter and query), Links/encoded and RouteInfo/query-hostile

Translated messages ​

Written$t(…) and t(…) from useI18n(), and locale
GuaranteeA message is text. vue-i18n's message compiler turns each locale file into parts at build time; at render, named and list values are put in as they are, as vue-i18n does with its default escapeParameter: false, and the whole message is then escaped where it is written, as Vue escapes {{ $t(…) }}. v-html of a message is refused (FV1502). A missing key renders as the key, escaped
CodeI18n::t in crates/ferrovue-i18n/src/lib.rs; packages/ferrovue/src/plugins/i18n.ts
TestsTranslated and Plurals fixtures, whose messages hold <b> and & and whose hostile fixture passes markup as a value; crates/ferrovue-i18n/src/tests.rs

v-html and trusted HTML ​

Writtenv-html
GuaranteeThe only place generated code writes a value unescaped. It is accepted only on a prop typed TrustedHtml or InlineHtml (FV1502); anything else, a string or a message, is refused at compile time. Such a prop's Rust type implements TrustedHtml, whose contract is that every value has been through a sanitiser. ferrovue's own types: BasicHtml and InlineHtml escape their whole input as escape_into does and write back as tags only their fixed lists, exactly spelled, without attributes, balanced; Sanitised (the ammonia feature) is ammonia's output. Each deserialises by sanitising again, so no JSON makes one that skipped the sanitiser. v-html is also refused where the browser's parser would rebuild the HTML (tables, <select>, SVG and MathML, block HTML inside a <p>: FV1512 and FV1513), which keeps the server's and client's trees the same
Codetrusted_into, BasicHtml, InlineHtml and Sanitised in crates/ferrovue/src/html.rs; the TrustedHtml type in packages/ferrovue/src/typescript.ts; packages/ferrovue/src/vhtml.ts; the v-html branch of packages/ferrovue/src/template.ts
Testscrates/ferrovue/src/html/tests.rs (its basic_html and sanitised modules: scripts, handlers, javascript: URLs) and the basic_html_* and inline_html_* properties, which parse every output back with html5ever (crates/ferrovue/tests/sanitised.rs); the v-html tests in components.test.ts; Prose, InlineProse and HtmlTruth fixtures

A TrustedHtml type of the application's own is outside ferrovue's guarantee: ferrovue writes what it holds.

Teleports ​

Written<Teleport> content, collected in Teleports and written by the application where each target is
GuaranteeThe content is generated markup, escaped as any other. to only names the collection the content goes into; it is never written into the page
Codecrates/ferrovue/src/page.rs; packages/ferrovue/src/plugins/teleport.ts
Testscrates/ferrovue/src/page/tests.rs; the teleport fixtures, compared with what Vue's server teleported

Holes ​

Writtenhole and PageHole write a marker that split_holes and HtmlStream cut the page at
GuaranteeNo value ferrovue writes holds the marker, so data cannot add or move a hole. The marker is <fv-hole"</script</style</noscript>: escaped text and attribute values have no <; the state script and page record have none either; unhead's attribute values have no raw ", its titles no raw <, its JSON scripts no raw <, and its other script, style and noscript content cannot hold that element's closing tag; BasicHtml, InlineHtml and ammonia write tags as a serialiser does, with no " after a tag's name. What fills a hole is written as it is
CodeHOLE in crates/ferrovue/src/render.rs; HtmlStream::new in crates/ferrovue/src/web.rs
Testsa_value_in_the_head_cannot_move_a_hole (web.rs), no_head_value_writes_the_hole_marker (crates/ferrovue/src/head/tests.rs), no_value_holds_a_hole (crates/ferrovue/src/html/tests.rs); pages/hostile.json passes <fv-hole> as a prop

Scope ids ​

data-v-… attributes are written as they are. They come from the compiler (hashes of the component's path and source) and reach components through render_scoped and Attrs; scope_attrs joins them without escaping. Code that builds an Attrs passes the ids generated code gave it, never data.

Rust twins, helpers and the application's own markup ​

A Rust twin writes its component's HTML itself, and a helper computes a value the template uses. ferrovue cannot check either against Vue, as errors_and_limits says, and their exactness is the application's assertion. A helper returns a string, number or boolean that generated code escapes like any other value, so a helper cannot write markup. A twin writes into the page directly, and must escape what it writes: escape_into for text and values, and attrs_into or passed_attrs_into for the attributes it is given. The same holds for slot closures, the page around the components and the content of holes: they are plain Rust, and what they push is written as it is.

Panics ​

Generated code and the runtime are written not to panic on props in a release build, and SECURITY.md counts one that does as a vulnerability. Props that ask for what cannot be written as Vue writes it, such as a date string browsers read differently or an integer beyond ±2⁶³ where the template needs one, are refused at render time: the generated try_render returns the refusal, so a handler that renders props from a request answers with an error, and render panics with its message (errors_and_limits). A debug build panics where Vue would throw or where data cannot be written exactly, so a mistake is found where it is made: props serde_json refuses, a required route parameter that is missing or empty, a plural number that chooses none of a message's cases. Page panics on a slot given twice and on a part written where Vue would give it a slot scope id, which are mistakes in the application's code. The router is held never to panic by properties over arbitrary locations.

What ferrovue inherits from Vue ​

Escaping keeps a value inside its context; it does not judge what the value means there. Vue does not either, and ferrovue writes what Vue writes, so each of these is left to the application. The Unsanitised conformance component holds the first four to Vue with hostile values.

  • URLs. A bound href, src, action, formaction or similar is written as given: a javascript: or data: URL from a reader stays one. Validate URLs from readers before rendering them (allow https:, http:, mailto: and relative ones), as a Vue application would.
  • srcdoc. The value is escaped for the attribute, and the browser decodes it and parses it as a whole document: :srcdoc of reader input is markup injection. Give it HTML from a sanitiser.
  • Event handler attributes. An attribute whose name starts on and a lower-case letter, such as :onclick="value" on an element or onclick passed to a component and falling through to its root, is an attribute to Vue, and its value is written escaped: the browser runs it as script. Never bind reader input to one.
  • CSS. A style value is escaped and not checked: { color: value } with red;position:fixed adds declarations, and url(…) fetches. Bind values from a fixed set, or check them.
  • <script> and <style> elements. A template that renders one through <component :is> and interpolates into it writes the value escaped, and escaping does not make script or CSS safe.
  • <RouterLink>. A string to that starts with //, such as //evil.example/x, is a protocol-relative URL to another host, as vue-router resolves it. So are /\evil.example/x and a /, a tab or line break and another /, since a browser reads \ as / and drops tabs and line breaks. A to built from reader input, :to="'/' + slug" included, should be an object with a name and params, whose values are encoded.
  • Routes behind middleware. vue-router matches a path case-insensitively and with or without a trailing slash, and so does Router::at. An axum or actix route matches its path exactly. When middleware guards a route of the framework and the same page is also rendered from its fallback, /Admin and /admin/ reach the fallback without the middleware, and the fallback renders the guarded page. Check access where the page is rendered, by the route Router::at resolves, which holds for every path. Or set "strict": true and "sensitive": true under router, and the same options in createRouter, so the router matches paths as exactly as the framework does (Matching paths exactly). A percent-encoded path such as /%61dmin matches neither side: neither decodes a path before matching it.
  • A request path that starts with //. On a page at //evil.example/x, every relative link, such as ?page=2, #top or sibling, resolves to an href on evil.example, as vue-router resolves it. Answer a path that starts with // or holds a \ before resolving it, as a page from the fallback does. linkRoutes and linkRouter refuse to hand such a link to navigate.
  • Route parameters. A parameter is decoded, as vue-router and axum's Path decode it: /users/..%2Fadmin gives the parameter ../admin, and %00 a NUL. Check a parameter before it names a file, and encode it with encodeURIComponent before it goes into a URL, a loader's fetch included.
  • Sizes from props. .repeat(), .padStart() and .padEnd() make strings as long as V8 makes them, about half a billion code units, and a regular expression with nested repetition takes time that grows with its input. Bound counts and lengths that come from readers.
  • Translated messages in URLs. A message is text wherever it goes; bound to :href, it is a URL and may be any URL the message files hold.
  • The page head. unhead does not check URLs in href and content. A script, style or noscript given reader input is code: in a script other than JSON, <!--<script> keeps the element open past its closing tag, as unhead writes it, and noscript content is HTML to a browser running without scripts. Put reader input in title, meta content and attributes, or in a script of type application/ld+json, whose < is escaped.

For a reviewer ​

ferrovue's escaping is small, and most of it is a few functions. These hold the guarantee, in the order a review should take them:

  1. crates/ferrovue-core/src/lib.rs: escape_into, which every value goes through.
  2. crates/ferrovue/src/attrs.rs and packages/ferrovue/src/attrs.ts, fallthrough.ts and styles.ts: attribute names and values, merging, fallthrough. The question: can a name come from data, or a value reach a quote unescaped?
  3. crates/ferrovue/src/json.rs, state.rs, html.rs and page.rs: JSON in an attribute and in a script. Can a value close the attribute or the element?
  4. crates/ferrovue/src/html.rs and packages/ferrovue/src/template.ts, typescript.ts and vhtml.ts: the one unescaped write, and what may reach it.
  5. crates/ferrovue/src/head.rs: unhead's rules, reproduced.
  6. crates/ferrovue-router/src/lib.rs: URL encoding.
  7. crates/ferrovue/src/render.rs and web.rs: the hole marker.

The compiler's side of each rule is the code that refuses: a construct the compiler cannot translate exactly is an error with a code (error_codes).