Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix([issue-1136]): allowlist OpenClaw runtime status fields and trim messages test-token response

[._.]/ Adam Eivy90ead42dd4d0
diff --git a/server/integrations/openclaw/api.js b/server/integrations/openclaw/api.js
index 9316c429a7..e2f6eafe05 100644
--- a/server/integrations/openclaw/api.js
+++ b/server/integrations/openclaw/api.js
@@ -109,7 +109,11 @@ function normalizeStatusPayload(payload, config, reachable, errorMessage) {
label: pickFirst(payload?.label, payload?.name, config.label, 'OpenClaw Runtime'),
defaultSession: pickFirst(payload?.defaultSession, payload?.defaultSessionId, config.defaultSession, null) || null,
message: errorMessage || pickFirst(payload?.message, payload?.statusMessage, null) || null,
- runtime: payload && typeof payload === 'object' ? payload : null
+ // Allowlist runtime fields — the upstream payload may echo internal fields
+ // (or reflected tokens), so never pass the raw object through to the client.
+ runtime: payload && typeof payload === 'object'
+ ? { sessionsCount: payload.sessionsCount ?? null }
+ : null
};
}
diff --git a/server/integrations/openclaw/api.test.js b/server/integrations/openclaw/api.test.js
new file mode 100644
index 0000000000..f7f71ca3dd
--- /dev/null
+++ b/server/integrations/openclaw/api.test.js
@@ -0,0 +1,80 @@
+import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
+
+vi.mock('../../lib/fileUtils.js', () => ({
+ PATHS: { data: '/tmp/portos-test-data' },
+ readJSONFile: vi.fn()
+}));
+
+vi.mock('../../lib/fetchWithTimeout.js', () => ({
+ fetchWithTimeout: vi.fn()
+}));
+
+import { readJSONFile } from '../../lib/fileUtils.js';
+import { fetchWithTimeout } from '../../lib/fetchWithTimeout.js';
+import { getRuntimeStatus } from './api.js';
+
+const OPENCLAW_ENV_KEYS = Object.keys(process.env).filter(key => key.startsWith('OPENCLAW_'));
+
+function mockUpstreamResponse(payload) {
+ fetchWithTimeout.mockResolvedValue({
+ ok: true,
+ status: 200,
+ text: async () => JSON.stringify(payload)
+ });
+}
+
+describe('openclaw getRuntimeStatus', () => {
+ const savedEnv = {};
+
+ beforeEach(() => {
+ vi.clearAllMocks();
+ for (const key of OPENCLAW_ENV_KEYS) {
+ savedEnv[key] = process.env[key];
+ delete process.env[key];
+ }
+ readJSONFile.mockResolvedValue({ baseUrl: 'http://openclaw.local', defaultSession: 'main' });
+ });
+
+ afterEach(() => {
+ for (const key of OPENCLAW_ENV_KEYS) {
+ process.env[key] = savedEnv[key];
+ }
+ });
+
+ it('exposes only the allowlisted runtime fields, never the raw upstream payload', async () => {
+ mockUpstreamResponse({
+ ok: true,
+ result: {
+ sessions: [{ id: 'main' }, { id: 'work' }],
+ internalToken: 'should-never-reach-the-client',
+ debugInfo: { host: 'internal-host' }
+ }
+ });
+
+ const status = await getRuntimeStatus();
+
+ expect(status.reachable).toBe(true);
+ expect(status.runtime).toEqual({ sessionsCount: 2 });
+ expect(JSON.stringify(status)).not.toContain('should-never-reach-the-client');
+ expect(JSON.stringify(status)).not.toContain('internal-host');
+ });
+
+ it('returns runtime: null when the runtime is unreachable', async () => {
+ fetchWithTimeout.mockRejectedValue(new Error('connect ECONNREFUSED'));
+
+ const status = await getRuntimeStatus();
+
+ expect(status.reachable).toBe(false);
+ expect(status.runtime).toBeNull();
+ });
+
+ it('returns runtime: null when OpenClaw is not configured', async () => {
+ readJSONFile.mockResolvedValue({});
+
+ const status = await getRuntimeStatus();
+
+ expect(status.configured).toBe(false);
+ expect(status.runtime).toBeNull();
+ expect(fetchWithTimeout).not.toHaveBeenCalled();
+ });
+});
diff --git a/server/routes/messages.js b/server/routes/messages.js
index b3ffe0ec93..9f835f97a8 100644
--- a/server/routes/messages.js
+++ b/server/routes/messages.js
@@ -468,7 +468,18 @@ router.post('/debug/test-token', asyncHandler(async (req, res) => {
const apiResult = await testApi(provider, tokenResult.token, parseInt(req.query?.top, 10) || 5);
- res.json({ token: tokenInfo, api: apiResult });
+ // Trim the raw Graph/Outlook response to a status summary — message bodies and
+ // recipient lists have no business in a token-connectivity check response.
+ res.json({
+ token: tokenInfo,
+ api: {
+ success: apiResult.success === true,
+ ...(apiResult.status !== undefined && { status: apiResult.status }),
+ ...(apiResult.error !== undefined && { error: apiResult.error }),
+ ...(apiResult.count !== undefined && { count: apiResult.count }),
+ ...(apiResult.note !== undefined && { note: apiResult.note })
+ }
+ });
}));
router.post('/debug/clear-token', asyncHandler(async (req, res) => {
diff --git a/server/routes/messages.test.js b/server/routes/messages.test.js
index 8e3fa086c9..9128fe3e2b 100644
--- a/server/routes/messages.test.js
+++ b/server/routes/messages.test.js
@@ -42,12 +42,20 @@ vi.mock('../services/messagePlaywrightSync.js', () => ({
launchProvider: vi.fn()
}));
+vi.mock('../services/messageTokenExtractor.js', () => ({
+ getToken: vi.fn(),
+ getTokenStatus: vi.fn(),
+ testApi: vi.fn(),
+ clearTokenCache: vi.fn()
+}));
+
// Import mocked modules
import * as messageAccounts from '../services/messageAccounts.js';
import * as messageSync from '../services/messageSync.js';
import * as messageDrafts from '../services/messageDrafts.js';
import * as messageSender from '../services/messageSender.js';
import * as messagePlaywrightSync from '../services/messagePlaywrightSync.js';
+import * as messageTokenExtractor from '../services/messageTokenExtractor.js';
const VALID_UUID = '11111111-1111-1111-1111-111111111111';
const VALID_UUID_2 = '22222222-2222-2222-2222-222222222222';
@@ -638,4 +646,52 @@ describe('Messages Routes', () => {
expect(response.body.error).toBe('Invalid provider');
});
});
+
+ describe('POST /api/messages/debug/test-token', () => {
+ it('trims the provider API result to a status summary without message payloads', async () => {
+ messageTokenExtractor.getToken.mockResolvedValue({
+ token: 'tok-abcdef',
+ fresh: true,
+ decoded: { exp: 1893456000, aud: 'https://outlook.office.com', scp: 'Mail.Read' }
+ });
+ messageTokenExtractor.testApi.mockResolvedValue({
+ success: true,
+ count: 2,
+ messages: [
+ { id: 'm1', subject: 'Private subject', bodyContent: 'private-body-content' },
+ { id: 'm2', subject: 'Another', bodyContent: 'more-private-content' }
+ ]
+ });
+
+ const response = await request(app)
+ .post('/api/messages/debug/test-token')
+ .send({ provider: 'outlook' });
+
+ expect(response.status).toBe(200);
+ expect(response.body.api).toEqual({ success: true, count: 2 });
+ const serialized = JSON.stringify(response.body);
+ expect(serialized).not.toContain('private-body-content');
+ expect(serialized).not.toContain('Private subject');
+ });
+
+ it('passes through status and error fields when the API test fails', async () => {
+ messageTokenExtractor.getToken.mockResolvedValue({
+ token: 'tok-abcdef',
+ fresh: false,
+ decoded: {}
+ });
+ messageTokenExtractor.testApi.mockResolvedValue({
+ success: false,
+ status: 401,
+ error: 'InvalidAuthenticationToken'
+ });
+
+ const response = await request(app)
+ .post('/api/messages/debug/test-token')
+ .send({ provider: 'outlook' });
+
+ expect(response.status).toBe(200);
+ expect(response.body.api).toEqual({ success: false, status: 401, error: 'InvalidAuthenticationToken' });
+ });
+ });
});