fix(webui): allow empty OneBot tokens on loopback bind hosts

Empty inbound tokens were gated on the WebUI page hostname / client IP,
so a remote panel visit blocked clearing the token even when the
listener was 127.0.0.1. Trust the bind host as well: loopback listeners
are not reachable from outside, while 0.0.0.0 still requires a local
WebUI session.
This commit is contained in:
DrSmoothl committed 2026-08-13 19:45:11 +08:00
1 parent b8b9be83c3
commit 5a012fe0c8
7 files changed
+76 -12

No files matched your search

@@ -14,17 +14,46 @@ function validate(
}
describe('OneBot access token save policy', () => {
it('rejects clearing an inbound token from a non-loopback client', () => {
it('rejects clearing an inbound token from a non-loopback client when the bind host is public', () => {
const previous = makeDefaultOneBotConfig();
const next = structuredClone(previous);
next.networks.httpServers[0].host = '0.0.0.0';
next.networks.httpServers[0].accessToken = undefined;
expect(() => validate(previous, next, '192.0.2.10')).toThrow(OneBotAccessTokenPolicyError);
expect(() => validate(previous, next, '192.0.2.10')).toThrow(/令牌/);
});
it('allows a remote client to clear a token when the inbound host is loopback', () => {
const previous = makeDefaultOneBotConfig();
const next = structuredClone(previous);
next.networks.httpServers[0].host = '127.0.0.1';
next.networks.httpServers[0].accessToken = undefined;
expect(() => validate(previous, next, '192.0.2.10')).not.toThrow();
});
it('treats localhost as a loopback bind host for empty inbound tokens', () => {
const previous = makeDefaultOneBotConfig();
const next = structuredClone(previous);
next.networks.wsServers[0].host = 'localhost';
next.networks.wsServers[0].accessToken = undefined;
expect(() => validate(previous, next, '192.0.2.10')).not.toThrow();
});
it('does not treat a missing bind host as loopback', () => {
const previous = makeDefaultOneBotConfig();
const next = structuredClone(previous);
next.networks.httpServers[0].host = undefined;
next.networks.httpServers[0].accessToken = undefined;
expect(() => validate(previous, next, '192.0.2.10')).toThrow(OneBotAccessTokenPolicyError);
expect(() => validate(previous, next, '192.0.2.10')).toThrow(/本机/);
});
it('treats every inbound token as new when no readable prior config exists', () => {
const next = makeDefaultOneBotConfig();
next.networks.httpServers[0].host = '0.0.0.0';
next.networks.httpServers[0].accessToken = undefined;
expect(() => validate(null, next, '192.0.2.10')).toThrow(OneBotAccessTokenPolicyError);