Metadata-Version: 2.4
Name: cloaked
Version: 0.1.0
Summary: Show agents what humans can't see
Keywords: prompt-injection,html,security,llm-agents,web-scraping
Author: JaiSuryaPrabu
Author-email: JaiSuryaPrabu <106684947+JaiSuryaPrabu@users.noreply.github.com>
License-Expression: Apache-2.0
License-File: LICENSE
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Security
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Dist: selectolax>=0.4.11
Requires-Python: >=3.13
Project-URL: Homepage, https://github.com/node-and-edge/cloaked
Project-URL: Repository, https://github.com/node-and-edge/cloaked
Project-URL: Issues, https://github.com/node-and-edge/cloaked/issues
Description-Content-Type: text/markdown

# cloaked

**Show agents what humans can't see.**

`cloaked` finds content that is present in a page's HTML but invisible to a
human reading it — and reports it. It does not judge, block, or sanitize. It
makes the gap between "what the page shows" and "what an agent reads" visible.

A human opening a web page sees a rendered document. An agent consuming that
page sees the extracted text — including everything the rendering hid.
`cloaked` reports the difference between those two views, deterministically,
offline, with no model and no network access.

This is an **awareness layer**, not a security scanner. "This span is
invisible to a human" is a verifiable, factual claim. "This span is an
attack" is not — that judgment belongs to semantic classifiers that run on
extracted text. `cloaked` runs *before* extraction and hands them a signal
they structurally cannot recover on their own.

## Install

```bash
pip install cloaked
```

## Usage

```python
import cloaked

report = cloaked.scan(html)

if report.has_findings:
    for finding in report.findings:
        print(finding.rule_id, finding.mechanism, finding.text)
```

Optional configuration, all keyword-only:

```python
cloaked.scan(
    html,
    rules=["CLK001", "CLK004"],   # allowlist; default = all
    min_text_length=8,            # ignore trivially short spans
)
```

For callers that just want the human-visible text with concealed content
stripped out:

```python
visible_text = cloaked.visible_only(html)   # -> str
```

That's the whole surface. Two functions.

## Output schema

```python
@dataclass(frozen=True)
class Finding:
    rule_id: str        # "CLK001"
    mechanism: str       # "display:none"
    text: str            # the hidden text itself
    selector: str        # best-effort CSS path to the element
    line: int | None     # source line, if determinable

@dataclass(frozen=True)
class Report:
    findings: tuple[Finding, ...]
    has_findings: bool
    hidden_char_count: int
    visible_char_count: int
```

`hidden_char_count` / `visible_char_count` are included because the *ratio*
is a useful single-number signal for callers who don't want to inspect every
finding.

## Detection classes

Each rule has a stable ID so callers can allow/deny individually.

| ID | Class | Detects |
| --- | --- | --- |
| `CLK001` | CSS invisibility | `display:none`, `visibility:hidden`, `opacity:0` |
| `CLK002` | Zero/near-zero sizing | `font-size:0`, zero width/height, `clip`/`clip-path`, clipped 1px containers |
| `CLK003` | Off-screen positioning | Absolute/fixed positioning far outside the viewport, `text-indent` pushes |
| `CLK004` | Color camouflage | Text color matching or near-matching its background (WCAG contrast ratio) |
| `CLK005` | Markup-only content | HTML comments containing prose |
| `CLK006` | Attribute-carried text | Prose stuffed into `alt`, `title`, `aria-label`, `data-*` |
| `CLK007` | Unicode concealment | Zero-width characters, bidi override/isolate control characters |

## Known limitations

These are honest constraints, not bugs — the package's credibility depends
on stating them plainly.

- **Inline and `<style>`-block CSS only.** External stylesheets are never
  fetched (no network access, by design), so concealment applied via an
  external sheet is missed.
- **No cascade resolution.** Specificity conflicts and inherited styles are
  approximated, not computed the way a rendering engine would.
- **No JavaScript execution.** Content hidden or revealed at runtime is
  invisible to this tool.
- **Detects concealment, not intent.** Hidden text is a signal, not proof.
  An attacker using *visible* text walks straight past this tool entirely —
  that's out of scope by design; deciding what's malicious is the semantic
  scanner's job, not this one's.

## Dependency policy

Runtime dependencies are Python's stdlib plus one HTML parser
([`selectolax`](https://github.com/rushter/selectolax)) — nothing else,
ever. If a future feature needs another runtime dependency, it ships behind
an optional extra (`cloaked[...]`) or it doesn't ship. Python 3.13+.

## Development

```bash
uv sync
uv run pytest
uv run ruff check src tests
uv run mypy --strict src
```

The test suite is corpus-driven: `tests/corpus/` holds hand-labeled real-world
HTML samples (concealed and ordinary pages), and `tests/test_false_positives.py`
checks every rule against that ground truth — the number that actually
matters is the false-positive rate on ordinary pages, not the catch rate on
purpose-built test cases.
