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

feat: bound agent session list and add revoke-all on Security settings (#10932)

Adam Eivyc574e81777e4
diff --git a/client/src/components/settings/SecurityTab.jsx b/client/src/components/settings/SecurityTab.jsx
index d4b78792b6..b434e3bbfb 100644
--- a/client/src/components/settings/SecurityTab.jsx
+++ b/client/src/components/settings/SecurityTab.jsx
@@ -5,7 +5,7 @@ import Banner from '../ui/Banner';
import FormField from '../ui/FormField';
import BrailleSpinner from '../BrailleSpinner';
import AgentKeyCard from './AgentKeyCard';
-import { getAuthStatus, setAuthPassword, clearAuthPassword, listAuthSessions, revokeAuthSession } from '../../services/api';
+import { getAuthStatus, setAuthPassword, clearAuthPassword, listAuthSessions, revokeAuthSession, revokeAllAgentSessions } from '../../services/api';
import { formatDateShort } from '../../utils/formatters';
// PortOS is single-user and normally trusted because it's tailnet-only — auth
@@ -27,6 +27,8 @@ export function SecurityTab() {
const statusRequestRef = useRef(0);
const [agentSessions, setAgentSessions] = useState([]);
const [revokingId, setRevokingId] = useState(null);
+ const [confirmRevokeAll, setConfirmRevokeAll] = useState(false);
+ const [revokingAll, setRevokingAll] = useState(false);
const sessionsRequestRef = useRef(0);
const loadAuthStatus = useCallback(() => {
@@ -93,6 +95,22 @@ export function SecurityTab() {
toast.success('Session revoked');
};
+ const handleRevokeAll = async () => {
+ if (revokingAll) return;
+ setRevokingAll(true);
+ const result = await revokeAllAgentSessions().catch((err) => err);
+ setRevokingAll(false);
+ if (result instanceof Error) {
+ toast.error(result.message || 'Revoke failed');
+ return;
+ }
+ // Invalidate any in-flight list fetch so it can't resurrect revoked rows.
+ sessionsRequestRef.current += 1;
+ setConfirmRevokeAll(false);
+ setAgentSessions([]);
+ toast.success(`Revoked ${result?.revoked ?? 0} agent session${result?.revoked === 1 ? '' : 's'}`);
+ };
+
const handleSubmit = async (event) => {
event.preventDefault();
if (saving) return;
@@ -299,14 +317,47 @@ export function SecurityTab() {
{enabled && agentSessions.length > 0 && (
<div className="bg-port-card border border-port-border rounded-lg p-4 space-y-3">
- <h3 className="text-md font-semibold text-white">
- {agentSessions.length} agent session{agentSessions.length === 1 ? '' : 's'}
- </h3>
+ <div className="flex flex-wrap items-center justify-between gap-2">
+ <h3 className="text-md font-semibold text-white">
+ {agentSessions.length} agent session{agentSessions.length === 1 ? '' : 's'}
+ </h3>
+ {confirmRevokeAll ? (
+ <div className="flex flex-wrap items-center gap-2">
+ <span className="text-sm text-gray-300">
+ Revoke all {agentSessions.length}? Running agents lose API access.
+ </span>
+ <button
+ type="button"
+ onClick={handleRevokeAll}
+ disabled={revokingAll}
+ className="min-h-9 text-sm bg-port-error text-white px-3 py-1.5 rounded hover:opacity-90 disabled:opacity-50 disabled:cursor-not-allowed"
+ >
+ {revokingAll ? 'Revoking…' : 'Confirm revoke all'}
+ </button>
+ <button
+ type="button"
+ onClick={() => setConfirmRevokeAll(false)}
+ disabled={revokingAll}
+ className="min-h-9 text-sm bg-port-bg border border-port-border text-gray-300 px-3 py-1.5 rounded hover:border-gray-400 disabled:opacity-50"
+ >
+ Cancel
+ </button>
+ </div>
+ ) : (
+ <button
+ type="button"
+ onClick={() => setConfirmRevokeAll(true)}
+ className="min-h-9 text-sm bg-port-bg border border-port-border text-port-error px-3 py-1.5 rounded hover:border-port-error"
+ >
+ Revoke all agent sessions
+ </button>
+ )}
+ </div>
<p className="text-sm text-gray-400">
Loopback API credentials PortOS minted for spawned agents. Revoking one does not
sign you out of the browser.
</p>
- <ul className="space-y-2">
+ <ul className="space-y-2 max-h-72 overflow-y-auto" aria-label="Agent sessions">
{agentSessions.map((session) => (
<li
key={session.id}
diff --git a/client/src/components/settings/SecurityTab.test.jsx b/client/src/components/settings/SecurityTab.test.jsx
index f0aa116e37..efe2c5962a 100644
--- a/client/src/components/settings/SecurityTab.test.jsx
+++ b/client/src/components/settings/SecurityTab.test.jsx
@@ -10,6 +10,7 @@ vi.mock('../../services/api', () => ({
clearAuthPassword: vi.fn(),
listAuthSessions: vi.fn(),
revokeAuthSession: vi.fn(),
+ revokeAllAgentSessions: vi.fn(),
getAgentKeyStatus: vi.fn(),
setAgentKeyEnabled: vi.fn(),
rotateAgentKey: vi.fn(),
@@ -169,6 +170,32 @@ describe('SecurityTab', () => {
expect(screen.getByText('Login password enabled')).toBeInTheDocument();
});
+ it('bounds the session list and revokes all agent sessions only after confirmation', async () => {
+ api.getAuthStatus.mockResolvedValue({ enabled: true });
+ api.listAuthSessions.mockResolvedValue({
+ sessions: [
+ { id: 'agent-1', label: 'agent', expiresAt: Date.parse('2026-10-01T00:00:00Z') },
+ { id: 'agent-2', label: 'agent', expiresAt: Date.parse('2026-10-01T00:00:00Z') },
+ ],
+ });
+ api.revokeAllAgentSessions.mockResolvedValue({ ok: true, revoked: 2 });
+
+ render(<SecurityTab />);
+
+ const list = await screen.findByRole('list', { name: 'Agent sessions' });
+ expect(list.className).toContain('max-h-72');
+ expect(list.className).toContain('overflow-y-auto');
+
+ fireEvent.click(screen.getByRole('button', { name: 'Revoke all agent sessions' }));
+ // First click only asks for confirmation.
+ expect(api.revokeAllAgentSessions).not.toHaveBeenCalled();
+ fireEvent.click(screen.getByRole('button', { name: 'Confirm revoke all' }));
+
+ await waitFor(() => expect(api.revokeAllAgentSessions).toHaveBeenCalledTimes(1));
+ await waitFor(() => expect(screen.queryByText('2 agent sessions')).not.toBeInTheDocument());
+ expect(screen.getByText('Login password enabled')).toBeInTheDocument();
+ });
+
it('refreshes agent sessions when password is changed', async () => {
api.getAuthStatus.mockResolvedValue({ enabled: true });
api.listAuthSessions
diff --git a/client/src/services/apiAuth.js b/client/src/services/apiAuth.js
index dd2b3226da..61e1f1db20 100644
--- a/client/src/services/apiAuth.js
+++ b/client/src/services/apiAuth.js
@@ -35,6 +35,14 @@ export const revokeAuthSession = (id, options) => request(`/auth/sessions/${enco
...options,
});
+// Revokes every agent-labelled session in one call; the caller's browser
+// session stays signed in. Resolves `{ ok, revoked }`.
+export const revokeAllAgentSessions = (options) => request('/auth/sessions?label=agent', {
+ method: 'DELETE',
+ silent: true,
+ ...options,
+});
+
// Agent API key (Settings → Security): state only, never the token itself.
export const getAgentKeyStatus = (options) => request('/auth/agent-key', options);
diff --git a/server/routes/auth.js b/server/routes/auth.js
index 917745c653..8b1891c9d0 100644
--- a/server/routes/auth.js
+++ b/server/routes/auth.js
@@ -16,6 +16,7 @@ import {
recordLoginFailure,
revokeSession,
revokeSessionById,
+ revokeSessionsByLabel,
sessionCookieNameFor,
setPassword,
verifyPassword,
@@ -35,6 +36,9 @@ const setPasswordSchema = z.object({
currentPassword: z.string().max(256).optional(),
}).strict();
const clearPasswordSchema = z.object({ currentPassword: z.string().min(1).max(256) }).strict();
+// Batch revoke is label-scoped so it can only ever drop non-interactive
+// credentials (never the caller's browser session, which carries no label).
+const revokeSessionsQuerySchema = z.object({ label: z.literal('agent') }).strict();
const sessionIdParamSchema = z.object({ id: z.string().min(1).max(64).regex(/^[a-f0-9]+$/) }).strict();
// Whether the request reached us over HTTPS (so the cookie should carry the
@@ -194,6 +198,16 @@ router.get('/sessions', asyncHandler(async (_req, res) => {
res.json({ sessions, count: sessions.length });
}));
+// DELETE /api/auth/sessions?label=agent — revoke every agent-labelled session
+// in one call (Settings → Security "Revoke all"). Leaves unlabelled browser
+// sessions, including the caller's, untouched.
+router.delete('/sessions', asyncHandler(async (req, res) => {
+ const { label } = validateRequest(revokeSessionsQuerySchema, req.query);
+ const revoked = await revokeSessionsByLabel(label);
+ logSecurityEvent('sessions.revoked', { ip: sourceOf(req), note: `${revoked} ${label} session(s)` });
+ res.json({ ok: true, revoked });
+}));
+
// DELETE /api/auth/sessions/:id — revoke exactly one session (e.g. the
// agent's loopback credential) without touching the caller's own browser
// session, unlike DELETE /api/auth/password (which revokes every session).
diff --git a/server/routes/auth.test.js b/server/routes/auth.test.js
index 5bf7414dc3..4d2469e0a2 100644
--- a/server/routes/auth.test.js
+++ b/server/routes/auth.test.js
@@ -244,6 +244,30 @@ describe('auth routes', () => {
expect(remaining.body.count).toBe(1);
});
+ it('DELETE /api/auth/sessions?label=agent revokes all agent sessions but keeps the browser session', async () => {
+ const app = await buildApp();
+ const { createSession } = await import('../services/auth.js');
+ const setupRes = await request(app).post('/api/auth/password').send({ newPassword: 'correct-horse' });
+ const cookie = setupRes.headers['set-cookie'];
+ await createSession({ label: 'agent' });
+ await createSession({ label: 'agent' });
+
+ const res = await request(app).delete('/api/auth/sessions?label=agent').set('Cookie', cookie);
+ expect(res.status).toBe(200);
+ expect(res.body).toEqual({ ok: true, revoked: 2 });
+
+ const whoami = await request(app).get('/api/auth/whoami').set('Cookie', cookie);
+ expect(whoami.body.authenticated).toBe(true);
+ const remaining = await request(app).get('/api/auth/sessions').set('Cookie', cookie);
+ expect(remaining.body.count).toBe(1);
+ });
+
+ it('DELETE /api/auth/sessions rejects a missing or non-agent label', async () => {
+ const app = await buildApp();
+ expect((await request(app).delete('/api/auth/sessions')).status).toBe(400);
+ expect((await request(app).delete('/api/auth/sessions?label=browser')).status).toBe(400);
+ });
+
it('DELETE /api/auth/sessions/:id 404s on an id that matches no live session', async () => {
const app = await buildApp();
const res = await request(app).delete('/api/auth/sessions/deadbeefdeadbeef');