reskSecure

September 11, 2026 ยท View on GitHub

Per-user LLM firewall: unauthorized content becomes physically ungeneratable.

PyPI version PyPI downloads Python versions License

๐Ÿ”— resk.fr/projects/resksecure โ€” part of RESK Security

๐Ÿ“š Guides: Capability Bitmasks: Real RBAC for LLM Applications ยท Data Protection in AI

Installation

pip install resksecure

Requires Python โ‰ฅ 3.13, PyTorch โ‰ฅ 2.0, transformers โ‰ฅ 4.35, resklogits โ‰ฅ 0.1.0.

Usage rapide (30 seconds)

Define a policy (policy.yaml):

version: "1.0"
policies:
  - mask: 7
    name: contributor
    default: true
    rules:
      - { phrase: "DROP TABLE", mode: hard }
      - { phrase: "salaries",   mode: bias, penalty: -5.0 }
    tools:
      send_email: { required_bit: 1 }
      read_sql:   { required_bit: 2 }

Enforce it inside generation:

from resksecure import BitmaskLogitsProcessor, load_policy, verify_tool_action

policy = load_policy("policy.yaml")
processor = BitmaskLogitsProcessor(
    mask=7, model_name="mistralai/Mistral-7B-v0.1",
    tokenizer=tokenizer, policy_set=policy, device="cuda",
)
outputs = model.generate(**inputs, logits_processor=[processor])

# Defense-in-depth: verify tool calls against the bitmask
if not verify_tool_action("send_email", user_mask=7, policy_set=policy):
    raise PermissionError("Action not authorized")

Pourquoi reskSecure ?

Prompt filters are jailbreakable; post-generation moderation detects violations after the content is already emitted. reskSecure works at the logits level: every candidate token is checked against an Aho-Corasick automaton before sampling. If a user's capability bitmask doesn't allow it, the model cannot start generating the banned phrase or the disallowed tool call โ€” no prompt engineering can change that.

reskSecurePrompt-based filtersPost-generation moderationGeneric policy engines (OPAโ€ฆ)
Where it actsInside the generation loopOn the promptOn the finished outputApp/API layer
Bypassable by prompt injectionโŒโœ…โŒโš ๏ธ if model emits
Forbidden content ever emittedNoYesYes โ€” firstYes
Per-user permissionsโœ… capability bitmaskโš ๏ธ prompt-levelโŒ global policyโœ… but not generation
Tool-call gating at token levelโœ… trigger phrases blocked per bitโŒโŒโš ๏ธ execution-time only
Policy hot-reload, no restartโœ… PolicyWatcherโ€”โ€”โœ…
What it protectsLLM output itselfLLM inputNothing retroactivelyApp resources

Documentation

Policy reference

FieldTypeDescription
maskintCapability bitmask identifying this policy
namestringHuman-readable policy name
strictboolStop generation at the first banned prefix
defaultboolUsed when no exact mask matches
ruleslistPhrase rules: phrase, mode (hard = -inf, bias = penalty), penalty
toolsdictTool name โ†’ required_bit + optional trigger_phrases

How it works

User request + bitmask (e.g. 7)
   โ†’ BitmaskLogitsProcessor intercepts each token prediction
   โ†’ Aho-Corasick automaton (resklogits, GPU-accelerated) checks if the token
     starts/completes a banned phrase
   โ†’ hard mode: logit = -inf ยท bias mode: logit += penalty
   โ†’ complete match โ‡’ EOS forced, generation stops immediately

Tool calls are gated at the token level too: without the required bit, the first token of send_email( can never be generated.

Features: hard/bias severity modes ยท strict prefix mode ยท thread-safe (mask, model) automaton cache with TTL ยท YAML policies with hot-reload ยท post-generation verify_tool_action defense-in-depth ยท receives a raw integer bitmask (auth/JWT stays in your app).

Package structure

src/resksecure/
  policy_loader.py         YAML parsing, Policy/PolicySet models
  trie_factory.py          Builds VectorizedAhoCorasick from a Policy
  bitmask_processor.py     BitmaskLogitsProcessor
  tool_guard.py            Post-generation tool action verification
  cache.py                 Thread-safe TTL cache for automata
  policy_watcher.py        Hot-reload daemon

Ecosystem

Built on resklogits ยท pairs with Resk-LLM (input-time detection) and ReskPoints (action logging). The Resk full-stack app wires all three together.

License

RESK Software License โ€” commercial use requires a paid license. See LICENSE or contact contact@resk.fr.