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: validate and bound the lines query on GET /api/browser/logs (#9134)

Adam Eivy0b40e59a680e
diff --git a/server/routes/browser.js b/server/routes/browser.js
index 24e62ec7ed..30dd21c1cd 100644
--- a/server/routes/browser.js
+++ b/server/routes/browser.js
@@ -1,7 +1,7 @@
import express from 'express';
import { z } from 'zod';
import { asyncHandler, ServerError } from '../lib/errorHandler.js';
-import { validateRequest } from '../lib/validation.js';
+import { validateRequest, logsQuerySchema } from '../lib/validation.js';
import { validateChromePath, validateMacAppBundle } from '../lib/browserConfig.js';
import { isSafeIngestUrl, isBlockedIngestHost } from '../lib/catalogValidation.js';
import { assertPublicHttpUrl } from '../lib/safeUrlFetch.js';
@@ -17,6 +17,10 @@ const router = express.Router();
const NAVIGATE_SETTLE_MS = 1000;
// Validation schemas
+// Reuses the PM2 logs bound (1..5000) but keeps this route's historical 50-line default.
+const browserLogsQuerySchema = logsQuerySchema.pick({ lines: true }).extend({
+ lines: z.coerce.number().int().min(1).max(5000).default(50),
+});
// SSRF guard (shared with catalog URL ingest): reject non-http(s) schemes
// (file:/chrome:/javascript:) and loopback / link-local / cloud-metadata host
// LITERALS so an agent-driven navigate can't directly target local-file
@@ -168,7 +172,7 @@ router.get('/version', asyncHandler(async (req, res) => {
// GET /api/browser/logs - Recent PM2 logs
router.get('/logs', asyncHandler(async (req, res) => {
- const lines = parseInt(req.query.lines || '50', 10);
+ const { lines } = validateRequest(browserLogsQuerySchema, req.query);
const logs = await browserService.getRecentLogs(lines);
res.json(logs);
}));
diff --git a/server/routes/browser.test.js b/server/routes/browser.test.js
index 0d8b35ebfe..0fe99f3c32 100644
--- a/server/routes/browser.test.js
+++ b/server/routes/browser.test.js
@@ -40,8 +40,10 @@ vi.mock('../services/browserService.js', () => ({
getHealthStatus: vi.fn(),
getBrowserStatus: vi.fn(),
getBrowserLogs: vi.fn(),
+ getRecentLogs: vi.fn(async () => ({ stdout: '', stderr: '' })),
}));
+const browserService = await import('../services/browserService.js');
const router = (await import('./browser.js')).default;
function makeApp() {
@@ -161,3 +163,18 @@ describe('POST /api/browser/navigate — SSRF guard', () => {
expect(navigateToUrlPinned).not.toHaveBeenCalled();
});
});
+
+describe('GET /api/browser/logs — lines query', () => {
+ it.each(['100000000', '-5', 'abc', '0'])('rejects lines=%s with 400', async (v) => {
+ const r = await request(makeApp()).get(`/api/browser/logs?lines=${v}`);
+ expect(r.status).toBe(400);
+ expect(browserService.getRecentLogs).not.toHaveBeenCalled();
+ });
+
+ it('defaults to 50 lines and forwards a valid value', async () => {
+ expect((await request(makeApp()).get('/api/browser/logs')).status).toBe(200);
+ expect(browserService.getRecentLogs).toHaveBeenLastCalledWith(50);
+ await request(makeApp()).get('/api/browser/logs?lines=200');
+ expect(browserService.getRecentLogs).toHaveBeenLastCalledWith(200);
+ });
+});