Skip to content

fix: treat empty config schema as no config items - #9619

Open
wcqqq1214 wants to merge 2 commits into
AstrBotDevs:masterfrom
wcqqq1214:fix/conf-schema-empty
Open

fix: treat empty config schema as no config items#9619
wcqqq1214 wants to merge 2 commits into
AstrBotDevs:masterfrom
wcqqq1214:fix/conf-schema-empty

Conversation

@wcqqq1214

@wcqqq1214 wcqqq1214 commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Fixes #9608

Modifications / 改动点

When a plugin ships an empty _conf_schema.json (i.e. {}), AstrBotConfig.__init__ checked the schema with a truthiness test (if schema:). An explicitly-empty schema is falsy, so the plugin loader's call AstrBotConfig(config_path=..., schema=...) fell back to the global DEFAULT_CONFIG. This seeded the plugin's config file with the entire global configuration (45 top-level keys) and generated a fresh dashboard password hash into it. Because the schema was empty, the dashboard applied no field filtering, exposing the whole polluted config in the WebUI.

Changed if schema: to if schema is not None: so an explicitly-empty schema resolves to zero config items instead of falling back to the global defaults. schema=None (no schema) keeps the previous behavior.

  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果

Reproduced locally using the helloworld plugin template with _conf_schema.json = {}:

  • Before: data/config/<plugin>_config.json contained the full global config (45 top-level keys), including a generated dashboard.pbkdf2_password.
  • After: the file contains {}.

Verification:

  • pytest tests/unit/test_config.py → 46 passed
  • ruff check astrbot/core/config/astrbot_config.py → passed
  • Live restart of a local instance: the previously-polluted plugin config file was cleaned to {}

Checklist / 检查清单

  • 😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
    / 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。

  • 👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
    / 我的更改经过了良好的测试,并已在上方提供了"验证步骤"和"运行截图"

  • 🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
    / 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到 requirements.txtpyproject.toml 文件相应位置。

  • 😮 My changes do not introduce malicious code.
    / 我的更改没有引入恶意代码。

Summary by Sourcery

Bug Fixes:

  • Prevent empty plugin config schemas from being populated with the full global configuration and dashboard password when loading configs.

@wcqqq1214
wcqqq1214 marked this pull request as ready for review August 10, 2026 15:04
@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. area:core The bug / feature is about astrbot's core, backend labels Aug 10, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • Consider adding an inline comment or brief docstring note explaining the distinction between schema is None (use global defaults) and an explicitly empty schema (no config items) so future changes don’t accidentally reintroduce the previous behavior.
  • It may be clearer to explicitly initialize default_config in the schema is None case in this constructor, rather than relying on external defaults, to make the configuration flow more self-contained and easier to reason about.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider adding an inline comment or brief docstring note explaining the distinction between `schema is None` (use global defaults) and an explicitly empty schema (no config items) so future changes don’t accidentally reintroduce the previous behavior.
- It may be clearer to explicitly initialize `default_config` in the `schema is None` case in this constructor, rather than relying on external defaults, to make the configuration flow more self-contained and easier to reason about.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core The bug / feature is about astrbot's core, backend size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] 在 _conf_schema.json 中输入 {} ,似乎会暴露外部的配置项

1 participant