Skip to content

feat: security that applies everywhere, with rules you can see and a log of what they caught - #85

Merged
fylorn merged 4 commits into
mainfrom
feat/global-security
Sep 21, 2026
Merged

fylorn merged 4 commits into
mainfrom
feat/global-security

Conversation

@fylorn

@fylorn fylorn commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Outbound redaction and tool-call inspection become global: one mode and one rule set each, applied the same way to every upstream. Every rule can be listed, switched off one by one, and supplemented with your own regular expressions, and everything the two guards catch is kept in a log.

Why

  • Three layers that disagreed. The global mode, each upstream's trust and redact classes, and each route rule's guard stacked on top of each other. Observe mode detected every class; enforce mode replaced only the upstream's classes. For an official endpoint that meant "credentials detected" while observing, and nothing replaced after switching to enforce.
  • Rules nobody could see. Redaction rules were hard-coded and only surfaced as five class names; tool-call rules could only be changed in config.yaml.
  • Evidence that disappeared. Tool-call hits (rule, tool, excerpt) were never stored, only a per-request count. Enforce-mode redactions were stored as a count too. The leak count ignored the dashboard's range and always covered seven days.
  • A switch wired to nothing. security.scan_configs did not change anything: the config watcher ran and alerted in every mode.

What changes

Config (security), no migration:

security:
  redact:
    mode: enforce            # off | observe | enforce
    enable: [internal-ip]    # built-in rules that ship off
    disable: [aws-temporary-key-id]
    custom:
      - name: Company token
        pattern: 'corp_[A-Za-z0-9]{32}'
  inspect_tools:
    mode: observe
    disable: [chmod-777]
    custom:
      - name: Delete cluster resources
        pattern: 'kubectl\s+delete'
        action: cut          # cut | record (default)

Removed: providers[].trust, providers[].redact, route rules' guard, security.scan_configs, security.scan_rules.

Data plane

  • Redaction rules are toggled one by one (26 built-ins; the two internal-address rules ship off). Custom rules are regexes; a match never crosses a JSON escape or quote, so replacing it cannot break the body. Observe and enforce use the same rules: findings come from the client's body once, replacement happens on what each hop actually sends.
  • Tool-call inspection uses the built-in command rules plus overrides and custom rules. A call is cut when the mode is enforce and the rule says cut, whoever the upstream is. The response-text prompt-injection check is gone: applied globally it flags ordinary answers that discuss prompt injection.
  • The same applies on the WebSocket path, which now also records in observe mode and does nothing when inspection is off.
  • The config scan uses the built-in rules only and no longer holds on to the configuration it started with.

Messages: the errors a client gets when a tool call is cut, and the scan findings, name the rule (“Download and run”) rather than its id; a custom rule, which has no reason attached, no longer leaves an empty () behind.

Events: LeakSeen and Redacted become SecretsFound { replaced, items: [{ rule, custom, kind, masked, count }] }. ToolCallFlagged carries action (cut / record) and custom instead of high. ResponseInspected is removed.

Store: a security_events table (one row per hit) replaces leaks; old leak rows are moved into it. requests.tool_calls, flagged and redacted are dropped. Rows expire with requests.

Control API (CONTROL_API_VERSION 4)

  • GET /security, PUT /security/{guard}/mode, PUT /security/{guard}/builtin/{id}, POST|PUT|DELETE /security/{guard}/custom[/{name}]: only settings that differ from the factory default are written; patterns are compiled before anything is written.
  • POST /security/{guard}/test: tries a sample against the current rules, one pattern, or one built-in rule (even one that is switched off, so a rule can be tried before it is turned on). Redaction samples are encoded as they would appear in a request body, so the answer matches the gateway. Offsets are in UTF-16.
  • GET /security/events: the log, filtered by guard and range, paged backwards.
  • /summary gains security counts (same rows as the log), replacing flagged_requests, redacted_requests and /leaks. History rows and request details carry their security events.
  • Removed: /leaks, /baseline (the upstream behaviour baseline), and the trust/redact fields on upstreams and their preview.

Tests

cargo test --workspace (1505 passed), clippy -D warnings, fmt --check, and scripts/smoke.sh (51 passed) locally. New: end-to-end redaction with a switched-off rule and a custom rule, tool-call cutting by rule action and custom rule, JSON-safe custom matches, plain-text test offsets, the store migration moving leak rows, and the control API for rules, tests (including one built-in rule while it is off) and the log.

🤖 Generated with Claude Code

fylorn and others added 4 commits September 21, 2026 23:08
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@fylorn
fylorn merged commit 0706d9e into main Sep 21, 2026
1 check passed
@fylorn
fylorn deleted the feat/global-security branch September 21, 2026 17:05
@fylorn fylorn mentioned this pull request Sep 21, 2026
fylorn added a commit that referenced this pull request Sep 21, 2026
Security that applies everywhere (#85): outbound redaction and
tool-call inspection each get one mode and one rule set for every
upstream. Rules can be listed, turned off one at a time, supplemented
with custom regular expressions and tried on a sample, and every hit is
kept in a log.

Breaking: CONTROL_API_VERSION 4. providers[].trust, providers[].redact,
route rules' guard, security.scan_configs and security.scan_rules are
gone from the configuration, and /leaks and /baseline from the control
API.

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant