strix/skills/tooling/hypothesis.md
Use Hypothesis when a security property can be expressed over local code and failures are likely to hide in combinations of encoding, normalization, structure, or parser recovery. It is especially useful for comparing two implementations or checking that validation and consumption preserve the same meaning.
Do not point unrestricted generators at a live service. Hypothesis is safest and most useful against pure local adapters with no network, subprocess, filesystem, or persistent-state side effects.
Use an isolated virtual environment and install a reviewed pinned version:
python -m pip install 'hypothesis==<reviewed-version>'
Official project: Hypothesis
Write the security relationship before writing strategies. Examples:
allowlist(raw) implies sink(canonicalize(raw)) remains inside the allowed origin/path
validator(raw) accepts implies consumer(raw) assigns the same media type/structure
parse_A(raw) and parse_B(raw) agree on message boundaries and authoritative fields
serialize(parse(raw)) cannot introduce a delimiter, wildcard, traversal, or new field
A test that only checks “does not crash” can find robustness bugs but does not establish a security differential.
from hypothesis import given, settings, strategies as st
def outcome(parser, raw):
try:
return ("accept", parser(raw))
except ExpectedParseError as exc:
return ("reject", type(exc).__name__)
@settings(max_examples=250, deadline=500)
@given(st.text(max_size=128))
def test_security_boundary(raw: str) -> None:
checked = outcome(security_parser, raw)
consumed = outcome(sink_parser, raw)
assert equivalent_security_meaning(checked, consumed)
st.one_of, st.sampled_from, st.lists, st.binary, st.text, and composite strategies to represent the actual grammar.@example for known delimiters and regressions.Generate only axes supported by the target's transformation graph. Cartesian payload spraying obscures causality.