Skip to content

[type:feat] register the sensitive word plugin in the admin - #7155

Merged
Aias00 merged 3 commits into
apache:masterfrom
HY-love-sleep:feat/sensitive-word-admin
Sep 22, 2026
Merged

Aias00 merged 3 commits into
apache:masterfrom
HY-love-sleep:feat/sensitive-word-admin

Conversation

@HY-love-sleep

Copy link
Copy Markdown
Contributor

Motivation

#7153 added the sensitive word plugin, but the plugin was not registered in the admin: no plugin
row and no plugin_handle rows, so no console form and no menu entry. This is the follow up tracked
in #7154.

What is added

1. The admin rows, for every dialect (db/init/{mysql,ob,pg,og,oracle} plus the h2 script the
admin uses):

  • the plugin row (id 67, role Ai, sort 197, the order of PluginEnum.SENSITIVE_WORD);
  • 14 plugin_handle rows: the redis client of the plugin (plugin level) and the five rule fields;
  • the 10 resource rows of the menu and the 10 permission rows binding them to the default role;
  • the two failClosed options in shenyu_dict, so the console renders a select for it;
  • the namespace_plugin_rel row.

db/upgrade/2.7.1-upgrade-2.7.2-{mysql,ob,og,oracle,pg}.sql carries the same rows for an existing
installation, and db/upgrade/upgrade-guide.md lists the new pair.

2. words on the rule. A small list can now be configured from the console form directly,
separated by commas or by new lines, and it is merged with the redis set the rule points at. This
answers the request to support a simple word list from the configuration side: a large list still
belongs in redis, and the console renders words as the generic single line input, so no
shenyu-dashboard change is involved.

3. maxBodySize. The largest body that is scanned, in bytes (0 scans every body):

  • the declared Content-Length is checked before the body is buffered, so an oversized request
    is never read into memory;
  • a body whose size is not declared (a chunked request) is checked once it has been read;
  • an oversized request is passed through unscanned with a warning, or rejected when the rule is
    failClosed, for the deployments that would rather block than let unfiltered content through.

Notes on the plugin changes

  • The dictionary cache is keyed by the redis key and the words of the rule, so two rules reading
    the same redis set with different words never share an automaton, and a changed word list is
    compiled again. A rule change drops the cached dictionary of both the previous and the new handle.
  • The words of the rule do not depend on redis: when the set cannot be read they are still enforced,
    which also softens the fail open default (a broken redis no longer means "no filtering at all" for
    such a rule).

Not included

Uploading a word list file from the console. It would need a redis client inside shenyu-admin
(the admin has none today), an upload endpoint with its size limit, encoding and audit rules, plus a
component in the separate shenyu-dashboard repository. Redis remains the way to feed a large list
and the module README documents it, so this is left out of the PR rather than half done — happy to
continue on it as a separate issue if it is wanted.

Testing

./mvnw -pl shenyu-plugin/shenyu-plugin-ai/shenyu-plugin-ai-sensitive-word,<starter> -am -Djacoco.skip=true test
./mvnw -pl shenyu-common -Dtest=SensitiveWordHandleTest test
  • 40 tests in the plugin module (16 plugin, 14 automaton, 10 handler), 2 in the starter and 5 in the
    dto, no failure, checkstyle 0, RAT ok.
  • The new tests cover the words of the rule alone, the words merged with the redis set, the words
    enforced while redis is down, and both maxBodySize policies (including a body whose size is not
    declared).
  • The sql was verified twice: the h2 script is executed with H2 (org.h2.tools.RunScript in MySQL
    mode) so the new rows are known to be valid, and every INSERT of the touched files was checked
    against the column count of its table, which is how a missing pair of date columns was caught
    before the push.

- db/init: the plugin, plugin_handle, resource, permission, shenyu_dict and
  namespace_plugin_rel rows for mysql, ob, pg, og, oracle and the admin h2 script
- db/upgrade: the 2.7.1 -> 2.7.2 scripts of the same dialects, listed in the upgrade guide
- rule handle: `words` (separated by commas or by new lines) merged with the redis set of the
  rule, and `maxBodySize` for a body that is too large to scan
- the declared Content-Length is checked before the body is buffered, so an oversized request
  is never read into memory; a body without a declared size is checked once it has been read
- an oversized request is passed through unscanned with a warning, or rejected when the rule
  is failClosed
- the dictionary cache is keyed by the rule words as well, and a rule change drops the cache
  of both the previous and the new configuration
- the words of the rule are enforced even when the redis set cannot be read
- README: the new fields, the registration and how to feed the dictionary
@Aias00
Aias00 merged commit 2da7ee1 into apache:master Sep 22, 2026
39 checks passed
@HY-love-sleep
HY-love-sleep deleted the feat/sensitive-word-admin branch September 22, 2026 02:19
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.

2 participants