Template safety

oxblade Alpha Laravel for Rust

Keep templates and view roots under application control. Treat values from requests, users and external services as untrusted data.

Choose the output form for the context

  • Use {{ value }} in HTML text and quoted HTML attributes. Validate URL schemes and CSS values before passing them to a view. Keep attribute names under application control.
  • Use @js(value) in a script block or an expression in a double-quoted JavaScript attribute. Use @json(value) with its defaults in a script block, an application/json data block or a single-quoted attribute. An explicit @json flag list replaces Blade's default HTML-safe flags. Keep the default flags or include hex_tag, hex_amp, hex_apos and hex_quot explicitly when embedding JSON in a script. @js always adds its required flags. Borrowed JSON integers through u64::MAX are emitted as exact decimal digits. JavaScript numbers can lose precision above 2^53 - 1 when read back, including through JSON.parse. JSON encoding charges output and expansion. Its depth comes from the directive's argument (default 512). Partial-output mode can continue past that depth.
  • Reserve Html and raw echoes for content the application trusts as markup.
  • @lang and @choice write their resolved result as raw output for Blade compatibility. This includes replacement values and the original key when a translation is missing. Use {{ __(key, replacements) }} or {{ trans_choice(key, count, replacements) }} for dynamic keys and replacements in HTML text or quoted attributes.
  • In HTML Markdown mail, escaped slot text is still parsed as Markdown. Links, images and formatting can remain active. Pass untrusted text through a Markdown-escaping step when it must appear literally.

Validate view and fragment selections

The core filesystem loader accepts dot-separated view names, with an optional namespace. The Laravel adapter delegates to the framework finder, which also accepts explicit slash-separated filenames and spaces in path segments. Use an application allow-list when a request chooses a view.

Each missing fragment name contributes the whole rendered view. Validate names against an allowlist if the requested fragment controls what a caller may see.

Resource limits

The Laravel adapter shares the render budget across pagination subviews and repeated views. Markdown mail post-processing charges for its final output and bounds CSS inlining work. The adapter rejects JSON fields nested more than 128 containers deep before building view layers. Typed view preparation also bounds Serde nesting. Pass the model or override by reference if the caller needs to dispose of deeply nested source data iteratively.