claude-code-hub icon indicating copy to clipboard operation
claude-code-hub copied to clipboard

配置敏感词管理没有生效

Open vipelanchen opened this issue 5 months ago • 5 comments

老师好: 我在系统设置--敏感词-添加敏感词。匹配类型选择了包含匹配

Image
        客户端cli 发送了这几个敏感词,并没有进行拦截,和日志显示拦截。
        请问是我设置的不对吗?
Image

vipelanchen avatar Jun 10 '26 01:06 vipelanchen

Thank you for reporting this issue. Based on a thorough analysis of the codebase, your configuration looks correct (contains match type should work). Here is what I found:

Analysis

The sensitive word detection system works as follows:

  1. Guard pipeline order (src/app/v1/_lib/proxy/guard-pipeline.ts:200-217): The sensitive word guard ("sensitive") runs as the 2nd step, right after authentication. This is correct placement.

  2. Match logic (src/lib/sensitive-word-detector.ts:160-163): For "contains match" (contains), the detection does a case-insensitive substring check: lowerText.includes(word). Both the configured word and the message text are lowercased before comparison, so case should not be an issue.

  3. Text extraction (src/lib/message-extractor.ts): The system extracts text from prompt, system, messages (only role: "user" items), and input (Response API format, also only role: "user" items).

Most Likely Cause: Cache Not Loaded

The most probable reason your sensitive words are not being intercepted is the in-memory cache was empty at the time of the request.

In src/app/v1/_lib/proxy/sensitive-word-guard.ts:32-35:

if (sensitiveWordDetector.isEmpty()) {
  return null;  // SKIP - pass through if cache is empty
}

When the cache is empty, the guard silently passes through without checking anything. The cache can be empty because:

  • Initial load timing: The cache loads asynchronously at startup (src/app/v1/[...route]/route.ts:28) and may not have completed before the first requests arrive.
  • Cross-process cache sync: When you add sensitive words in the admin panel, the system tries to notify proxy workers via Redis pub/sub (src/lib/sensitive-word-detector.ts:55-69). If Redis pub/sub is not working or if the admin panel and proxy run in different processes, the cache on the proxy worker may not have been updated.

Recommended Steps

  1. Check if the cache loaded successfully: Look at your application logs for lines containing [SensitiveWordCache] Loaded N sensitive words. This will tell you if the words were loaded at startup and how many.

  2. Use the manual refresh button: On the sensitive words settings page, there is a "Refresh Cache" button (src/app/[locale]/settings/sensitive-words/_components/refresh-cache-button.tsx). Click it after adding new words and verify the count shown matches your expectations.

  3. Check Redis connectivity: Cross-process cache invalidation depends on Redis pub/sub. If Redis is not properly connected, cache updates from the admin panel may not reach the proxy worker. Check logs for [SensitiveWordCache] Subscribed to Redis pub/sub channel or any Failed to subscribe to Redis pub/sub warnings.

  4. Verify the word is enabled: When viewing the word list in settings, confirm the word shows as "enabled" (not disabled). The system only loads words where isEnabled = true (src/repository/sensitive-words.ts:22).

To help diagnose further, please provide:

  • Application logs around the time you added the sensitive words and sent the test messages
  • Whether Redis is configured and running (REDIS_URL environment variable)
  • Whether the "Refresh Cache" button shows the correct word count after clicking it
  • The exact sensitive words you configured (or similar examples) to rule out encoding issues

Automated response from Claude AI

github-actions[bot] avatar Jun 10 '26 01:06 github-actions[bot]

您好,敏感词匹配建议一条只写入一个词语。 我们也正在努力在下个季度的重构版本中提供更强大的安全护栏功能。

ding113 avatar Jun 11 '26 04:06 ding113

@ding113 老师你好, 在敏感词列表里,一行添加一条敏感词,选择包含匹配

Image

通过CLI 的方式进行测试,提示词中包含敏感词的,提示拦截

Image

但是我让AI读取文件夹里的文件,这个文件名就是敏感词,系统没有拦截,这个是我设置的不对吗?

Image

vipelanchen avatar Jun 16 '26 07:06 vipelanchen

This issue has been automatically marked as stale because it has not had any activity in the last 30 days.

If this issue is still relevant:

  • Please comment to keep it open
  • Add any new information that might help resolve it

This issue will be automatically closed in 14 days if there is no further activity.

github-actions[bot] avatar Jul 17 '26 01:07 github-actions[bot]

This issue has been automatically closed due to inactivity.

If you believe this issue is still relevant, please feel free to reopen it with additional information.

github-actions[bot] avatar Jul 31 '26 01:07 github-actions[bot]