Skip to content

alexgreensh/repo-forensics / skills/repo-forensics

repo-forensics

Flagged

Security forensics for git repos, AI skills, and MCP servers. Audits dependencies, detects prompt injection, credential theft, runtime dynamism, manifest drift, known CVEs, CISA KEV (actively exploited) vulns, and 2026 attack patterns. Not for fixing vulnerabilities or pentesting.

FileKindSize
.gitignoreother193 B
SKILL.mdskill md43.4 KB
checksums.jsonconfig10.8 KB
checksums.json.sigother64 B
data/README.mdmarkdown1.3 KB
data/compromised_versions.jsonconfig188.3 KB
data/rule_ids.csvother35.3 KB
data/rulepacks/.gitkeepother221 B
data/rulepacks/dead_anchors.jsonconfig9.0 KB
data/rulepacks/mcp_security.jsonconfig31.2 KB
data/rulepacks/runtime_dynamism.jsonconfig46.7 KB
data/rulepacks/sast.jsonconfig107.6 KB
data/rulepacks/secrets.jsonconfig30.4 KB
data/rulepacks/shared.jsonconfig4.4 KB
data/rulepacks/skill_threats.jsonconfig95.4 KB
data/runtime_floors.jsonconfig2.3 KB
data/yara/cryptominers.yarother1.8 KB
data/yara/hacktools.yarother2.2 KB
data/yara/malware.yarother2.2 KB
data/yara/manifest.jsonconfig8.0 KB
data/yara/webshells.yarother2.5 KB
references/cursor-hook-contract.mdmarkdown5.6 KB
references/kernel_privesc_sandbox_pack.mdmarkdown5.0 KB
references/mcp-attack-patterns.mdmarkdown8.7 KB
references/research_sources.mdmarkdown8.0 KB
references/threat_patterns.mdmarkdown20.3 KB
scripts/_context_gate.pyscript21.7 KB
scripts/_ed25519.pyscript5.1 KB
scripts/_pyc_unmarshal.pyscript17.1 KB
scripts/_shared_patterns.pyscript4.8 KB
scripts/adjudication.pyscript16.4 KB
scripts/adjudication_bridge.pyscript1.0 KB
scripts/aggregate_json.pyscript69.2 KB
scripts/auto_scan.pyexecutablescript152.1 KB
scripts/corpus_sync.pyscript10.0 KB
scripts/cursor_pre_scan.pyscript22.5 KB
scripts/dast_sandbox.sbother1.6 KB
scripts/dead_anchors_extract.pyscript14.8 KB
scripts/dead_anchors_probe.pyscript27.1 KB
scripts/forensics_core.pyscript176.5 KB
scripts/gen_rule_ids.pyscript8.6 KB
scripts/hook_adapter.pyscript19.4 KB
scripts/ioc_manager.pyscript49.6 KB
scripts/parse_pnpm_lock.pyscript7.9 KB
scripts/pre_scan.pyscript143.5 KB
scripts/pypi_pins.pyscript8.1 KB
scripts/refresh_controller.pyexecutablescript48.4 KB
scripts/refresh_threat_dbs.pyexecutablescript19.4 KB
scripts/rule_loader.pyscript44.8 KB
scripts/rulepack_feed.pyscript26.4 KB
scripts/run_forensics.shexecutablescript20.3 KB
scripts/sarif_export.pyscript18.6 KB
scripts/scan_agent_skills.pyscript33.2 KB
scripts/scan_archive.pyscript29.1 KB
scripts/scan_ast.pyscript44.9 KB
scripts/scan_binary.pyscript10.9 KB
scripts/scan_bytecode.pyscript28.2 KB
scripts/scan_dast.pyscript28.8 KB
scripts/scan_dataflow.pyscript15.4 KB
scripts/scan_dead_anchors.pyscript15.9 KB
scripts/scan_decode.pyscript37.5 KB
scripts/scan_dependencies.pyscript124.5 KB
scripts/scan_devcontainer.pyscript8.5 KB
scripts/scan_entropy.pyscript15.6 KB
scripts/scan_entrypoint.pyscript34.3 KB
scripts/scan_git_config.pyscript96.3 KB
scripts/scan_git_forensics.pyscript24.1 KB
scripts/scan_history.pyscript14.5 KB
scripts/scan_infra.pyscript54.3 KB
scripts/scan_integrity.pyscript41.0 KB
scripts/scan_lifecycle.pyscript65.1 KB
scripts/scan_manifest_drift.pyscript47.0 KB
scripts/scan_mcp_security.pyscript42.3 KB
scripts/scan_oversize.pyscript11.7 KB
scripts/scan_post_incident.pyscript36.9 KB
scripts/scan_provenance.pyscript19.4 KB
scripts/scan_runtime_dynamism.pyscript23.5 KB
scripts/scan_runtime_floors.pyscript33.5 KB
scripts/scan_sast.pyscript59.1 KB
scripts/scan_secrets.pyscript11.9 KB
scripts/scan_skill_threats.pyscript102.4 KB
scripts/scan_splitstream.pyscript29.5 KB
scripts/scan_yara.pyscript19.7 KB
scripts/session_scan.pyscript54.1 KB
scripts/suppressions.pyscript15.4 KB
scripts/validate_manifests.pyscript13.7 KB
scripts/verify_install.pyscript26.2 KB
scripts/vuln_feed.pyscript31.1 KB
tests/conftest.pyscript13.4 KB
tests/corpus/DEAD_ANCHORS_CORPUS.mdmarkdown2.3 KB
tests/corpus/budgets.jsonconfig5.6 KB
tests/cursor_helpers.pyscript12.6 KB
tests/fixtures/legacy_main_blocks.jsonconfig10.3 KB
tests/fixtures/powershell_verdict_corpus.jsonconfig114.9 KB
tests/golden/parity_mcp_security.jsonconfig17.5 KB
tests/golden/parity_runtime_dynamism.jsonconfig31.7 KB
tests/golden/parity_sast.jsonconfig59.8 KB
tests/golden/parity_secrets.jsonconfig18.8 KB
tests/golden/parity_skill_threats.jsonconfig48.8 KB
tests/parity_corpus.pyscript6.3 KB
tests/powershell_hook.pyscript8.2 KB
tests/report_builders.pyscript5.0 KB
tests/schemas/sarif-schema-2.1.0.jsonconfig109.1 KB
tests/shell_compat.pyscript2.2 KB
tests/test_adjudication_bridge.pyscript832 B
tests/test_adjudication_containment.pyscript1.4 KB
tests/test_adjudication_output.pyscript20.0 KB
tests/test_adjudication_suppressions.pyscript18.7 KB
tests/test_advisory_adjudication.pyscript1.3 KB
tests/test_agent_relay_rules.pyscript7.8 KB
tests/test_aggregate_json.pyscript10.0 KB
tests/test_auto_scan_patterns.pyscript10.5 KB
tests/test_benign_corpus.pyscript16.4 KB
tests/test_benign_new_scanners.pyscript6.1 KB
tests/test_build_output_skip.pyscript10.6 KB
tests/test_capability_ledger.pyscript18.8 KB
tests/test_codex_install.pyscript10.0 KB
tests/test_codex_marketplace.pyscript3.3 KB
tests/test_comment_false_positives.pyscript2.2 KB
tests/test_composer_dependencies.pyscript4.0 KB
tests/test_compromised_versions.pyscript51.2 KB
tests/test_context_gate.pyscript32.4 KB
tests/test_coverage_status.pyscript7.6 KB
tests/test_css_compounding_shrink.pyscript20.8 KB
tests/test_cursor_adapter.pyscript7.8 KB
tests/test_cursor_benign.pyscript3.4 KB
tests/test_cursor_degrade.pyscript12.7 KB
tests/test_cursor_install.pyscript17.1 KB
tests/test_cursor_latency.pyscript7.2 KB
tests/test_cursor_parity.pyscript5.8 KB
tests/test_cursor_redteam_fn.pyscript4.9 KB
tests/test_cursor_tamper_modify.pyscript14.2 KB
tests/test_cursor_wiring.pyscript32.3 KB
tests/test_d1_yara_correlation.pyscript9.2 KB
tests/test_dead_anchors_extract.pyscript7.6 KB
tests/test_dead_anchors_probe.pyscript19.7 KB
tests/test_evidence_engine_parity.pyscript8.1 KB
tests/test_evidence_model.pyscript11.4 KB
tests/test_forensics_core.pyscript79.2 KB
tests/test_fp_hardening_r3.pyscript9.7 KB
tests/test_fp_hardening_r4.pyscript18.8 KB
tests/test_fp_regression_pairs.pyscript62.5 KB
tests/test_fp_structural.pyscript21.2 KB
tests/test_freshness.pyscript6.2 KB
tests/test_frontmatter_validity.pyscript7.0 KB
tests/test_gpg_rce_hotfix.pyscript4.8 KB
tests/test_hook_inert_data.pyscript6.1 KB
tests/test_hook_scripts.pyscript14.0 KB
tests/test_inspection_cpu_budget.pyscript11.6 KB
tests/test_ioc_manager.pyscript55.4 KB
tests/test_kernel_privesc_rules.pyscript27.8 KB
tests/test_legit_precision_regressions.pyscript6.8 KB
tests/test_lethal_trifecta.pyscript20.7 KB
tests/test_manifest_signature.pyscript1.5 KB
tests/test_manifest_validity.pyscript2.9 KB
tests/test_monotonic_trust_e2e.pyscript4.4 KB
tests/test_non_breaking_contract.pyscript22.7 KB
tests/test_openclaw_install.pyscript6.6 KB
tests/test_pack_parity.pyscript24.8 KB
tests/test_parse_pnpm_lock.pyscript10.7 KB
tests/test_plugin_checkout_provenance.pyscript11.1 KB
tests/test_powershell_hook_wire.pyscript10.6 KB
tests/test_powershell_verdict_corpus.pyscript6.2 KB
tests/test_pr44_hardening.pyscript6.5 KB
tests/test_pre_scan.pyscript19.6 KB
tests/test_pre_scan_composer.pyscript7.4 KB
tests/test_precondition_fields.pyscript4.6 KB
tests/test_provenance_offline.pyscript2.5 KB
tests/test_published_rulepack_feed_current.pyscript1.4 KB
tests/test_py38_compat.pyscript3.3 KB
tests/test_pypi_pinned_versions.pyscript19.3 KB
tests/test_pyproject_string_forms.pyscript2.2 KB
tests/test_redteam_fn_regression.pyscript32.5 KB
tests/test_reflective_fetch_execute.pyscript23.5 KB
tests/test_reflective_review_fixes.pyscript17.8 KB
tests/test_refresh_controller.pyscript19.9 KB
tests/test_refresh_rulepacks.pyscript12.4 KB
tests/test_review_gate_regressions.pyscript9.3 KB
tests/test_rule_loader.pyscript23.2 KB
tests/test_rulepack_feed.pyscript38.1 KB
tests/test_run_forensics_json.pyscript1012 B
tests/test_run_scanner_fail_loud.pyscript6.5 KB
tests/test_runtime_floors.pyscript19.8 KB
tests/test_sandbox_probing_rules.pyscript9.6 KB
tests/test_sarif_export.pyscript19.9 KB
tests/test_scan_agent_skills.pyscript31.3 KB
tests/test_scan_archive.pyscript11.6 KB
tests/test_scan_ast.pyscript12.8 KB
tests/test_scan_binary.pyscript15.3 KB
tests/test_scan_bytecode.pyscript21.5 KB
tests/test_scan_dast.pyscript32.1 KB
tests/test_scan_dataflow.pyscript7.1 KB
tests/test_scan_dead_anchors.pyscript11.5 KB
tests/test_scan_decode.pyscript28.0 KB
tests/test_scan_dependencies.pyscript37.8 KB
tests/test_scan_devcontainer.pyscript8.5 KB
tests/test_scan_entropy.pyscript11.2 KB
tests/test_scan_entrypoint.pyscript19.5 KB
tests/test_scan_git_config.pyscript58.5 KB
tests/test_scan_git_config_review_fixes.pyscript33.3 KB

tests/test_css_compounding_shrink.py

View on GitHub
"""Compounding font-size shrink check for HTML-like files (scan_sast)."""

import os
import sys

import pytest

SCRIPTS = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "scripts")
sys.path.insert(0, SCRIPTS)

import scan_sast  # noqa: E402


class TestCompoundingShrink:
    @staticmethod
    def _lines(tmp_path, text):
        f = tmp_path / "a.html"
        f.write_text(text)
        return [x.line for x in scan_sast.scan_css_steganography(str(f), "a.html")]

    def test_twenty_nested_08em_is_flagged(self, tmp_path):
        css = "<style>.nest{font-size:0.8em}</style>\n"
        assert self._lines(tmp_path, css + '<div class="nest">' * 20 + "x" + "</div>" * 20)

    def test_six_nested_06em_is_flagged(self, tmp_path):
        css = "<style>.n{font-size:0.6em}</style>\n"
        assert self._lines(tmp_path, css + '<div class="n">' * 6 + "x")

    def test_inline_style_chain_is_flagged(self, tmp_path):
        assert self._lines(tmp_path, '<div style="font-size:0.7em">' * 9 + "x")

    def test_single_and_sibling_repeats_are_clean(self, tmp_path):
        css = "<style>.nest{font-size:0.8em}</style>\n"
        assert not self._lines(tmp_path, css + '<div class="nest">x</div>')
        assert not self._lines(tmp_path, css + '<div class="nest">x</div>' * 8)

    def test_large_markup_is_linear(self, tmp_path):
        import time
        css = "<style>.nest{font-size:0.8em}</style>\n"
        start = time.perf_counter()
        self._lines(tmp_path, css + "<div>" * 150000)
        self._lines(tmp_path, css + "<a " * 150000)
        assert time.perf_counter() - start < 10


class TestCompoundingMarkup:
    @staticmethod
    def _lines(tmp_path, text, name="a.html"):
        f = tmp_path / name
        f.write_text(text)
        return [x.line for x in scan_sast.scan_css_steganography(str(f), name)]

    CSS = "<style>.s{font-size:0.6em}</style>\n"

    def test_data_class_is_not_a_class(self, tmp_path):
        assert not self._lines(tmp_path, "<style>.h{font-size:0.8em}</style>\n" + '<div data-class="h">' * 30)

    def test_unquoted_class_and_gt_in_attribute(self, tmp_path):
        assert self._lines(tmp_path, self.CSS + "<div class=s>" * 7)
        assert self._lines(tmp_path, self.CSS + '<div title="a>b" class="s">' * 7)


class TestCompoundingExponents:
    CSS = "<style>.s{font-size:0.6em}</style>\n"

    @staticmethod
    def _lines(tmp_path, text, name="a.html"):
        f = tmp_path / name
        f.write_text(text)
        return [x.line for x in scan_sast.scan_css_steganography(str(f), name)]

    @pytest.mark.parametrize("size", ["0.6e0em", "6e-1em", "+.6em"])
    def test_exponent_sizes_chain(self, tmp_path, size):
        css = "<style>.s{font-size:%s}</style>\n" % size
        assert self._lines(tmp_path, css + '<div class="s">' * 8)

    def test_no_font_word_skips_the_size_helpers(self, tmp_path):
        assert self._lines(tmp_path, "<p>" + "hello <b>x</b> " * 1000) == []


class TestCompoundingClassExponents:
    @staticmethod
    def _lines(tmp_path, text, name="a.html"):
        f = tmp_path / name
        f.write_text(text)
        return [x.line for x in scan_sast.scan_css_steganography(str(f), name)]

    @pytest.mark.parametrize("size,cls", [("6e-1em", "a"), ("6e1%", "a"), ("+.6em", "a")])
    def test_exponent_class_sizes(self, tmp_path, size, cls):
        css = "<style>.a{font-size:%s}</style>\n" % size
        assert self._lines(tmp_path, css + '<div class="a">' * 8)


class TestCompoundingLabel:
    @staticmethod
    def _found(tmp_path, text):
        f = tmp_path / "a.html"
        f.write_text(text)
        return scan_sast.scan_css_steganography(str(f), "a.html")

    def test_compounding_bound_is_a_labelled_low_finding(self, tmp_path):
        css = "<style>.n{font-size:0.8em}</style>\n"
        found = self._found(tmp_path, css + '<span class="n">' * 20 + 'x' + '</span>' * 20)
        assert [f.severity for f in found] == ["low"]
        assert "nesting estimated from tags" in found[0].title

    def test_few_small_items_stay_clean(self, tmp_path):
        css = "<style>.n{font-size:0.8em}</style>\n"
        assert not self._found(tmp_path, css + '<span class="n">' * 8 + 'x' + '</span>' * 8)


class TestCompoundingDeclarations:
    @staticmethod
    def _found(tmp_path, text):
        f = tmp_path / "a.html"
        f.write_text(text)
        return scan_sast.scan_css_steganography(str(f), "a.html")

    S = "<style>.s{font-size:0.8em}</style>"

    def test_entity_encoded_class_and_style_are_counted(self, tmp_path):
        assert self._found(tmp_path, self.S + '<div class="&#115;">' * 20)
        assert self._found(tmp_path, '<div style="font-size:&#48;.8em">' * 20)

    def test_important_and_later_declarations_do_not_hide_a_shrink(self, tmp_path):
        css = "<style>.s{font-size:0.8em!important;font-size:2em}</style>"
        assert self._found(tmp_path, css + '<div class="s">' * 20)

    def test_font_shorthand_is_counted(self, tmp_path):
        assert self._found(tmp_path, "<style>.s{font:0.8em sans-serif}</style>" + '<div class="s">' * 20)
        assert self._found(tmp_path, '<div style="font:0.8em/1.2 serif">' * 20)
        assert not self._found(tmp_path, '<div style="font:700 1em serif">' * 20)

    def test_class_and_style_on_one_element_count_once(self, tmp_path):
        text = self.S + '<div class="s" style="font-size:0.8em">' * 7
        assert not self._found(tmp_path, text)


class TestCompoundingSelectors:
    @staticmethod
    def _found(tmp_path, text):
        f = tmp_path / "a.html"
        f.write_text(text)
        return scan_sast.scan_css_steganography(str(f), "a.html")

    @pytest.mark.parametrize("name,text", [
        ("tag", "<style>span{font-size:.7em}</style>" + "<span>" * 8 + "x"),
        ("id", "<style>" + "".join("#i%d{font-size:.7em}" % i for i in range(8)) + "</style>"
         + "".join("<div id=i%d>" % i for i in range(8))),
        ("attr", "<style>[data-x]{font-size:.7em}</style>" + "<div data-x>" * 8),
        ("pseudo", "<style>.a:first-child{font-size:.7em}</style>" + "<div class=a>" * 8),
        ("escaped", "<style>.a\\:b{font-size:.7em}</style>" + '<div class="a:b">' * 8),
        ("hex-escape", "<style>.\\61 b{font-size:.7em}</style>" + '<div class="ab">' * 8),
        ("list", "<style>h1,.a,#z{font-size:.7em}</style>" + "<div class=a>" * 8),
        ("descendant", "<style>div .a{font-size:.7em}</style>" + "<div class=a>" * 8),
        ("calc", "" + '<div style="font-size:calc(.7em)">' * 8),
        ("smaller", '<div style="font-size:smaller">' * 16),
    ])
    def test_selector_forms_and_keywords_are_counted(self, tmp_path, name, text):
        assert self._found(tmp_path, text), name

    @pytest.mark.parametrize("text", [
        "<style>span{font-size:.7em}</style><span>x</span>",
        "<style>.a:not(.b){font-size:.7em}</style><div class=b>" * 1,
        '<div style="font-size:calc(1px + .7em)">' * 20,
        '<div style="font-size:var(--s)">' * 20,
        "<style>.a{font-size:.7em}</style>" + "<div class=other>" * 50,
    ])
    def test_unrelated_or_unfactorable_forms_stay_clean(self, tmp_path, text):
        assert not self._found(tmp_path, text)


class TestCompoundingSelectorForms:
    @staticmethod
    def _found(tmp_path, text):
        f = tmp_path / "a.html"
        f.write_text(text)
        return scan_sast.scan_css_steganography(str(f), "a.html")

    @pytest.mark.parametrize("name,text", [
        ("space", "<style>.a {font-size:.7em}</style>" + "<div class=a>" * 8),
        ("newline", "<style>.a\n{font-size:.7em}</style>" + "<div class=a>" * 8),
        ("comment", "<style>.a/* x */{font-size:.7em}</style>" + "<div class=a>" * 8),
        ("escaped-comma", "<style>.a\\,b{font-size:.7em}</style>" + '<div class="a,b">' * 8),
        ("smaller-short", "<style>.s{font:smaller sans-serif}</style>" + "<div class=s>" * 16),
        ("calc-short", "<style>.s{font:calc(.7em) serif}</style>" + "<div class=s>" * 8),
        ("italic-calc", '<div style="font:italic bold calc(.7em) serif">' * 8),
    ])
    def test_selector_trim_split_and_shorthand(self, tmp_path, name, text):
        assert self._found(tmp_path, text), name

    @pytest.mark.parametrize("text", [
        "<style>.a:not(.b,.c){font-size:.7em}</style>" + "<div class=c>" * 8,
        "<style>[hidden]{font-size:.7em}</style>" + "<div data-x=hidden>" * 8,
        '<style>[title="a,b"]{font-size:.7em}</style>' + "<div class=b>" * 8,
    ])
    def test_top_level_comma_and_attribute_values_are_not_names(self, tmp_path, text):
        assert not self._found(tmp_path, text)

    def test_subject_keys_trim_and_split(self):
        assert scan_sast._subject_keys(".a ") == [("class", "a")]
        assert scan_sast._split_selector_list(".a:not(.b,.c),.d") == [".a:not(.b,.c)", ".d"]
        assert scan_sast._split_selector_list(".a\\,b,.c") == [".a\\,b", ".c"]


class TestCompoundingDecoys:
    @staticmethod
    def _found(tmp_path, text):
        f = tmp_path / "a.html"
        f.write_text(text)
        return scan_sast.scan_css_steganography(str(f), "a.html")

    A = "<style>.a{font-size:.7em}</style>"

    @pytest.mark.parametrize("name,text", [
        ("title-decoy-before", A + '<div title="class=other" class=a>' * 8),
        ("comment-in-style", '<div style="font-size:/**/.7em">' * 8),
        ("ns-empty", "<style>[|data-x]{font-size:.7em}</style>" + "<div data-x>" * 8),
        ("ns-star", "<style>[*|data-x]{font-size:.7em}</style>" + "<div data-x>" * 8),
        ("ns-named", "<style>[ns|data-x]{font-size:.7em}</style>" + "<div data-x>" * 8),
        ("size-after-style", "<style>.a{font:italic 700 .7em/1.2 serif}</style>" + "<div class=a>" * 8),
    ])
    def test_decoys_comments_and_namespaces(self, tmp_path, name, text):
        assert self._found(tmp_path, text), name

    @pytest.mark.parametrize("text", [
        A + '<div title="class=a">' * 8,
        '<div title="style=font-size:.7em">' * 8,
        "<style>.a{font:16px/.7em serif}</style>" + "<div class=a>" * 8,
        "<style>.a{font:16px smaller}</style>" + "<div class=a>" * 16,
        '<div style="font:16px/calc(.7em) serif">' * 8,
        '<div style="content:\'font-size:.7em\'">' * 8,
    ])
    def test_attribute_values_and_later_shorthand_slots_do_not_count(self, tmp_path, text):
        assert not self._found(tmp_path, text)


class TestCompoundingBlocksAndCaps:
    @staticmethod
    def _found(tmp_path, text):
        f = tmp_path / "a.html"
        f.write_text(text)
        return scan_sast.scan_css_steganography(str(f), "a.html")

    @pytest.mark.parametrize("css", [
        ".a{font-size:70%;&.b{color:red}}",
        ".a{&.b{color:red}font-size:70%}",
        ".a{@media screen{color:red}font-size:70%}",
        ".a{f\\6fnt-size:70%}",
        ".a{font-size:7\\30 %}",
    ])
    def test_nested_blocks_and_escapes(self, tmp_path, css):
        assert self._found(tmp_path, "<style>" + css + "</style>" + "<div class=a>\n" * 14)

    def test_input_caps_report_instead_of_dropping(self, tmp_path):
        big = " " * 3_000_000 + "<style>.a{font-size:70%}</style>" + "<div class=a>\n" * 14
        assert any("too large" in f.title for f in self._found(tmp_path, big))
        wide = "<style>.a{font-size:70%}</style><div " + "x=1 " * 6000 + "class=a>\n"
        assert any("too large" in f.title for f in self._found(tmp_path, wide))


class TestReviewRound1:
    @staticmethod
    def _found(tmp_path, text, name="a.html"):
        f = tmp_path / name
        f.write_text(text)
        return scan_sast.scan_css_steganography(str(f), name)

    def test_jsx_classname_counts_as_class(self, tmp_path):
        css = "<style>.s{font-size:0.6em}</style>\n"
        assert self._found(tmp_path, css + '<div className="s">' * 8, "a.jsx")

    @pytest.mark.parametrize("style", [
        "style={{fontSize: '0.7em'}}",
        "style={{ 'font-size': '70%' }}",
        'style={{"font-size": "0.7em"}}',
    ])
    def test_jsx_style_objects_count(self, tmp_path, style):
        assert self._found(tmp_path, "<div %s>" % style * 9, "a.tsx")

    def test_long_selector_list_is_not_dropped(self, tmp_path):
        pad = ",".join(".x%d" % i for i in range(400))      # well over 1000 characters
        css = "<style>%s,.s{font-size:0.6em}</style>\n" % pad
        assert self._found(tmp_path, css + '<div class="s">' * 8)

    @pytest.mark.parametrize("where", ["style-block", "inline-style"])
    def test_long_digit_runs_are_linear(self, tmp_path, where):
        import time
        digits = "1" * 60000
        if where == "style-block":
            text = "<style>.a{font-size:%sem}</style>\n<div class=a>" % digits
        else:
            text = '<div style="font-size:%sem">' % digits
        start = time.perf_counter()
        self._found(tmp_path, text)
        self._found(tmp_path, "<style>.a{font:bold %sem x}</style>" % digits)
        assert time.perf_counter() - start < 2.0

    def test_entity_encoded_font_word_still_reaches_the_check(self, tmp_path):
        assert self._found(tmp_path, '<div style="&#102;ont-size:0.7em">' * 9)

    def test_compound_selector_needs_every_key(self, tmp_path):
        css = "<style>td.small{font-size:0.6em}</style>\n"
        assert not self._found(tmp_path, css + "<td>x</td>" * 40 + '<td class="small">y</td>')
        assert self._found(tmp_path, css + '<td class="small">' * 8 + 'y' + '</td>' * 8)

    def test_attribute_compound_does_not_count_every_tag(self, tmp_path):
        css = "<style>a[href^=http]{font-size:0.6em}</style>\n"
        assert not self._found(tmp_path, css + "<a>x</a>" * 40 + '<a href="http://x">y</a>')
        assert self._found(tmp_path, css + '<a href="http://x">' * 8 + 'y' + '</a>' * 8)

    def test_many_compounds_on_one_key_stay_bounded(self, tmp_path):
        import time
        rules = "".join("div.c%d{font-size:0.9em}" % i for i in range(3000))
        start = time.perf_counter()
        self._found(tmp_path, "<style>%s</style>\n" % rules + '<div class="c1">' * 20000)
        assert time.perf_counter() - start < 5.0

    RULE = "<style>.s{font-size:0.5em}</style>\n"
    ELEMS = '<p class="s">' * 30 + 'x' + '</p>' * 30

    def test_commented_style_rule_is_not_live(self, tmp_path):
        assert not self._found(tmp_path, "<!-- " + self.RULE + "-->\n" + self.ELEMS)

    def test_commented_elements_are_not_counted(self, tmp_path):
        assert not self._found(tmp_path, self.RULE + "<!-- " + self.ELEMS + " -->")

    @pytest.mark.parametrize("tag", ["script", "textarea", "template", "title", "noscript"])
    def test_inert_bodies_are_not_counted(self, tmp_path, tag):
        body = "<%s>%s</%s>" % (tag, self.ELEMS, tag)
        assert not self._found(tmp_path, self.RULE + body)

    def test_controls_and_live_rules_still_flag(self, tmp_path):
        assert not self._found(tmp_path, self.RULE.replace("0.5em", "0.9em") + '<p class="s">x</p>' * 5)
        assert self._found(tmp_path, self.RULE + self.ELEMS)
        assert self._found(tmp_path, "<style><!-- .s{font-size:0.5em} --></style>\n" + self.ELEMS)
        assert self._found(tmp_path, "<!-- c -->" + self.RULE + self.ELEMS)

    def test_fake_style_inside_a_comment_is_not_style_context(self, tmp_path):
        prefix = "<!-- <style> --><!-- .s{font-size:0.5em} -->"
        assert not self._found(tmp_path, prefix + self.ELEMS)

    NEST = '<span class="small">' * 8 + "ordinary text" + "</span>" * 8
    SMALL = "<style>.small{font-size:.7em}</style>"

    def test_rules_inside_inert_bodies_do_not_leak(self, tmp_path):
        tpl = '<template id="p">' + self.SMALL + "<p>x</p></template>\n"
        assert not self._found(tmp_path, tpl + self.NEST)
        scr = '<script type="text/plain">.small{font-size:.7em}</script>\n'
        assert not self._found(tmp_path, scr + self.NEST)

    def test_nested_template_is_tracked_by_depth(self, tmp_path):
        doc = self.SMALL + "\n<template><template></template>" + self.NEST + "</template>"
        assert not self._found(tmp_path, doc)
        assert self._found(tmp_path, self.SMALL + "\n" + self.NEST)

    @pytest.mark.parametrize("prefix", [
        '<script>const t = "<style>";</script>\n<!-- .small{font-size:.7em} -->\n',
        '<div data-example="<style>"></div>\n<!-- .small{font-size:.7em} -->\n',
    ])
    def test_style_text_in_script_or_attribute_is_not_a_marker(self, tmp_path, prefix):
        assert not self._found(tmp_path, prefix + self.NEST)

    def test_comment_open_in_script_does_not_hide_a_live_style(self, tmp_path):
        doc = '<script>const c = "<!--";</script>\n' + self.SMALL + "\n" + self.NEST
        assert self._found(tmp_path, doc)

    INNER = '<span style="font-size:0.5em">' * 12 + "x" + "</span>" * 12

    def test_vue_top_level_template_is_live(self, tmp_path):
        p = tmp_path / "App.vue"
        p.write_text("<template>" + self.INNER + "</template>")
        assert [f for f in scan_sast.scan_css_steganography(str(p), "App.vue") if "compounding" in f.title]

    @pytest.mark.parametrize("tag", ["title", "script", "textarea", "noscript", "template"])
    def test_unclosed_mention_does_not_blank_to_eof(self, tmp_path, tag):
        doc = "Use the <%s> tag.\n" % tag + self.INNER
        assert self._found(tmp_path, doc)

    @pytest.mark.parametrize("tag", ["script", "template", "textarea", "title", "noscript"])
    def test_many_unclosed_tags_are_linear(self, tag):
        import time
        text = ("<%s>" % tag) * 200000
        start = time.perf_counter()
        scan_sast._blank_dead_markup(text)
        assert time.perf_counter() - start < 2.0

    def test_inert_regions_survive_an_unclosed_template_mention(self, tmp_path):
        head = "Use the <template> tag.\n"
        assert not self._found(tmp_path, head + "<!-- " + self.INNER + " -->")
        for tag in ("script", "textarea", "title", "noscript"):
            body = "<%s>%s</%s>" % (tag, self.INNER, tag)
            assert not self._found(tmp_path, head + body), tag
        assert self._found(tmp_path, head + self.INNER)

    def test_live_jsx_next_to_comment_openers_in_strings_still_flags(self, tmp_path):
        p = tmp_path / "S.tsx"
        spans = '<span style={{fontSize: "50%"}}>' * 6 + "x" + "</span>" * 6
        p.write_text("const re = '{/*';\nexport const C = () => (<div>" + spans + "</div>);\nconst c = '*/}';\n")
        assert [f for f in scan_sast.scan_css_steganography(str(p), p.name) if "compounding" in f.title]


class TestSiblingsDoNotCompound:
    """Nesting is estimated from open/close tags (2.14.16 review B1): the common
    docs pattern of a `code{font-size:85%}` rule plus many inline <code> tags is
    siblings, not a chain, and must stay clean."""

    CSS = "<style>code{font-size:85%}</style>\n"

    @staticmethod
    def _found(tmp_path, text):
        f = tmp_path / "a.html"
        f.write_text(text)
        return scan_sast.scan_css_steganography(str(f), "a.html")

    def test_twenty_sibling_code_tags_do_not_flag(self, tmp_path):
        body = "<p>see <code>x</code></p>\n" * 20
        assert not self._found(tmp_path, self.CSS + body)

    def test_twenty_nested_code_tags_flag(self, tmp_path):
        body = "<code>" * 20 + "x" + "</code>" * 20
        found = self._found(tmp_path, self.CSS + body)
        assert [f.severity for f in found] == ["low"]
        assert "nesting estimated from tags" in found[0].title

    def test_unclosed_elements_still_compound(self, tmp_path):
        assert self._found(tmp_path, self.CSS + "<code>x" * 20)

    def test_void_and_self_closed_elements_never_nest(self, tmp_path):
        css = "<style>.s{font-size:0.5em}</style>\n"
        assert not self._found(tmp_path, css + '<img class="s">' * 20)
        assert not self._found(tmp_path, css + '<span class="s"/>' * 20)


class TestInputTooLargeNeedsEvidence:
    """'input too large to verify' fires only with a shrinking size seen or
    `font` in the unread tail (2.14.16 review B2)."""

    @staticmethod
    def _found(tmp_path, text):
        f = tmp_path / "big.html"
        f.write_text(text)
        return scan_sast.scan_css_steganography(str(f), "big.html")

    def test_big_benign_html_without_font_sizes_is_clean(self, tmp_path):
        body = "<p>plain paragraph of ordinary text</p>\n" * 80000
        assert len(body) > 3_000_000
        # 'font' appears in the read part (a font-family rule), never a shrink.
        text = "<style>body{font-family:sans-serif}</style>\n" + body
        assert not self._found(tmp_path, text)

    def test_big_html_with_shrinking_rule_past_the_limit_still_flags(self, tmp_path):
        body = "<p>plain paragraph of ordinary text</p>\n" * 80000
        text = "<style>body{font-family:sans-serif}</style>\n" + body + "<style>.s{font-size:0.5em}</style>\n"
        found = self._found(tmp_path, text)
        assert [f.title for f in found] == ["CSS hiding: possible compounding shrink (input too large to verify)"]

    def test_big_html_with_shrinking_rule_in_read_part_flags(self, tmp_path):
        body = "<p>plain paragraph of ordinary text</p>\n" * 80000
        text = "<style>.s{font-size:0.9em}</style>\n" + body
        found = self._found(tmp_path, text)
        assert [f.title for f in found] == ["CSS hiding: possible compounding shrink (input too large to verify)"]
rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first.Stars: 194kUpdated Claude CodeCodexVerifiedInstall