Skip to main content

ragleap-security

Small, auditable security primitives for the ragleap libraries. The core is standard library only; encryption is an optional extra. Alpha. Not independently audited: see docs/threat-model.md for exactly what is and is not defended.

What is in 0.3.0

From 0.1.0:

  • Scope: an immutable tenant scope (tenant, subject, agent, session) with an unambiguous key, covers, narrow and require_scope, so stores can refuse to work without one.
  • AuditLog: an append-only JSON Lines log with a SHA-256 hash chain and verify(). Tamper-evident, not tamper-proof (see the threat model).
  • SecretStr, from_env, redact: secrets that do not print themselves, read from the environment by name, and a heuristic redactor for logs.
  • check_size, check_json_shape, bounded_read, Deadline: hard limits for untrusted input.

New in 0.2.0:

  • Key, KeyRing: a 32-byte key with an id that never prints its value, and a ring of keys for rotation.
  • ragleap_security.crypto (needs pip install ragleap-security[crypto]): encrypt, decrypt, encrypt_with_passphrase, decrypt_with_passphrase, reencrypt, key_id. AES-256-GCM through the cryptography package, a versioned envelope, and a context (for example a Scope) that must match on decrypt.
  • RateLimiter, SQLiteRateLimiter: a token bucket per key, in memory or shared between processes on one machine. They refuse when they cannot decide.
  • build_manifest, verify_manifest, Manifest, file_digest: detect that files changed, with an optional HMAC so the manifest itself cannot be edited unnoticed.

New in 0.3.0 (standard library only, imported on its own):

  • ragleap_security.net: SafeFetcher, FetchPolicy. Outbound HTTP (GET and HEAD) that an attacker cannot point at your own network: a per-tenant host allowlist (deny by default), strict URL parsing, every resolved address checked, the connection pinned to the checked address, redirects re-checked on every hop, one deadline, a body cap, TLS verification always on, no proxy from the environment. Every refusal is a fixed reason code; the audit record never holds a path, query, header or body.

    fetcher = SafeFetcher(lambda scope: FetchPolicy(allow_hosts=("api.example.com",)), audit=log) res = fetcher.get(Scope("acme"), "https://api.example.com/v1/items") # NetError(reason) on any refusal

Nothing in 0.1.0 or 0.2.0 changed. The new modules are additive.

Examples

Encrypt data for one tenant and rotate keys:

from ragleap_security import Key, KeyRing, Scope
from ragleap_security.crypto import decrypt, encrypt, reencrypt

scope = Scope("acme", subject="alice")
old = Key.generate("2026-10")
box = encrypt(old, b"private notes", scope)           # the scope is authenticated too
assert decrypt(old, box, scope) == b"private notes"   # a different scope would fail

new = Key.generate("2026-11")
ring = KeyRing([new, old])                             # the first key is active
box = reencrypt(ring, box, scope)                      # now encrypted with "2026-11"

Keys come from the environment by variable name (base64), never from code:

key = Key.from_env("MY_APP_KEY", "2026-11")

Rate limit by scope:

from ragleap_security import RateLimiter, Scope

limiter = RateLimiter(rate=5, burst=10)               # 5 per second, bursts of 10
limiter.require(Scope("acme", subject="alice"))       # raises RateLimitError when refused

Detect changed files:

from ragleap_security import Key, build_manifest, verify_manifest

key = Key.from_env("MY_APP_KEY", "manifest")
manifest = build_manifest("app/", key=key, exclude=["__pycache__"])
result = verify_manifest("app/", manifest, key=key, exclude=["__pycache__"])
assert result.ok, (result.changed, result.missing, result.extra)

What this does not do

Encryption does not protect data while the program is running, and does not help against someone who has the key. Rate limits do not stop attacks spread over many machines. An integrity check detects changes; it does not prevent anyone from copying your code, models or data. The threat model lists the rest.

Verifying it yourself

pip install -e ".[test,crypto]"
pytest
python scripts/mutation_check.py   # breaks one protection at a time; every mutation must be killed

Without the cryptography package the crypto tests are skipped and everything else still runs.

Not in 0.3.0

Canary tokens (planned: detect and trace leaks), pin, POST and other methods in net, public-key signatures, streaming encryption for very large files, a policy engine, output detectors and a red-team harness are planned (issue #899) and not available yet.

Metadata

Release files for ragleap-security 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ragleap-security 0.3.0
File Size Uploaded Provenance Actions
ragleap_security-0.3.0.tar.gz 61.6 kB With provenance Details for ragleap_security-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ragleap-security 0.3.0
File Interpreter ABI Platform Actions
ragleap_security-0.3.0-py3-none-any.whl Python 3 none any Details for ragleap_security-0.3.0-py3-none-any.whl

Total release size: 91.4 kB

Release files / ragleap_security-0.3.0.tar.gz

Download URL ragleap_security-0.3.0.tar.gz
Size 61.6 kB
Tags Source
SHA-256 checksum
How to use checksums
619b13a362858d301f4e30e92577fb8a95a1bed3a03ff0a214a5da8cdc3b52e8
BLAKE2b-256 checksum
How to use checksums
486fe9d35d84ac2662a43b945208a44f73fd9b1c1788dd87dc5c88074c2eabda
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

Release files / ragleap_security-0.3.0-py3-none-any.whl

Download URL ragleap_security-0.3.0-py3-none-any.whl
Size 29.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6a9c5a6c162e1c0759ab6731fe48ef441bc505b0a564c77fb5d31554c9b9b37d
BLAKE2b-256 checksum
How to use checksums
7bf2ea4c9e99b72e3ff64fdcaa3ed7cad5eea0f0a2765dab5d7d1f229eee6cd7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

Security for ragleap-security 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for ragleap_security-0.3.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page