Files
plugins/packages/privacy-gate/docs/operations.md
T
Muyangandsiml1169 9f02ad545f privacy-gate: middleware settings page (#1145)
The ShyPie plugin page gets a Middleware settings tab, so privacy-gate's
ctx.options can be set from the page instead of the CLI only. Options are
grouped as Protection, Advanced inspection and Diagnostics; the Agents view
is unchanged and both share one Save.

- Lists are validated (shape, count); a malformed allowModels blocks the
  save instead of turning into an allow-everything list.
- Numbers are floored and clamped to the middleware's own numOpt ranges,
  so a save that only flips an agent keeps the limit that actually runs
  (maxDepth 500 stays 200, not the page default 40).
- An unknown binaryPolicy is reported and blocks the save.
- A save re-reads the options and reports a conflict when another surface
  changed a managed field; options outside the form are kept.
- logEveryRows has one cap, 100000, in resolvedOptions and onUsage.
- privacy-gate 0.4.1.

Run at 9bb381bf on WSL (Ubuntu 24.04, Bun 1.4.2): bun test in
packages/privacy-gate 77 pass, 0 fail; scripts/check.mjs privacy-gate
clean. Broken by hand: page.test.mjs with 7c119f16's settings.js fails
(maxDepth Expected 200, Received 40). The diff adds no network call.
Not tried: the page in a running magpie.

Co-authored-by: siml1169 <siml1169@users.noreply.github.com>
2026-11-14 22:28:47 +08:00

5.5 KiB

ShyPie

Operations

Installation, configuration, verification and troubleshooting for the Magpie middleware.

Install

magpie plugin add @magpie-community/middleware-privacy-gate
magpie plugin

Confirm that Magpie's built-in JS gateway plugins plugin is on (Settings → Plugins → Built-in, id middleware). If it is off, no middleware runs.

For a gateway where only Magpie-routed DSH traffic should carry PII as text:

{
  "binaryPolicy": "guide",
  "allowModels": ["deepseek/*", "copilot/*"],
  "localModels": ["ollama/*", "lmstudio/*"],
  "localProviders": ["ollama", "lmstudio"],
  "guideTools": []
}

Use "binaryPolicy": "fail" if you want a hard 403 instead of a withhold-and- prompt response.

guideTools should stay empty unless a matching local MCP extractor is actually configured for the agent. The middleware cannot execute a tool; it only names it in the guide prompt.

Verify

  1. Save options:

    magpie plugin options privacy-gate '{"binaryPolicy":"guide"}'
    magpie plugin
    
  2. Send a request with an image part to a non-local model.

    • guide: HTTP 200, the model asks how to process the file locally, and no image bytes appear at the provider.
    • fail: HTTP 403 and a privacy-gate: message.
  3. Send a text-only request through the same model. It should pass.

  4. Send a request whose text contains a 600-character base64 run. It should be rejected with a BLOB message even if there is no image part.

  5. Check Magpie's plugin log for counts and the usage line. The middleware never logs request content — only provider/model/status/blocked counters.

Per-agent controls

Open Settings → Plugins → Installed → ShyPie → Open page for the full per-agent page. The same switches are available in the ShyPie protection card at the bottom of Magpie's Agents page, and right-clicking an agent adds ShyPie protection to its row menu.

Every agent is protected by default. A switch that is off writes that agent's id to disabledAgents; it bypasses both the request gate and the provider check. Globs and raw values are preserved verbatim and shown read-only under Policy patterns. A custom id already present only in disabledAgents is seeded into the page so its bypass stays visible. The Unknown / unclassified agent switch controls protectUnknownAgent and defaults to on. Saving applies to the next request; no Magpie restart is needed. If options changed elsewhere, the page asks you to reload rather than overwriting the newer values.

A bypassed agent is intentionally unprotected, including binary parts and encoded blobs. Use it only for an agent whose traffic you have chosen to trust.

Middleware settings page

The page's Middleware settings tab edits the same options as magpie plugin options, grouped as Protection, Advanced inspection and Diagnostics. Ranges and list shape are checked before saving. Numeric out-of-range values are shown at the effective clamped value the middleware uses; an unknown select is reported as invalid. Options outside the form are preserved. A malformed existing allowModels blocks saving instead of being replaced by an empty, allow-everything list; fix it in the form or with magpie plugin options.

Troubleshooting

I get a 403 for an image

Expected in fail mode. Either extract the image locally and send text, or set binaryPolicy: "guide" so the model receives metadata and a local-processing prompt instead.

Guide mode returns 200 but the model cannot see the file

Correct. The middleware never forwards the bytes. The model must use a local MCP/extractor that the agent has configured. Without one, the response is advice, not extraction.

An image reaches a local but non-local provider

Set both localModels and localProviders; with only localModels, onProvider blanks the content rather than sending it.

A legitimate request is rejected with BLOB

A long hash, minified line or base64-ish text can exceed the 400-character threshold. Raise blobBase64Chars / blobHexChars deliberately and understand that a larger document can then pass. Do not disable the gate.

The request went through even though the gate is on

Check the Magpie log for onRequest: took too long. Magpie drops a hook after 250 ms and forwards the original request. This is the engine's fail-open behavior, tracked in magpie#5305. The middleware's own budgets reduce the chance of a timeout but cannot change that outcome.

Update and rollback

Update through Magpie's plugin manager (magpie plugin update) and re-check the saved options after a version change.

To roll back to the strictest behavior, remove the options ({}) or set binaryPolicy: fail and clear localModels/localProviders. Removing the plugin leaves agents without the structural check; text masking is unaffected.

Companion deployment

The DSH half is @shypie_privacy/dsh-privacy-gate 0.3.0. It performs local image/PDF extraction before the DSH transcript and enforces the DSH llm/stream egress guard. This Magpie gate then covers every other agent behind the same gateway.

Support