# Template safety (oxblade)

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

- Package: oxblade (Laravel for Rust, alpha), crates: `oxblade`, `oxblade-laravel`, `oxblade-macros`, `oxblade-mail`, `oxblade-cli`
- Maintenance: active; Latest release: 0.2.0 (2026-12-05); Framework: laravel-rust 0.2.x; MSRV: Rust 1.99 or later; Licence: MIT
- Links: [Repository](https://github.com/bowerbird-si/oxblade), [crates.io](https://crates.io/crates/oxblade/0.2.0), [docs.rs](https://docs.rs/oxblade/0.2.0), [Changelog](https://oss.bowerbird.si/oxblade/docs/changelog/), [Contributing](https://github.com/bowerbird-si/oxblade/blob/c7fab7e68e7ad4df560796ee140e438944d26598/CONTRIBUTING.md), [Security policy](https://github.com/bowerbird-si/oxblade/blob/c7fab7e68e7ad4df560796ee140e438944d26598/SECURITY.md)
- Based on: [Laravel Blade](https://github.com/illuminate/view): The template language this package implements: Blade's markup, directives and rendered HTML (illuminate/view, MIT).
- Community package, not affiliated with Laravel.
- HTML version: https://oss.bowerbird.si/oxblade/docs/template-safety/
- Source: https://github.com/bowerbird-si/oxblade/blob/c7fab7e68e7ad4df560796ee140e438944d26598/docs/template-safety.md

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.
