PII masking for DeepSeek Harness — anonymizes names, phones, emails, ids, and keys before requests and restores them at the display layer, keeping plaintext out of session logs.
Install
# from npm (prebuilt)
dsh plugin --profile web add dsh-mask
# from GitHub (first run asks for allowBuilds approval — follow the hint, retry)
dsh plugin --profile web add github:PerryLink/dsh-mask
Any plugin you install runs third-party code with your own permissions — it can read your files, use your credentials, and reach the network, and tool approvals don’t sandbox it. GitHub-sourced plugins also run build scripts at install time — pnpm blocks those until you allow them, so an install can stop with ERR_PNPM_GIT_DEP_PREPARE_NOT_ALLOWED or ERR_PNPM_IGNORED_BUILDS; dsh prints the exact key to add under allowBuilds in your profile’s pnpm-workspace.yaml, and the install works on the next run. Allowing a build is a trust decision: only install sources you trust, and pin a commit (github:owner/repo#sha).
README
dsh-mask
Anonymize personal data before it reaches the model — the plaintext never enters your session log.
A pure host-side PII masking middleware for DeepSeek Harness: phones, emails, ID cards, bank cards, and keys become placeholders at the model boundary, and the restore table stays on your own machine.
Install · Configuration · FAQ · 简体中文 · English · Español · Português · हिन्दी
dsh plugin --profile <name> add dsh-mask
Community plugin, not affiliated with DeepSeek. Canonical repository: https://github.com/PerryLink/dsh-mask (Gitee is a mirror).
What it is
Before a message reaches the model, dsh-mask rewrites the phones, emails, ID cards, bank cards, and keys inside it into placeholders such as <PHONE_1> — what the model sees and what the session log records are placeholders only. The originals live solely in the host-side restore table (memory plus the controlled dsh_mask storage domain), and an explicit /mask restore call delivers them back as a 0600-permission file whose path — never the plaintext — is what gets logged. Pure regex, zero dependencies, no network requests.
Three-step setup
Install (pick one channel):
# git channel (latest main; equivalent to git+https://github.com/PerryLink/dsh-mask.git) dsh plugin --profile web add github:PerryLink/dsh-mask # npm channel (published releases) dsh plugin --profile web add dsh-mask # tarball channel: pnpm pack in this repo, then dsh plugin --profile web add ./dsh-mask-<version>.tgzNo build step —
index.mjsandlib/are the shipped artifacts.Minimal config (sane defaults; tailor the entity list as needed):
- insert: - id: mask name: dsh-mask config: entities: [phone, email, id-card, bank-card, key]Verify it mounts:
dsh --profile web --dump-config | grep -A2 'id: mask'> /mask status > /mask restore <PHONE_1> mask: restored 1 placeholder(s): <PHONE_1> file: /tmp/dsh-mask-restore/restore-1f0c….txt (mode 0600, one file per session)
Uninstall: dsh plugin --profile web remove dsh-mask (or remove the row from the profile patch).
dsh-maskno longer bundles the storage stack. Profiles that already compose it (thewebprofile does, via@deepseek-ai/dsh-web-app) providestorageDomain, so persistence works out of the box. On a bare profile without storage the plugin still mounts and masks, but the restore table is memory-only (lost on restart) — compose the storage stack in your profile patch, or setpersistRestoreTable: false.
Every PerryLink plugin is listed in the built-in DSH Desktop market: Market → Sources → Add source → paste https://perrylink-dsh-catalog.perrylink.workers.dev/catalog-source.json → select. Installation still requires the market's npm identity check and your confirmation.
Core capabilities
dsh-mask anonymizes personal data at the model boundary — before a message reaches the model — and keeps a restore table host-side so placeholders stay reversible:
- Request-time masking —
agent/pre-stepmessages are rewritten so phones, emails, ID cards, bank cards, and keys (on by default) and IPs (opt-in) become<PHONE_1>-style placeholders. The masked text is what gets logged and sent to the model. - Restore table — the
placeholder → originalmap lives only in memory and a controlled storage domain (dsh_mask); the plaintext never enters the session log. - Audit, not plaintext — the
mask/appliedsession event records only "replaced N values + type distribution", never the original text or the mapping. /maskcommand —status(counts + distribution),on/off(runtime toggle),restore <text>(unmap placeholders and deliver the plaintext as a file, never as logged text),help.mask_testtool — run a snippet through the detector and see the placeholder result; it never reveals the original values.
user message ──agent/pre-step──▶ placeholders ──model──▶ placeholders ──restore──▶ controlled file
▲ │
└──────── restore table (memory + dsh_mask) ───────────┘
Commands & tools surface
| Surface | Reveals plaintext | Notes |
|---|---|---|
agent/pre-step masking |
never | Rewrites messages to placeholders before they are logged or sent to the model |
tools/post-execute masking |
never | Rewrites tool-result text blocks to placeholders before they are logged or fed back to the model (scope: tools) |
/mask status |
never | Enabled state, total replaced, type distribution |
/mask on / /mask off |
never | Runtime toggle (resets to config.enabled on restart) |
/mask restore <text> |
yes (explicit) | Unmaps placeholders back to the values stored for this session and writes them to a controlled file (one per session, mode 0600); the result text and the session log carry only that path and the placeholder names |
mask_test |
never | Masks a snippet and reports the placeholder result + counts |
Examples
These are the plugin's real entry points; install once, then call one.
Detailed example — command mask_test, input:
{"text":"电话 13812345678"}
Output:
mask_test: replaced 1 PII value(s) (PHONE=1)
masked:
电话 <PHONE_1>
Observed from plugins/dsh-mask/index.mjs:243-250; test/index.test.mjs:306-315
Failure branch — input:
/mask restore <PHONE_1> with restoreDir=/tmp/dsh-mask-probe-not-a-dir (a regular file)
Output:
mask: restore failed: EEXIST: file already exists, mkdir '/tmp/dsh-mask-probe-not-a-dir'
Observed from plugins/dsh-mask/index.mjs:501-506; plugins/dsh-mask/lib/deliver.mjs:89-97; plugins/dsh-mask/test/index.test.mjs:278-290
Brief examples: mask_test · /mask restore <text>
Measured data
The per-type P/R/F1 benchmark over 108 synthetic samples (60 positive, 48 negative) is published in benchmark/RESULTS.md; regenerate it with node benchmark/run.mjs (no build step, zero new dependencies). The benchmark covers the regex path only: shape checks without checksums, the ip regex is range-loose (hence its false positives), and person/address are not measured.
Configuration
All tunables are Schemastery Config fields (changeable from cordis.yml). An id-targeted override replaces the whole row — restate every key you need. cordis.patch.yml documents each key inline.
Most-used keys:
| Key | Default | Meaning |
|---|---|---|
enabled |
true |
Master switch; false unregisters the listener, the /mask command, and the mask_test tool |
mode |
regex |
Detection mode; only regex is implemented (regex+ner for name/address recognition is reserved and fails loud) |
entities |
[phone, email, id-card, bank-card, key] |
Which PII types to mask; ip is also regex-capable (opt-in), person/address require NER |
scope |
[messages] |
Masking surface(s); messages masks agent/pre-step messages, tools masks tool-result text on tools/post-execute. Accepts a string or an array, e.g. [messages, tools] |
persistRestoreTable |
true |
Persist the restore table to the controlled dsh_mask storage domain (false = memory only) |
restoreDir |
'' |
Where /mask restore delivers the restored plaintext. Empty = os.tmpdir()/dsh-mask-restore; a relative value resolves against the host process working directory. The directory is created 0700 and the file written 0600, one file per session |
| Key | Default | Meaning |
|---|---|---|
enabled |
true |
Master switch; false unregisters the listener, the /mask command, and the mask_test tool |
mode |
regex |
Detection mode; only regex is implemented (regex+ner for name/address recognition is reserved and fails loud) |
entities |
[phone, email, id-card, bank-card, key] |
Which PII types to mask; ip is also regex-capable (opt-in), person/address require NER |
scope |
[messages] |
Masking surface(s); messages masks agent/pre-step messages, tools masks tool-result text on tools/post-execute. Accepts a string or an array, e.g. [messages, tools] |
registerCommand |
true |
Register the /mask command |
registerTools |
true |
Register the mask_test tool when the tools service is present |
persistRestoreTable |
true |
Persist the restore table to the controlled dsh_mask storage domain (false = memory only) |
maxRestoreEntriesPerSession |
500 |
Per-session restore entry cap (oldest evicted first) |
maxSessions |
1000 |
In-memory session cap (least-recently-used evicted, mapping reloaded on demand) |
maskClientEnabled |
false |
Feature flag for the browser half "reveal" bubble (defensive; off by default until the live slot catalog verifies the target slot). The key is schema-declared and validated, but no runtime code reads it yet, so it changes nothing until the browser half ships |
restoreDir |
'' |
Where /mask restore delivers the restored plaintext. Empty = os.tmpdir()/dsh-mask-restore; a relative value resolves against the host process working directory. The directory is created 0700 and the file written 0600, one file per session |
Example override in your profile patch:
- insert:
- id: mask
name: dsh-mask
config:
entities: [phone, email, id-card, bank-card, key, ip]
persistRestoreTable: false
registerCommand: true
FAQ
The placeholder → original restore table lives in memory and, when persistRestoreTable: true, in the controlled dsh_mask storage domain — it is never written to the session log. The only other plaintext copy is the delivery file an explicit /mask restore writes under restoreDir (mode 0600, one file per session, overwritten by the next restore); nothing writes plaintext to disk implicitly.
Nothing is silent. On a bare profile without the storage stack the plugin still mounts and masks, with the restore table degrading to memory-only plus a one-time warning. When the host does not record the mask/applied event type, audit appends are skipped and the first refusal per session logs one visible warning. Unimplemented mode (regex+ner), NER entities, unknown scope values, and out-of-bounds numbers all fail loudly at load.
No. Every tool is namespaced, it provides no service key, registers no client slot and no webServer prefix, and mutates no globals; every shared-event listener delegates through next() and never short-circuits the chain. The point-by-point argument is in "Interoperability with other DSH plugins".
The detector is zero-dependency pure regex — no network requests, no model calls — rewriting message text synchronously on agent/pre-step. For measured accuracy, see "Measured data" (108 samples, Macro F1 0.972).
Security boundaries
- Plaintext never enters the session log. The masked (placeholder) form is what gets logged and sent to the model, so model-visible content is reconstructable from the log in placeholder form; the originals stay in the restore table. The same rule governs the reveal direction: a command's result text is logged verbatim by the host and rendered from that same event, so
/mask restorewrites the plaintext to a controlled file and returns only its path. - Sanitize before display/log.
lib/sanitize.mjsredacts PII, secrets, and URL credentials before any text reaches the model or the log;mask_test,/mask status, and every/maskerror path never echo originals. - Controlled restore.
/mask restoreis the single explicit reveal surface, and it only reads the mapping for the active session. Failure fails closed: if the delivery file cannot be written, the command reports an error and never falls back to echoing the plaintext. - Fail closed. Unimplemented
mode(regex+ner), unknownscopevalues, NER-only entities, and out-of-bounds numbers all fail loudly at load. - Registrations are effects. The listener, command, tool, and storage-domain close are all Cordis effects — stop/hot-reload removes them.
Permissions & data
- Permissions:
dsh-maskperforms no network requests and stores no credentials; it reads the session at theagent/pre-stepboundary, writes its owndsh_maskstorage domain, and writes the/mask restoredelivery file (the manifest declaresfilesystem:writefor exactly that). ThedshWorkshopmanifest also declaresnetwork:noneandcredentials:none. - Data: see the first FAQ entry for where the restore table and the delivery file live — the conclusion stands: plaintext never reaches the session log.
- Session log:
mask/appliedis declared intypes.d.tsand appended only when the host records the type (see Known limitations). Its payload is counts + type distribution only.
Known limitations
- Regex only. Name (
person) and address (address) recognition needs an external NER recognizer, which the pure-host zero-dependency form does not bundle;mode: regex+nerand those entities fail loudly at load. The PII types covered out of the box are phone, email, ID card, bank card, key, and (opt-in) IP. - Region-specific patterns. The
phoneandid-carddetectors match mainland-China formats only:phoneis1[3-9]followed by nine digits, andid-cardis an 18-character Chinese resident ID (17 digits plus a digit orX). Phone numbers and national identifiers from other countries are not detected.email,ip, andkeyare region-agnostic;bank-cardaccepts any 16-19 digit run at a lower confidence score. - Display-layer restore needs a client half. Masking is fully host-side, but transparently un-masking the assistant bubbles in the client UI is a browser-half feature this pure-host form does not ship. The host side keeps the restore table and the exported
RestoreStoreseam (its methods take a session id), so a future client half would reach them through a host remote rather than directly; today the unmasking surface is the/mask restore <text>command, which delivers the plaintext as a file because a command result is logged verbatim (see Security boundaries), and themaskClientEnabledkey is validated but read by no runtime code yet. - No no-argument
/mask restore. Restoring every placeholder of the most recent assistant message is not offered, and the command says so when invoked without text. Two host facts block it: the restore table is a flat per-session{placeholder: original}map with no per-message index, so that message has to be located in the session event log; and the host deprecatedSession.snapshotEvents()/eventAt()/ownEvents()with an explicit "new calls are prohibited", leaving an incremental projection as the only sanctioned route — which this plugin's declared host corridor (>=0.1.2-rc.1) cannot rely on. Placeholders keep working one at a time instead:/mask restore <PHONE_1>. - Session events on
0.1.7-rc.2. The harness records 59 session event types and none of them ismask/*; itsSession.appendalso cannot stamp theignorableenvelope, so the session-log audit appends are skipped and sessions keep loading. The gate is not silent about it: the first refusal per session logs one visible warning naming the skipped type and this documented limitation. The plugin enables the append automatically once a host records the type or supports theignorableenvelope.
Interoperability with other DSH plugins
Verified against DSH 0.2.0-rc.2 (the runtime this README ships for) and the high-star plugin set surveyed on 2026-10-05.
This plugin does not interfere with other plugins, including the widely installed high-star ones:
- No tool-name collision. Every tool is namespaced; no bare name owned by a shipped tool or another plugin is registered.
- No service-key collision. It provides no service key at all, so it cannot collide on one.
- No slot collision. It registers no client slot key, so it cannot contend for a
shadows-shipped-uiseat. - No HTTP route collision. It registers no
webServerprefix. - No patch-layer collision. The bundle patch only
inserts its own row; it never overrides a built-in row'sconfig. - No global mutation. It does not patch prototypes, rewrite
process.env, or replace the global fetch dispatcher.
Shared event listeners are non-interfering by construction. It observes the ordering-sensitive events agent/pre-step, tools/post-execute with ctx.on() — Cordis's broadcast registration, where every listener runs and none can starve another. Every listener here delegates through next(), so the chain is never short-circuited, and a mutation is applied to the value next() produced rather than returned in its place:
agent/pre-step— also used bydsh-routing-suite(7000★, 7 listeners),modlens(4122★),dsh-purge(3317★),dsh-agent-teams(1923★),dsh-context(1849★).tools/post-execute— also used bycc-safety-net(1576★).
Static evidence: dsh-plugin-doctor K10–K13 report pass for every check on this repository.
Compatibility
| Surface | Status |
|---|---|
| Harness | DeepSeek Harness dsh-v0.2.1-alpha.1 (adapted 2026-09-18): the session envelope keeps its ignorable field for stored-log read compatibility only - Session.append still cannot stamp it, so audit-gate behavior is unchanged. Verified 2026-09-18 against the dsh-v0.1.7-alpha.1 master checkout (full gate chain + profile install smoke). |
| Node | ^22.19.0 || >=24.0.0 |
| Platforms | Anywhere DSH runs (pure host, zero-dependency regex; no browser half) |
| Model | Text models fully supported; no extra model capability required |
Ecosystem & quality
- Gitee mirror (sync mirror; GitHub is canonical)
- dshfind plugin page (installs and ranking)
- OpenSSF Scorecard report (driven by .github/workflows/scorecard.yml)
- dsh-plugin-doctor verification report (K10–K13 all
pass) - DSH Market (listed)
- 1024 store channel:
npm i -g dsh1024once, thendsh1024 plugin --profile web add dsh-mask(counts toward the deepseek1024.com install ranking) - Ecosystem knowledge base — measured data, not marketing: plugin development guide · plugin-selection data · maintenance criteria
Development
pnpm install # node ^22.19 || >=24
pnpm run typecheck && pnpm run typecheck:ci # two rulers: checkout face (guarded; unverifiable without the checkout) + published-line face
pnpm test # node --test
pnpm run verify:self-contained # dependency specs resolve from the registry
pnpm run verify:artifacts # shipped files present + index.mjs importable
pnpm run check:readmes # five-language README consistency
pnpm pack # the published tarball
There is no build step: pure ESM, index.mjs and lib/ are the shipped artifacts. Benchmark: node benchmark/run.mjs, results in benchmark/RESULTS.md. The README images are generated programmatically by scripts/gen-readme-assets.py (Python + Pillow) and are safe to re-run.
Topics: dsh, dsh-plugin, deepseek-harness, deepseek, cordis, pii, mask, privacy, anonymization, security
Family & thanks
This project is part of the DeepSeek Harness plugin family from PerryLink (all Apache-2.0). If it is useful, a star helps the next person find it — nothing is gated behind it.
- @PerryLink — creator and maintainer: the regex PII detector ported from Pii-Stripper-Middleware, the
agent/pre-stepmasking seam, the restore table, the/maskcommand andmask_testtool, and the five-language docs.
License
LICENSE (Apache License 2.0) © 2026 dsh-mask contributors
Links
More in this category
kenryu42/cc-safety-net★ 2025
Pre-execution guard that blocks destructive Git and filesystem commands and access to secrets such as SSH keys and .env files before a tool call runs.
ADWMC/helm-d#helmd★ 1266
Security-analysis plugin for DeepSeek Harness: 33 tools spanning six security domains, evidence/reporting and toolbox, plus the case lifecycle, routing and tool ledger; a session-bound case workflow with an evidence chain, E-id validation and reproducible findings; 362 on-demand references; three hot-swappable persona profiles; and a four-tab workbench (armor / case / intercept / about) with case-state recovery after context compaction.
toby-bridges/api-relay-audit★ 914
Runs local security audits of AI API relays and LLM proxies from DeepSeek Harness, producing Markdown reports for prompt injection, model substitution signals, tool-call rewriting, error leakage, stream integrity, and profile-gated Web3 risks.
SeaOf0/dsh-redteam-model★ 877
Authorized-security DSH collection: nine work modes (redteam coordinator, pentest, code audit, binary analysis, attack-defense, AV evasion, incident response, cloud security, CTF solving) and fifteen runtime plugins, managed from a settings page with one-click deploy, install, update and uninstall.
howmp/dsh-pentest★ 621
Authorized pentest mode for DeepSeek Harness — exploration chain, assets and findings with a Web view.
PerryLink/dsh-auto-review★ 248
Second-model auto-review on the approval answerer chain: a read-only reviewer subagent returns structured allow/deny verdicts with reasons, fail-closed by default.
Community comments
Comments are public GitHub Discussions. Loading them connects to GitHub and Giscus; a GitHub account is required to post.