Conformance checks and host-usable assertions for the generated SVG —
the enforcement side of OpenFresco.Svg's security contract.
Two audiences:
- This package's tests —
check_svg/1verifies every generated document against a fixed tag / attribute / URL-scheme allowlist, and the fuzz corpus (hostile_scenes/0) drives hostile scene fields through the generator asserting the allowlist always holds. - Host apps — import
check_svg/1(andcheck_scene/2) into your own test suite to CI your templates against this contract, so a library change that widened the emitted surface fails your build too.
The allowlist is intentionally strict: the generator emits a small, fixed vocabulary. If a legitimate feature needs a new tag, it's added here deliberately — never discovered in production.
Summary
Functions
The generator's emitted-tag allowlist (for host tests that assert on it).
Render scene with values/opts and check the output — the common
host assertion (assert :ok = check_scene(my_template, my_values)).
Check an SVG binary against the contract. Returns :ok or
{:error, [violations]} where each violation is
{:disallowed_tag, tag}, {:banned_tag, tag},
{:event_handler, attr}, or {:unsafe_url, scheme, url}.
A corpus of scenes whose fields carry hostile strings — <script>
injection, javascript: / data:text/html hrefs, quote-breakouts,
event-handler attribute breakouts, entity tricks. Every one must pass
check_svg/1 after rendering; drives the fuzz test and is exported so
hosts can extend it.
Functions
@spec allowed_tags() :: [String.t()]
The generator's emitted-tag allowlist (for host tests that assert on it).
@spec check_scene(OpenFresco.Scene.t(), map(), keyword()) :: :ok | {:error, [term()]}
Render scene with values/opts and check the output — the common
host assertion (assert :ok = check_scene(my_template, my_values)).
Check an SVG binary against the contract. Returns :ok or
{:error, [violations]} where each violation is
{:disallowed_tag, tag}, {:banned_tag, tag},
{:event_handler, attr}, or {:unsafe_url, scheme, url}.
@spec hostile_scenes() :: [OpenFresco.Scene.t()]
A corpus of scenes whose fields carry hostile strings — <script>
injection, javascript: / data:text/html hrefs, quote-breakouts,
event-handler attribute breakouts, entity tricks. Every one must pass
check_svg/1 after rendering; drives the fuzz test and is exported so
hosts can extend it.