OpenFresco.Conformance (open_fresco v0.2.0)

Copy Markdown View Source

Conformance checks and host-usable assertions for the generated SVG — the enforcement side of OpenFresco.Svg's security contract.

Two audiences:

  • This package's testscheck_svg/1 verifies 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 (and check_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

allowed_tags()

@spec allowed_tags() :: [String.t()]

The generator's emitted-tag allowlist (for host tests that assert on it).

check_scene(scene, values \\ %{}, opts \\ [])

@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_svg(svg)

@spec check_svg(binary()) :: :ok | {:error, [term()]}

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}.

hostile_scenes()

@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.