dsh-llm-injection-filter: Applying a Layer of Injection Filtering to DSH's LLM Response Stream

Introduction

The DSH plugin mechanism allows hooking new capabilities into the execution flow. For LLM streaming responses, a practical issue is that model outputs arrive in shards at token granularity. While a single delta may appear short and benign, the combined output could contain control characters, protocol markers, anomalous scripts, or spam keywords.

dsh-llm-injection-filter addresses this problem. It hooks into the llm/stream waterfall to inspect and handle responses before they enter the agent, without modifying any runtime source code.

What is this

The following section outlines the basic positioning of this plugin.

  • Plugin Name: dsh-llm-injection-filter
  • Maintainer: XiaoYuOvO
  • License: MIT
  • Runtime Environment: Node >=18
  • Delivery Form: Dynamic plugin / npm package, pure JS, no imports, no runtime dependencies
  • Scope: Hooks into the llm/stream waterfall, effective for all adapters
  • Core Objective: Detect suspected prompt injection / contamination and handle it based on configuration

It is automatically added to dsh.profile.bundles via dsh.bundle.patch and is mounted through the DSH plugin mechanism upon installation.

Core Functions

Track A: Hard Block on Rare Scripts

Track A handles script-level anomalies.

When Unicode characters not belonging to the allowed script set appear in the model output, the plugin interrupts the stream immediately. Track A has the highest priority; when triggered, it does not perform strip / reject but directly interrupts the response stream.

The default allowed scripts are:

Latin
Han
Common
Inherited
Greek

This means the default allowed set does not include scripts like Japanese Kana, Korean Hangul, or Russian Cyrillic. If legitimate output contains these scripts, it will be hard-blocked by Track A. You can allow the corresponding scripts via allowedScripts.

maxScanLen only constrains the segment-by-segment scanning/replacement of Track B; Track A has no upper limit.

Track B: Scoring Rule Disposition

Track B processes content based on scoring rules. Rule types include:

CTRL
PROTO
SCRIPT
KW

It also supports combined bonuses. The trigger threshold is minScore, with a default value of:

100

Track B supports the following disposition modes:

audit
strip
reject

There are two restrictions:

  • KW never triggers alone.
  • SCRIPT is only counted towards the total score if it co-occurs with at least one PROTO / CTRL.

The reject mode relies on block-end carrying the complete arguments. In delta-only streams that do not send block-end, tool-call arguments cannot be rewritten as a whole block; in this case, only auditing is performed.

Auditing and WebUI

The plugin outputs structured audit logs with the following rule types:

HARD_BLOCK | CTRL | PROTO | SCRIPT | KW

Interception records are not persisted to disk; they are output to the structured logging channel via the plugin fiber. The in-process ring buffer is limited by maxRecords.

In the WebUI, you can navigate to:

Settings → LLM Injection Filter

to query and adjust configurations. The settings page supports real-time configuration adjustments, with changes taking effect immediately without requiring a restart.

Please note that configuration state is persisted in localStorage. After a Host restart, configurations revert to default values and must be saved again in the settings page.

When stopping/unloading the plugin, listeners are automatically cleaned up along with the plugin fiber, leaving no timers or global subscriptions behind.

Installation and Activation

Below are several installation methods.

Install from GitHub default branch

dsh plugin --profile web add github:XiaoYuOvO/dsh-llm-injection-filter

Install by tag

Installing by tag allows locking to a verified version.

dsh plugin --profile web add github:XiaoYuOvO/dsh-llm-injection-filter#v1.1.0
dsh plugin --profile web add "link:G:/DEEPSE~1/data/dsh/plugins/LLM-IN~1"

Verify Installation

After installation, execute:

dsh --profile web --dump-config

This step is used to confirm that the plugin has been included in the current profile’s configuration / bundle composition.

Typical Usage

After installation, you can first open the WebUI settings page to view the configuration.

Settings → LLM Injection Filter

Configurable items include:

CFG.enabled
CFG.hardBlockRareScripts
CFG.allowedScripts
CFG.mode
CFG.minScore
CFG.applyToProviders
CFG.applyToModels
CFG.skipProviders
CFG.skipModels
CFG.maxRecords
CFG.extraKeywords
CFG.maxScanLen
CFG.maxSampleLen
CFG.recordMaxLen

Common adjustment paths are as follows:

  1. First, confirm whether CFG.enabled is turned on.
  2. If legitimate output contains scripts like Japanese, Korean, or Russian, append the corresponding scripts to CFG.allowedScripts.
  3. If you only want to observe without modifying output, set CFG.mode to audit.
  4. If you need to raise the trigger threshold, adjust CFG.minScore.
  5. If you only want to inspect specific providers/models, configure CFG.applyToProviders and CFG.applyToModels.
  6. If you need to skip certain providers/models, configure CFG.skipProviders and CFG.skipModels.
  7. Query recent interception records in the WebUI to confirm rule hit situations.

Use Cases and Notes

This plugin is suitable for users utilizing DSH’s LLM streaming responses who wish to perform a layer of security filtering before responses enter the agent.

Please note before use:

  • The plugin runs with the current DSH process privileges; check the source code and license before installation.
  • Track A’s default allowed scripts are relatively strict, not including Japanese Kana, Korean Hangul, Russian Cyrillic, etc., by default.
  • Track B only triggers when the total score reaches minScore.
  • KW does not trigger alone; SCRIPT is only counted if it co-occurs with PROTO / CTRL.
  • reject mode relies on complete arguments; for some delta-only streams, only auditing is possible.
  • Interception records are not persisted to disk; they are only kept in the in-process ring buffer, limited by maxRecords.
  • WebUI configurations are saved in localStorage and must be saved again after a Host restart.

Conclusion

dsh-llm-injection-filter provides injection/contamination filtering capabilities at the DSH LLM response stream level. Its core consists of Track A’s hard blocking of rare scripts and Track B’s scoring rule disposition, complemented by structured audit logs and the WebUI settings page.

GitHub Repository Address:

https://github.com/XiaoYuOvO/dsh-llm-injection-filter

If you need to find it in the DSH community directory, you can search for the plugin name:

dsh-llm-injection-filter
羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye