Metadata-Version: 2.5
Name: orion-verify
Version: 0.5.0
Summary: ORION Model: self-hosted domain ownership verification and browser anti-abuse SDK
Project-URL: Homepage, https://github.com/testfkij/orion-model
Project-URL: Documentation, https://github.com/testfkij/orion-model#readme
Project-URL: Repository, https://github.com/testfkij/orion-model
Project-URL: Issues, https://github.com/testfkij/orion-model/issues
Author: ORION Model contributors
License-Expression: MIT
License-File: LICENSE
Keywords: anti-abuse,browser,domain-ownership,orion-model,privacy,self-hosted,starlette,verification
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
Classifier: Topic :: Security
Requires-Python: >=3.11
Requires-Dist: dnspython<3,>=2.6
Requires-Dist: httpx<1,>=0.27
Requires-Dist: sqlalchemy<3,>=2.0
Requires-Dist: starlette<1,>=0.40
Requires-Dist: uvicorn<1,>=0.30
Provides-Extra: postgres
Requires-Dist: psycopg[binary]<4,>=3.2; extra == 'postgres'
Provides-Extra: test
Requires-Dist: httpx<1,>=0.27; extra == 'test'
Requires-Dist: pytest<9,>=8; extra == 'test'
Description-Content-Type: text/markdown

<!-- Docs reviewed: 2026-10-18; update this date and related docs with every code/security/API change. -->

# ORION Model

**Formerly ORION Verify.** The Python import namespace and existing `orion-verify` distribution name are retained for compatibility during the branding transition.

**Self-hosted browser verification for Python websites.** Run the API and PostgreSQL on infrastructure you control; there is no mandatory ORION-hosted dashboard or central account.

> **Alpha software (0.5.0).** This project has not received an independent security audit. Do not use it as the only access-control layer for payments, account recovery, sensitive data, or other high-risk actions. See [SECURITY.md](SECURITY.md). Proof-of-work raises automation cost; it does **not** prove that a visitor is human.

## What is included

- Starlette ASGI service, PostgreSQL persistence, and an installable Python SDK.
- `orion-model`, `orion`, and `orion-verify` CLI aliases; `orion-model verify example.com` checks DNS ownership for a domain already registered on this server.
- `orion-model init` / `orion-verify init` create private local configuration; `orion-model check --database` checks setup; `orion-model cleanup` removes expired rows during maintenance.
- DNS TXT ownership verification before a site key becomes active.
- Up to three registered site keys by default, including keys waiting for ownership verification.
- Signed short-lived tokens, site/audience binding, database-backed single redemption, and atomic daily quota increments on SQLite/PostgreSQL.
- Default limits of 30 issued tokens and 120 challenge requests per source IP per UTC day. The proof-of-work difficulty defaults to 16 bits and is configurable (12–20 bits); this is an abuse-cost signal, not proof of humanity.
- Origin allowlisting, bounded request bodies, conservative HTTP defaults, hardened SDK network timeouts, Docker Compose, automated tests, and GitHub Actions build workflows.

## Install

### Local source / GitHub

```bash
python -m venv .venv
# Linux/macOS/Termux: source .venv/bin/activate
# Windows PowerShell: .venv\Scripts\Activate.ps1
python -m pip install --upgrade pip
python -m pip install "orion-verify[test] @ git+https://github.com/testfkij/orion-model.git"
```

### From PyPI

The distribution keeps its existing name for compatibility while the product is rebranded. The existing TestPyPI alpha can be installed with the supplied command:

```bash
python -m pip install -i https://test.pypi.org/simple/ orion-verify==0.4.0
```

For the updated local source, use the GitHub/source install above. Version 0.5.0 must not be considered published until the package index confirms it.

Package availability depends on the project’s release status and the name being available on PyPI; a GitHub build does not itself publish a PyPI release. Releases are intended to be built and validated by GitHub Actions before a trusted-publishing workflow is enabled.

## Fastest local start

```bash
python -m pip install orion-verify
orion quick-start
```

The command creates a private `.env` when one does not exist and runs the API on **127.0.0.1:8000**. It never overwrites an existing `.env`. Press Ctrl+C to stop it. In local development only, SQLite is used by default.

Useful alternatives:

```bash
orion quick-start --no-run
orion quick-start --host 127.0.0.1 --port 8080
orion-verify init
orion check --database
orion-model verify example.com
orion cleanup --retention-days 7
```

Check the health endpoint:

```bash
curl --fail --show-error http://127.0.0.1:8000/health
```

## Production deployment with PostgreSQL

1. Install Docker Engine and Docker Compose on a server you administer.
2. In the project directory, copy `.env.example` to `.env` and use unique secrets. `orion-verify init` can generate a private config file; configure the database URL for PostgreSQL.
3. Set `POSTGRES_PASSWORD` to a long URL-safe random value in the shell/environment used for Compose. Keep it out of source control and terminal screenshots.
4. Run from the project root:

   ```bash
   docker compose -f deploy/docker-compose.yml up --build -d
   docker compose -f deploy/docker-compose.yml logs -f api
   ```

5. Put a trusted HTTPS reverse proxy in front of the API. The Compose example binds port 8000 to loopback only; it does not expose PostgreSQL. Configure database backups, monitoring, host firewall and patching.
6. Keep the admin endpoint reachable only through the loopback/management network. The default `ORION_ADMIN_ALLOWED_CIDRS` permits loopback only; do not widen it to `0.0.0.0/0`.

For PostgreSQL, use a URL-safe password or percent-encode reserved characters correctly in `ORION_DATABASE_URL`. Do not expose the database port to the public internet.

## Register and verify your domain

The admin endpoint expects a private management request with the `X-ORION-Admin-Key` header. In a trusted shell, load your config without displaying it: `set -a; . ./.env; set +a`. Replace placeholders and use your own service URL/domain:

```bash
curl --fail-with-body --silent --show-error \
  -X POST 'http://127.0.0.1:8000/v1/admin/sites' \
  -H 'Content-Type: application/json' \
  -H "X-ORION-Admin-Key: ${ORION_ADMIN_SECRET}" \
  --data '{"domain":"example.com","server_ip":"203.0.113.10"}'
```

The response includes a public `site_key`, a private one-time `server_secret`, and a DNS TXT record name/value. **Save the server secret securely and never put it in HTML, JavaScript, mobile apps, or public repositories.** Publish the exact TXT record at `_orion-verify.example.com`, wait for DNS to propagate, then request activation from the same private management network:

```bash
curl --fail-with-body --silent --show-error \
  -X POST 'http://127.0.0.1:8000/v1/admin/sites/verify' \
  -H 'Content-Type: application/json' \
  -H "X-ORION-Admin-Key: ${ORION_ADMIN_SECRET}" \
  --data '{"site_key":"or_pub_YOUR_SITE_KEY"}'
```

A site key remains inactive until the server finds the exact TXT value. Remove the DNS TXT record after successful activation if you no longer need it. DNS ownership checks require outbound DNS resolution from the server. The `server_ip` field is recorded as administrator-supplied metadata; it is not used as the visitor IP for quota enforcement. After registration and DNS propagation, run `orion-model verify example.com` on the ORION Model host. It reports whether the domain is registered, pending, or active; it does not print or reconstruct the one-time TXT value.

### Key separation — do not mix these up

- `ORION_MASTER_SECRET`: only on the ORION Model API host; signs tokens and hashes identifiers. Never share it with the website backend, browser, or client module.
- `ORION_ADMIN_SECRET`: only in the trusted management environment; required for site registration, activation, and revocation. Keep the management endpoints on loopback/private networks.
- Per-site `server_secret`: private credential returned once when registering a site. Store it only in the protected website backend as `ORION_SERVER_SECRET`; it authorizes server-to-server token redemption.
- `site_key`: public identifier that may appear in website HTML. It is not a secret and grants no right to redeem a token.

The current project has no end-user account system. To secure signup/account creation in your own application, redeem the short-lived token server-to-server before creating the account and then run your own email/identity, CSRF, authorization, and abuse checks. Never create an account because a browser event alone fired.

## Embed on a website

Host the widget API over HTTPS, then add this to the page where the verification control should appear:

```html
<div data-orion-verify></div>
<script
  src="https://verify.example.net/widget.js"
  data-api="https://verify.example.net"
  data-sitekey="or_pub_YOUR_SITE_KEY"
  defer
></script>
```

Listen for `orion-verified` and send the token to **your own HTTPS backend**. Do not grant access based only on browser-side events. The backend must call ORION’s server-to-server siteverify endpoint using the private server secret, and it must also enforce its own authorization rules. Use [`Codes.md`](Codes.md) for the canonical codebook, HTML/JavaScript embed helper, server-side connection module, account-creation integration patterns, and raw HTTP/FastAPI/Flask/Django/React examples.

## Python SDK

```python
from orion_verify import VerifyClient

client = VerifyClient(
    base_url="https://verify.example.net",
    server_secret="YOUR_PRIVATE_SERVER_SECRET",
    timeout=5.0,
)

result = client.verify(token_from_your_request, site_key="or_pub_YOUR_SITE_KEY")
if not result.success:
    raise PermissionError("Verification required")
```

The SDK requires HTTPS except for loopback development URLs, keeps TLS certificate validation on, does not follow redirects, and uses bounded timeouts. Treat network errors and non-success HTTP responses as failed verification. `await client.verify_async(token, site_key)` is also supported. Do not use the server secret from untrusted clients.

## HTTP/security behavior

- JSON API requests are size-limited (default 16 KiB); oversized requests return HTTP 413.
- Site origins are checked against active registered domains. Explicitly allow only the real website origin; no wildcard `*` CORS configuration is used.
- Admin endpoints require both a configured network CIDR and `X-ORION-Admin-Key`. `POST /v1/admin/sites/revoke` invalidates an active site key and its outstanding challenges/tokens.
- `/v1/siteverify` is server-to-server and uses `Authorization: Bearer ...`; browser-origin requests are rejected.
- Verification tokens expire, bind to one site, and can be redeemed exactly once.
- Token quota counts successful token issuance; a separate atomic daily challenge-request quota limits how often one IP can request challenges. Each valid challenge is consumed before proof validation, including failed proof attempts, so a single nonce cannot be guessed repeatedly.
- The app ignores `X-Forwarded-For` unless `ORION_TRUSTED_PROXY_CIDRS` explicitly lists the direct proxy peer. Configure the proxy to append/overwrite the header safely and block direct public access when enabling this option; never trust arbitrary forwarding headers.

## Further documentation

- [Security review, warning levels, and hardening plan](SECURITY_AUDIT.md)
- [All integration code and module explanations](Codes.md)
- [ORION Model rebrand and release announcement](ANNOUNCEMENT.md)

- [Architecture and trust boundaries](ARCHITECTURE.md)
- [HTTP API reference](API_REFERENCE.md)
- [Security policy and threat model](SECURITY.md) and [threat model details](THREAT_MODEL.md)
- [Image licensing and asset guidance](IMAGES.md)
- [Release checklist](RELEASE_CHECKLIST.md)
- [Contributing](CONTRIBUTING.md) and [changelog](CHANGELOG.md)

## Project files

- `src/orion_verify/` — package, HTTP application, security logic, SDK, CLI and widget.
- `widget/widget.js` — editable standalone copy of the browser widget.
- `Codes.md` — canonical integration codebook. `code.md` remains as a backward-compatible pointer.
- `ANNOUNCEMENT.md` — product rebrand and release-status statement.
- `SECURITY.md` — threat model and pre-production gates.
- `deploy/docker-compose.yml` and `Dockerfile` — container packaging.
- `.github/workflows/` — test and wheel-build/release workflows.

## Development and tests

```bash
python -m pip install -e '.[test]'
python -m compileall -q src tests
python -m pytest -q
python -m build
```

The suite includes service, token replay, one-attempt proof, quota, origin, API input, client, CLI, and integration-helper checks. Use a staging deployment for database-engine concurrency tests, dependency and secret scans, browser accessibility/compatibility tests, backups/restore drills, and an independent external security audit before production. Retention cleanup is intentionally not run on public requests; schedule `orion cleanup --retention-days 7` as a maintenance job. Existing databases receive an additive `daily_quotas.challenge_requests` migration at startup. Future non-additive schema changes should use versioned migrations.

## License

MIT. See [`LICENSE`](LICENSE).

## Privacy-conscious anti-abuse and extensions

The widget does **not** use a fake "I'm not a robot" checkbox, third-party browser fingerprint SDK, or tracking cookies. It uses a user-triggered, time-bounded proof-of-work challenge and server-side controls. The service derives a keyed/hashed IP identifier for quotas; the source IP is still processed by the network stack, so disclose this processing in your privacy notice and set retention appropriately. Do not use browser fingerprinting as an identity proof. Any bot signal can be spoofed, so use layered rate limiting and enforce authorization on your own server.

For DDoS resilience, put the service behind a reputable CDN/WAF or hosting DDoS protection, apply edge rate limits to challenge and verification routes, set connection/body/header/time limits at the reverse proxy, cap worker concurrency, restrict admin routes to private networks, monitor 429/5xx and database pool saturation, and keep backups. Application quotas alone cannot stop volumetric attacks or TLS/connection exhaustion. Do not try to bypass another service's DDoS controls; test only your own local/staging deployment at a fixed low rate.

### Extension manager (experimental)

```bash
orion --get https://github.com/OWNER/REPO/tree/main/path/to/extension
orion --uninstall extension-name
# Non-interactive confirmation only when you intentionally want it:
orion --get https://github.com/OWNER/REPO/tree/main/path/to/extension --yes
orion --uninstall extension-name --yes
```

The installer shows the GitHub source, declared owner/version, size, available storage, and a risk warning, then asks `y/N` unless `--yes` is supplied. Extensions are placed under `~/.orion-model/extensions/`; the installer does not execute extension code or automatically install its dependencies. It accepts only a bounded set of file types, up to 500 files / 20 MiB, rejects symlinks and hidden files, and rejects NUL-containing content in text/script files. This is a file filter, not a malware scanner or guarantee that allowed files are safe. Review every extension and pin/audit dependencies before running anything manually. `extension.json` may declare `owner`, `version`, and `description`, but these fields are self-reported and are not verified identity. Extension authors are responsible for maintenance, updates, compatibility, and security. Uninstall prompts before deletion by default. See [`Codes.md`](Codes.md) for the manifest and lifecycle.

A review-first, framework-neutral anti-spam extension example is included at `examples/extensions/orion-antispam/`. It produces signals for moderation rather than automatically banning users. Adapt it to your bot framework and test against false positives before deployment.
