rheodev/cpa-plugin-privacyfilter

A native privacy filter plugin for CLIProxyAPI. It intercepts model requests, detects sensitive text, and redacts it before the request is forwarded to an upstream provider.

36

stars

8

commits

Go

primary language

Jun 15, 2026

updated

README

CPA Plugin Privacy Filter

English | 简体中文

A native privacy filter plugin for CLIProxyAPI. It intercepts model requests, detects sensitive text, and redacts it before the request is forwarded to an upstream provider.

AI learners and builders can join the Linux.do community: linux.do.

This project uses packyme/privacy-filter for the core filtering logic and adapts it to the CPA plugin ABI from router-for-me/CLIProxyAPI.

What It Does

When CLIProxyAPI receives a request, this plugin scans supported text fields before the request leaves the local process. If sensitive content is found, the request body is rewritten with redacted placeholders.

Typical use cases:

  • Prevent accidental leakage of API keys and tokens
  • Remove personal contact information before sending prompts to models
  • Apply Gitleaks-style secret detection to LLM traffic
  • Keep filtering local to the CLIProxyAPI plugin pipeline

Features

  • Request interceptor for the CLIProxyAPI plugin runtime
  • Redacts emails, phone numbers, secrets, connection strings, certificates, and similar sensitive data
  • Uses built-in Gitleaks rules from rules/gitleaks.toml
  • Supports custom Gitleaks rule files
  • Handles OpenAI-style messages and input request bodies
  • Can skip filtering by model name or source format
  • Builds as a native shared library for Linux, macOS, and Windows

Requirements

  • Go 1.26+
  • CGO enabled
  • make

Build

Clone and build the plugin:

git clone https://github.com/rheodev/cpa-plugin-privacyfilter.git
cd cpa-plugin-privacyfilter

make build

The default build writes the shared library to the repository root:

  • Linux: privacyfilter.so
  • macOS: privacyfilter.dylib
  • Windows: privacyfilter.dll

Build for a specific platform:

GOOS=linux GOARCH=amd64 make build
GOOS=darwin GOARCH=arm64 make build
GOOS=windows GOARCH=amd64 make build

Use BUILD_DIR to place build output elsewhere:

BUILD_DIR=dist make build

Use with CLIProxyAPI

Place the shared library in your CLIProxyAPI plugin directory. The gitleaks rules are embedded in the binary, so no extra files are required:

privacyfilter/
└── privacyfilter.so        # or privacyfilter.dylib / privacyfilter.dll

Then enable the privacyfilter plugin in CLIProxyAPI.

Plugin metadata:

  • Name: privacyfilter
  • Capability: RequestInterceptor
  • Author: rheodev

Configuration

The plugin is configured inside CLIProxyAPI's main config file (config.yaml). Under plugins.configs.<id>, the host-owned fields (enabled, priority) are consumed by CLIProxyAPI, and the remaining YAML subtree is passed to the plugin verbatim.

Enable the plugin:

plugins:
  enabled: true
  dir: "plugins"
  configs:
    privacyfilter:
      enabled: true

Enable with custom rules:

plugins:
  enabled: true
  dir: "plugins"
  configs:
    privacyfilter:
      enabled: true
      gitleaks_toml: ""        # Empty uses embedded rules (or rules/gitleaks.toml sidecar)
      skip_models:
        - gpt-4
      skip_formats:
        - openai

Plugin fields:

FieldTypeDefaultDescription
gitleaks_tomlstring""Custom gitleaks rule file path. Relative paths are resolved from the plugin directory.
skip_modelsarray[]Models that should skip redaction.
skip_formatsarray[]Source formats that should skip redaction.

When gitleaks_toml is empty and no rules/gitleaks.toml sidecar file exists, the plugin uses the rules embedded in the binary at build time.

How It Works

The plugin runs for both before-auth and after-auth request interception hooks, then parses the JSON body:

  1. Checks skip_models and skip_formats.
  2. Parses the request body as JSON.
  3. Handles messages first, then falls back to input.
  4. Edits text fields only.
  5. Replaces detected sensitive data with placeholders.
  6. Leaves the request unchanged if parsing fails or no supported field is found.

Supported request shapes include:

{
  "model": "gpt-4",
  "messages": [
    {
      "role": "user",
      "content": "Email me at user@example.com"
    }
  ]
}
{
  "model": "gpt-4",
  "input": "My GitHub token is ghp_xxx"
}

Rules

Built-in rules are embedded into the shared library at build time from:

rules/gitleaks.toml

At runtime the plugin resolves rules in this order:

  1. gitleaks_toml config value, if set
  2. rules/gitleaks.toml sidecar next to the shared library
  3. The rules embedded at build time (default)

Update embedded rules and rebuild:

make update-rules
make build

You can also set gitleaks_toml to use your own rule file:

gitleaks_toml: custom/gitleaks.toml

Relative paths are resolved from the plugin directory.

Development

Common commands:

go test ./...
make build
make clean

Main files:

main.go                 Plugin metadata and build entry
abi.go                  CLIProxyAPI plugin ABI adapter
interceptor.go          Request interception and redaction logic
config.go               YAML configuration parsing
rules/gitleaks.toml     Built-in detection rules

Dependency note:

privacyfilter => github.com/packyme/privacy-filter

Credits

Contributors

rheodev

8 commits

rheodev/cpa-plugin-privacyfilter

A native privacy filter plugin for CLIProxyAPI. It intercepts model requests, detects sensitive text, and redacts it before the request is forwarded to an upstream provider.

36

stars

8

commits

Go

primary language

Jun 15, 2026

updated

README

CPA Plugin Privacy Filter

English | 简体中文

A native privacy filter plugin for CLIProxyAPI. It intercepts model requests, detects sensitive text, and redacts it before the request is forwarded to an upstream provider.

AI learners and builders can join the Linux.do community: linux.do.

This project uses packyme/privacy-filter for the core filtering logic and adapts it to the CPA plugin ABI from router-for-me/CLIProxyAPI.

What It Does

When CLIProxyAPI receives a request, this plugin scans supported text fields before the request leaves the local process. If sensitive content is found, the request body is rewritten with redacted placeholders.

Typical use cases:

  • Prevent accidental leakage of API keys and tokens
  • Remove personal contact information before sending prompts to models
  • Apply Gitleaks-style secret detection to LLM traffic
  • Keep filtering local to the CLIProxyAPI plugin pipeline

Features

  • Request interceptor for the CLIProxyAPI plugin runtime
  • Redacts emails, phone numbers, secrets, connection strings, certificates, and similar sensitive data
  • Uses built-in Gitleaks rules from rules/gitleaks.toml
  • Supports custom Gitleaks rule files
  • Handles OpenAI-style messages and input request bodies
  • Can skip filtering by model name or source format
  • Builds as a native shared library for Linux, macOS, and Windows

Requirements

  • Go 1.26+
  • CGO enabled
  • make

Build

Clone and build the plugin:

git clone https://github.com/rheodev/cpa-plugin-privacyfilter.git
cd cpa-plugin-privacyfilter

make build

The default build writes the shared library to the repository root:

  • Linux: privacyfilter.so
  • macOS: privacyfilter.dylib
  • Windows: privacyfilter.dll

Build for a specific platform:

GOOS=linux GOARCH=amd64 make build
GOOS=darwin GOARCH=arm64 make build
GOOS=windows GOARCH=amd64 make build

Use BUILD_DIR to place build output elsewhere:

BUILD_DIR=dist make build

Use with CLIProxyAPI

Place the shared library in your CLIProxyAPI plugin directory. The gitleaks rules are embedded in the binary, so no extra files are required:

privacyfilter/
└── privacyfilter.so        # or privacyfilter.dylib / privacyfilter.dll

Then enable the privacyfilter plugin in CLIProxyAPI.

Plugin metadata:

  • Name: privacyfilter
  • Capability: RequestInterceptor
  • Author: rheodev

Configuration

The plugin is configured inside CLIProxyAPI's main config file (config.yaml). Under plugins.configs.<id>, the host-owned fields (enabled, priority) are consumed by CLIProxyAPI, and the remaining YAML subtree is passed to the plugin verbatim.

Enable the plugin:

plugins:
  enabled: true
  dir: "plugins"
  configs:
    privacyfilter:
      enabled: true

Enable with custom rules:

plugins:
  enabled: true
  dir: "plugins"
  configs:
    privacyfilter:
      enabled: true
      gitleaks_toml: ""        # Empty uses embedded rules (or rules/gitleaks.toml sidecar)
      skip_models:
        - gpt-4
      skip_formats:
        - openai

Plugin fields:

FieldTypeDefaultDescription
gitleaks_tomlstring""Custom gitleaks rule file path. Relative paths are resolved from the plugin directory.
skip_modelsarray[]Models that should skip redaction.
skip_formatsarray[]Source formats that should skip redaction.

When gitleaks_toml is empty and no rules/gitleaks.toml sidecar file exists, the plugin uses the rules embedded in the binary at build time.

How It Works

The plugin runs for both before-auth and after-auth request interception hooks, then parses the JSON body:

  1. Checks skip_models and skip_formats.
  2. Parses the request body as JSON.
  3. Handles messages first, then falls back to input.
  4. Edits text fields only.
  5. Replaces detected sensitive data with placeholders.
  6. Leaves the request unchanged if parsing fails or no supported field is found.

Supported request shapes include:

{
  "model": "gpt-4",
  "messages": [
    {
      "role": "user",
      "content": "Email me at user@example.com"
    }
  ]
}
{
  "model": "gpt-4",
  "input": "My GitHub token is ghp_xxx"
}

Rules

Built-in rules are embedded into the shared library at build time from:

rules/gitleaks.toml

At runtime the plugin resolves rules in this order:

  1. gitleaks_toml config value, if set
  2. rules/gitleaks.toml sidecar next to the shared library
  3. The rules embedded at build time (default)

Update embedded rules and rebuild:

make update-rules
make build

You can also set gitleaks_toml to use your own rule file:

gitleaks_toml: custom/gitleaks.toml

Relative paths are resolved from the plugin directory.

Development

Common commands:

go test ./...
make build
make clean

Main files:

main.go                 Plugin metadata and build entry
abi.go                  CLIProxyAPI plugin ABI adapter
interceptor.go          Request interception and redaction logic
config.go               YAML configuration parsing
rules/gitleaks.toml     Built-in detection rules

Dependency note:

privacyfilter => github.com/packyme/privacy-filter

Credits

See what people are saying

Contributors

rheodev

8 commits

Languages

Go

91.2%

Shell

5.5%

Makefile

3.3%