fix(onebot): strengthen endpoint defaults
Use safer defaults for newly created service endpoints and guide operators toward suitable access credentials without disrupting existing deployments. Apply the same policy at the save boundary, retain deliberate local-only setups and external client compatibility, and add regression coverage for editing, recovery, and trusted access paths.
This commit is contained in:
16 files changed
+601
-33
No files matched your search
@@ -1,11 +1,24 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import {
|
||||
describeTrustProxy,
|
||||
isLoopbackClientIp,
|
||||
parseTrustProxy,
|
||||
pickClientIp,
|
||||
type TrustProxyMode,
|
||||
} from '../src/webui/client-ip';
|
||||
|
||||
describe('isLoopbackClientIp', () => {
|
||||
it.each(['127.0.0.1', '127.0.0.2', '::1', '0:0:0:0:0:0:0:1', '::ffff:127.0.0.9'])(
|
||||
'accepts loopback address %s',
|
||||
(address) => expect(isLoopbackClientIp(address)).toBe(true),
|
||||
);
|
||||
|
||||
it.each(['', 'localhost', '0.0.0.0', '192.168.1.2', '::ffff:192.168.1.2'])(
|
||||
'rejects non-loopback or unverified address %s',
|
||||
(address) => expect(isLoopbackClientIp(address)).toBe(false),
|
||||
);
|
||||
});
|
||||
|
||||
function mockCtx(headers: Record<string, string> = {}) {
|
||||
return {
|
||||
req: {
|
||||
@@ -79,6 +92,23 @@ describe('pickClientIp', () => {
|
||||
const mode: TrustProxyMode = { kind: 'none' };
|
||||
expect(pickClientIp(mockCtx({}), mode, () => { throw new Error('boom'); })).toBe('127.0.0.1');
|
||||
});
|
||||
|
||||
it('can fail closed when a security decision cannot resolve the socket peer', () => {
|
||||
const mode: TrustProxyMode = { kind: 'none' };
|
||||
expect(pickClientIp(mockCtx({}), mode, () => { throw new Error('boom'); }, '')).toBe('');
|
||||
});
|
||||
|
||||
it('does not trust forwarded headers when the socket peer is unknown', () => {
|
||||
const mode: TrustProxyMode = { kind: 'all' };
|
||||
expect(
|
||||
pickClientIp(
|
||||
mockCtx({ 'x-real-ip': '127.0.0.1' }),
|
||||
mode,
|
||||
() => { throw new Error('boom'); },
|
||||
'',
|
||||
),
|
||||
).toBe('');
|
||||
});
|
||||
});
|
||||
|
||||
describe('describeTrustProxy', () => {
|
||||
|
||||
Reference in new issue
Block a user