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:
7 files changed
+76
-12
No files matched your search
@@ -35,8 +35,12 @@ describe('OneBot access token editor policy', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('only permits an empty inbound token on loopback', () => {
|
||||
expect(accessTokenFeedback('', [], false)).toMatchObject({ valid: false, tone: 'error' });
|
||||
it('only permits an empty inbound token in a trusted bind or local-page context', () => {
|
||||
expect(accessTokenFeedback('', [], false)).toEqual({
|
||||
valid: false,
|
||||
tone: 'error',
|
||||
message: '未绑定本机地址时,远程访问必须填写令牌;请生成令牌或将主机改为 127.0.0.1。',
|
||||
});
|
||||
expect(accessTokenFeedback('', [], true)).toMatchObject({ valid: true, tone: 'warning' });
|
||||
});
|
||||
});
|
||||
@@ -1,5 +1,6 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import {
|
||||
allowEmptyInboundAccessToken,
|
||||
isLoopbackHostname,
|
||||
shouldWarnAboutInsecureRemoteAccess,
|
||||
} from '../src/lib/transport-security';
|
||||
@@ -27,6 +28,18 @@ describe('WebUI transport security notice', () => {
|
||||
expect(isLoopbackHostname(hostname)).toBe(false);
|
||||
});
|
||||
|
||||
it('allows an empty inbound token when the bind host is loopback, even from a remote WebUI', () => {
|
||||
expect(allowEmptyInboundAccessToken('192.168.1.20', '127.0.0.1')).toBe(true);
|
||||
expect(allowEmptyInboundAccessToken('panel.example.com', 'localhost')).toBe(true);
|
||||
expect(allowEmptyInboundAccessToken('192.168.1.20', '0.0.0.0')).toBe(false);
|
||||
expect(allowEmptyInboundAccessToken('192.168.1.20', '')).toBe(false);
|
||||
});
|
||||
|
||||
it('still allows an empty inbound token when the WebUI itself is opened on loopback', () => {
|
||||
expect(allowEmptyInboundAccessToken('127.0.0.1', '0.0.0.0')).toBe(true);
|
||||
expect(allowEmptyInboundAccessToken('localhost', undefined)).toBe(true);
|
||||
});
|
||||
|
||||
it('warns only when a non-loopback page is accessed without HTTPS', () => {
|
||||
expect(shouldWarnAboutInsecureRemoteAccess({ protocol: 'http:', hostname: '192.168.1.20' }))
|
||||
.toBe(true);
|
||||
|
||||
Reference in new issue
Block a user