Spaces:
Runtime error
Runtime error
Merge pull request #21 from builderz-labs/fix/p0-security-critical
Browse files- middleware.ts +17 -3
- src/app/api/activities/route.ts +4 -0
- src/app/api/agents/[id]/heartbeat/route.ts +3 -0
- src/app/api/agents/[id]/route.ts +3 -0
- src/app/api/agents/[id]/soul/route.ts +3 -0
- src/app/api/agents/comms/route.ts +4 -0
- src/app/api/agents/route.ts +3 -0
- src/app/api/auth/access-requests/route.ts +4 -1
- src/app/api/auth/me/route.ts +4 -1
- src/app/api/auth/users/route.ts +4 -1
- src/app/api/chat/conversations/route.ts +4 -0
- src/app/api/chat/messages/[id]/route.ts +3 -0
- src/app/api/chat/messages/route.ts +3 -0
- src/app/api/cron/route.ts +3 -0
- src/app/api/events/route.ts +6 -1
- src/app/api/logs/route.ts +3 -0
- src/app/api/notifications/deliver/route.ts +3 -0
- src/app/api/notifications/route.ts +3 -0
- src/app/api/pipelines/route.ts +4 -1
- src/app/api/pipelines/run/route.ts +3 -0
- src/app/api/quality-review/route.ts +3 -0
- src/app/api/sessions/route.ts +6 -2
- src/app/api/spawn/route.ts +3 -0
- src/app/api/standup/route.ts +4 -1
- src/app/api/status/route.ts +4 -0
- src/app/api/tasks/[id]/comments/route.ts +4 -1
- src/app/api/tasks/[id]/route.ts +4 -1
- src/app/api/tasks/route.ts +4 -1
- src/app/api/tokens/route.ts +3 -0
- src/app/api/workflows/route.ts +4 -1
- src/components/panels/memory-browser-panel.tsx +7 -2
- src/lib/auth.ts +16 -2
middleware.ts
CHANGED
|
@@ -1,6 +1,20 @@
|
|
| 1 |
import { NextResponse } from 'next/server'
|
| 2 |
import type { NextRequest } from 'next/server'
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
function envFlag(name: string): boolean {
|
| 5 |
const raw = process.env[name]
|
| 6 |
if (raw === undefined) return false
|
|
@@ -65,13 +79,13 @@ export function middleware(request: NextRequest) {
|
|
| 65 |
// API routes: accept session cookie OR API key
|
| 66 |
if (pathname.startsWith('/api/')) {
|
| 67 |
const apiKey = request.headers.get('x-api-key')
|
| 68 |
-
if (sessionToken || (apiKey && apiKey
|
| 69 |
return NextResponse.next()
|
| 70 |
}
|
| 71 |
|
| 72 |
// Backward compat: accept legacy cookie during migration
|
| 73 |
const legacyCookie = request.cookies.get('mission-control-auth')
|
| 74 |
-
if (legacyCookie?.value
|
| 75 |
return NextResponse.next()
|
| 76 |
}
|
| 77 |
|
|
@@ -85,7 +99,7 @@ export function middleware(request: NextRequest) {
|
|
| 85 |
|
| 86 |
// Backward compat: accept legacy cookie
|
| 87 |
const legacyCookie = request.cookies.get('mission-control-auth')
|
| 88 |
-
if (legacyCookie?.value
|
| 89 |
return NextResponse.next()
|
| 90 |
}
|
| 91 |
|
|
|
|
| 1 |
import { NextResponse } from 'next/server'
|
| 2 |
import type { NextRequest } from 'next/server'
|
| 3 |
|
| 4 |
+
/** Edge-compatible constant-time string comparison. */
|
| 5 |
+
function safeCompare(a: string, b: string): boolean {
|
| 6 |
+
if (typeof a !== 'string' || typeof b !== 'string') return false
|
| 7 |
+
const encoder = new TextEncoder()
|
| 8 |
+
const bufA = encoder.encode(a)
|
| 9 |
+
const bufB = encoder.encode(b)
|
| 10 |
+
if (bufA.length !== bufB.length) return false
|
| 11 |
+
let result = 0
|
| 12 |
+
for (let i = 0; i < bufA.length; i++) {
|
| 13 |
+
result |= bufA[i] ^ bufB[i]
|
| 14 |
+
}
|
| 15 |
+
return result === 0
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
function envFlag(name: string): boolean {
|
| 19 |
const raw = process.env[name]
|
| 20 |
if (raw === undefined) return false
|
|
|
|
| 79 |
// API routes: accept session cookie OR API key
|
| 80 |
if (pathname.startsWith('/api/')) {
|
| 81 |
const apiKey = request.headers.get('x-api-key')
|
| 82 |
+
if (sessionToken || (apiKey && safeCompare(apiKey, process.env.API_KEY || ''))) {
|
| 83 |
return NextResponse.next()
|
| 84 |
}
|
| 85 |
|
| 86 |
// Backward compat: accept legacy cookie during migration
|
| 87 |
const legacyCookie = request.cookies.get('mission-control-auth')
|
| 88 |
+
if (safeCompare(legacyCookie?.value || '', process.env.AUTH_SECRET || '')) {
|
| 89 |
return NextResponse.next()
|
| 90 |
}
|
| 91 |
|
|
|
|
| 99 |
|
| 100 |
// Backward compat: accept legacy cookie
|
| 101 |
const legacyCookie = request.cookies.get('mission-control-auth')
|
| 102 |
+
if (safeCompare(legacyCookie?.value || '', process.env.AUTH_SECRET || '')) {
|
| 103 |
return NextResponse.next()
|
| 104 |
}
|
| 105 |
|
src/app/api/activities/route.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
| 1 |
import { NextRequest, NextResponse } from 'next/server';
|
| 2 |
import { getDatabase, Activity } from '@/lib/db';
|
|
|
|
| 3 |
|
| 4 |
/**
|
| 5 |
* GET /api/activities - Get activity stream or stats
|
| 6 |
* Query params: type, actor, entity_type, limit, offset, since, hours (for stats)
|
| 7 |
*/
|
| 8 |
export async function GET(request: NextRequest) {
|
|
|
|
|
|
|
|
|
|
| 9 |
try {
|
| 10 |
const { searchParams, pathname } = new URL(request.url);
|
| 11 |
|
|
|
|
| 1 |
import { NextRequest, NextResponse } from 'next/server';
|
| 2 |
import { getDatabase, Activity } from '@/lib/db';
|
| 3 |
+
import { requireRole } from '@/lib/auth'
|
| 4 |
|
| 5 |
/**
|
| 6 |
* GET /api/activities - Get activity stream or stats
|
| 7 |
* Query params: type, actor, entity_type, limit, offset, since, hours (for stats)
|
| 8 |
*/
|
| 9 |
export async function GET(request: NextRequest) {
|
| 10 |
+
const auth = requireRole(request, 'viewer')
|
| 11 |
+
if ('error' in auth) return NextResponse.json({ error: auth.error }, { status: auth.status })
|
| 12 |
+
|
| 13 |
try {
|
| 14 |
const { searchParams, pathname } = new URL(request.url);
|
| 15 |
|
src/app/api/agents/[id]/heartbeat/route.ts
CHANGED
|
@@ -16,6 +16,9 @@ export async function GET(
|
|
| 16 |
request: NextRequest,
|
| 17 |
{ params }: { params: Promise<{ id: string }> }
|
| 18 |
) {
|
|
|
|
|
|
|
|
|
|
| 19 |
try {
|
| 20 |
const db = getDatabase();
|
| 21 |
const resolvedParams = await params;
|
|
|
|
| 16 |
request: NextRequest,
|
| 17 |
{ params }: { params: Promise<{ id: string }> }
|
| 18 |
) {
|
| 19 |
+
const auth = requireRole(request, 'viewer')
|
| 20 |
+
if ('error' in auth) return NextResponse.json({ error: auth.error }, { status: auth.status })
|
| 21 |
+
|
| 22 |
try {
|
| 23 |
const db = getDatabase();
|
| 24 |
const resolvedParams = await params;
|
src/app/api/agents/[id]/route.ts
CHANGED
|
@@ -11,6 +11,9 @@ export async function GET(
|
|
| 11 |
request: NextRequest,
|
| 12 |
{ params }: { params: Promise<{ id: string }> }
|
| 13 |
) {
|
|
|
|
|
|
|
|
|
|
| 14 |
try {
|
| 15 |
const db = getDatabase()
|
| 16 |
const { id } = await params
|
|
|
|
| 11 |
request: NextRequest,
|
| 12 |
{ params }: { params: Promise<{ id: string }> }
|
| 13 |
) {
|
| 14 |
+
const auth = requireRole(request, 'viewer')
|
| 15 |
+
if ('error' in auth) return NextResponse.json({ error: auth.error }, { status: auth.status })
|
| 16 |
+
|
| 17 |
try {
|
| 18 |
const db = getDatabase()
|
| 19 |
const { id } = await params
|
src/app/api/agents/[id]/soul/route.ts
CHANGED
|
@@ -13,6 +13,9 @@ export async function GET(
|
|
| 13 |
request: NextRequest,
|
| 14 |
{ params }: { params: Promise<{ id: string }> }
|
| 15 |
) {
|
|
|
|
|
|
|
|
|
|
| 16 |
try {
|
| 17 |
const db = getDatabase();
|
| 18 |
const resolvedParams = await params;
|
|
|
|
| 13 |
request: NextRequest,
|
| 14 |
{ params }: { params: Promise<{ id: string }> }
|
| 15 |
) {
|
| 16 |
+
const auth = requireRole(request, 'viewer')
|
| 17 |
+
if ('error' in auth) return NextResponse.json({ error: auth.error }, { status: auth.status })
|
| 18 |
+
|
| 19 |
try {
|
| 20 |
const db = getDatabase();
|
| 21 |
const resolvedParams = await params;
|
src/app/api/agents/comms/route.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
| 1 |
import { NextRequest, NextResponse } from "next/server"
|
| 2 |
import { getDatabase, Message } from "@/lib/db"
|
|
|
|
| 3 |
|
| 4 |
/**
|
| 5 |
* GET /api/agents/comms - Inter-agent communication stats and timeline
|
| 6 |
* Query params: limit, offset, since, agent
|
| 7 |
*/
|
| 8 |
export async function GET(request: NextRequest) {
|
|
|
|
|
|
|
|
|
|
| 9 |
try {
|
| 10 |
const db = getDatabase()
|
| 11 |
const { searchParams } = new URL(request.url)
|
|
|
|
| 1 |
import { NextRequest, NextResponse } from "next/server"
|
| 2 |
import { getDatabase, Message } from "@/lib/db"
|
| 3 |
+
import { requireRole } from '@/lib/auth'
|
| 4 |
|
| 5 |
/**
|
| 6 |
* GET /api/agents/comms - Inter-agent communication stats and timeline
|
| 7 |
* Query params: limit, offset, since, agent
|
| 8 |
*/
|
| 9 |
export async function GET(request: NextRequest) {
|
| 10 |
+
const auth = requireRole(request, 'viewer')
|
| 11 |
+
if ('error' in auth) return NextResponse.json({ error: auth.error }, { status: auth.status })
|
| 12 |
+
|
| 13 |
try {
|
| 14 |
const db = getDatabase()
|
| 15 |
const { searchParams } = new URL(request.url)
|
src/app/api/agents/route.ts
CHANGED
|
@@ -11,6 +11,9 @@ import { getUserFromRequest, requireRole } from '@/lib/auth';
|
|
| 11 |
* Query params: status, role, limit, offset
|
| 12 |
*/
|
| 13 |
export async function GET(request: NextRequest) {
|
|
|
|
|
|
|
|
|
|
| 14 |
try {
|
| 15 |
const db = getDatabase();
|
| 16 |
const { searchParams } = new URL(request.url);
|
|
|
|
| 11 |
* Query params: status, role, limit, offset
|
| 12 |
*/
|
| 13 |
export async function GET(request: NextRequest) {
|
| 14 |
+
const auth = requireRole(request, 'viewer')
|
| 15 |
+
if ('error' in auth) return NextResponse.json({ error: auth.error }, { status: auth.status })
|
| 16 |
+
|
| 17 |
try {
|
| 18 |
const db = getDatabase();
|
| 19 |
const { searchParams } = new URL(request.url);
|
src/app/api/auth/access-requests/route.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
import { randomBytes } from 'crypto'
|
| 2 |
import { NextRequest, NextResponse } from 'next/server'
|
| 3 |
-
import { createUser, getUserFromRequest } from '@/lib/auth'
|
| 4 |
import { getDatabase, logAuditEvent } from '@/lib/db'
|
| 5 |
|
| 6 |
function makeUsernameFromEmail(email: string): string {
|
|
@@ -20,6 +20,9 @@ function ensureUniqueUsername(base: string): string {
|
|
| 20 |
}
|
| 21 |
|
| 22 |
export async function GET(request: NextRequest) {
|
|
|
|
|
|
|
|
|
|
| 23 |
const user = getUserFromRequest(request)
|
| 24 |
if (!user || user.role !== 'admin') {
|
| 25 |
return NextResponse.json({ error: 'Admin access required' }, { status: 403 })
|
|
|
|
| 1 |
import { randomBytes } from 'crypto'
|
| 2 |
import { NextRequest, NextResponse } from 'next/server'
|
| 3 |
+
import { createUser, getUserFromRequest , requireRole } from '@/lib/auth'
|
| 4 |
import { getDatabase, logAuditEvent } from '@/lib/db'
|
| 5 |
|
| 6 |
function makeUsernameFromEmail(email: string): string {
|
|
|
|
| 20 |
}
|
| 21 |
|
| 22 |
export async function GET(request: NextRequest) {
|
| 23 |
+
const auth = requireRole(request, 'viewer')
|
| 24 |
+
if ('error' in auth) return NextResponse.json({ error: auth.error }, { status: auth.status })
|
| 25 |
+
|
| 26 |
const user = getUserFromRequest(request)
|
| 27 |
if (!user || user.role !== 'admin') {
|
| 28 |
return NextResponse.json({ error: 'Admin access required' }, { status: 403 })
|
src/app/api/auth/me/route.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
| 1 |
import { NextRequest, NextResponse } from 'next/server'
|
| 2 |
-
import { getUserFromRequest, updateUser } from '@/lib/auth'
|
| 3 |
import { logAuditEvent } from '@/lib/db'
|
| 4 |
import { verifyPassword } from '@/lib/password'
|
| 5 |
|
| 6 |
export async function GET(request: Request) {
|
|
|
|
|
|
|
|
|
|
| 7 |
const user = getUserFromRequest(request)
|
| 8 |
|
| 9 |
if (!user) {
|
|
|
|
| 1 |
import { NextRequest, NextResponse } from 'next/server'
|
| 2 |
+
import { getUserFromRequest, updateUser , requireRole } from '@/lib/auth'
|
| 3 |
import { logAuditEvent } from '@/lib/db'
|
| 4 |
import { verifyPassword } from '@/lib/password'
|
| 5 |
|
| 6 |
export async function GET(request: Request) {
|
| 7 |
+
const auth = requireRole(request, 'viewer')
|
| 8 |
+
if ('error' in auth) return NextResponse.json({ error: auth.error }, { status: auth.status })
|
| 9 |
+
|
| 10 |
const user = getUserFromRequest(request)
|
| 11 |
|
| 12 |
if (!user) {
|
src/app/api/auth/users/route.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
| 1 |
import { NextRequest, NextResponse } from 'next/server'
|
| 2 |
-
import { getUserFromRequest, getAllUsers, createUser, updateUser, deleteUser } from '@/lib/auth'
|
| 3 |
import { logAuditEvent } from '@/lib/db'
|
| 4 |
|
| 5 |
/**
|
| 6 |
* GET /api/auth/users - List all users (admin only)
|
| 7 |
*/
|
| 8 |
export async function GET(request: NextRequest) {
|
|
|
|
|
|
|
|
|
|
| 9 |
const user = getUserFromRequest(request)
|
| 10 |
if (!user || user.role !== 'admin') {
|
| 11 |
return NextResponse.json({ error: 'Admin access required' }, { status: 403 })
|
|
|
|
| 1 |
import { NextRequest, NextResponse } from 'next/server'
|
| 2 |
+
import { getUserFromRequest, getAllUsers, createUser, updateUser, deleteUser , requireRole } from '@/lib/auth'
|
| 3 |
import { logAuditEvent } from '@/lib/db'
|
| 4 |
|
| 5 |
/**
|
| 6 |
* GET /api/auth/users - List all users (admin only)
|
| 7 |
*/
|
| 8 |
export async function GET(request: NextRequest) {
|
| 9 |
+
const auth = requireRole(request, 'viewer')
|
| 10 |
+
if ('error' in auth) return NextResponse.json({ error: auth.error }, { status: auth.status })
|
| 11 |
+
|
| 12 |
const user = getUserFromRequest(request)
|
| 13 |
if (!user || user.role !== 'admin') {
|
| 14 |
return NextResponse.json({ error: 'Admin access required' }, { status: 403 })
|
src/app/api/chat/conversations/route.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
| 1 |
import { NextRequest, NextResponse } from 'next/server'
|
| 2 |
import { getDatabase } from '@/lib/db'
|
|
|
|
| 3 |
|
| 4 |
/**
|
| 5 |
* GET /api/chat/conversations - List conversations derived from messages
|
| 6 |
* Query params: agent (filter by participant), limit, offset
|
| 7 |
*/
|
| 8 |
export async function GET(request: NextRequest) {
|
|
|
|
|
|
|
|
|
|
| 9 |
try {
|
| 10 |
const db = getDatabase()
|
| 11 |
const { searchParams } = new URL(request.url)
|
|
|
|
| 1 |
import { NextRequest, NextResponse } from 'next/server'
|
| 2 |
import { getDatabase } from '@/lib/db'
|
| 3 |
+
import { requireRole } from '@/lib/auth'
|
| 4 |
|
| 5 |
/**
|
| 6 |
* GET /api/chat/conversations - List conversations derived from messages
|
| 7 |
* Query params: agent (filter by participant), limit, offset
|
| 8 |
*/
|
| 9 |
export async function GET(request: NextRequest) {
|
| 10 |
+
const auth = requireRole(request, 'viewer')
|
| 11 |
+
if ('error' in auth) return NextResponse.json({ error: auth.error }, { status: auth.status })
|
| 12 |
+
|
| 13 |
try {
|
| 14 |
const db = getDatabase()
|
| 15 |
const { searchParams } = new URL(request.url)
|
src/app/api/chat/messages/[id]/route.ts
CHANGED
|
@@ -9,6 +9,9 @@ export async function GET(
|
|
| 9 |
request: NextRequest,
|
| 10 |
{ params }: { params: Promise<{ id: string }> }
|
| 11 |
) {
|
|
|
|
|
|
|
|
|
|
| 12 |
try {
|
| 13 |
const db = getDatabase()
|
| 14 |
const { id } = await params
|
|
|
|
| 9 |
request: NextRequest,
|
| 10 |
{ params }: { params: Promise<{ id: string }> }
|
| 11 |
) {
|
| 12 |
+
const auth = requireRole(request, 'viewer')
|
| 13 |
+
if ('error' in auth) return NextResponse.json({ error: auth.error }, { status: auth.status })
|
| 14 |
+
|
| 15 |
try {
|
| 16 |
const db = getDatabase()
|
| 17 |
const { id } = await params
|
src/app/api/chat/messages/route.ts
CHANGED
|
@@ -96,6 +96,9 @@ function extractReplyText(waitPayload: any): string | null {
|
|
| 96 |
* Query params: conversation_id, from_agent, to_agent, limit, offset, since
|
| 97 |
*/
|
| 98 |
export async function GET(request: NextRequest) {
|
|
|
|
|
|
|
|
|
|
| 99 |
try {
|
| 100 |
const db = getDatabase()
|
| 101 |
const { searchParams } = new URL(request.url)
|
|
|
|
| 96 |
* Query params: conversation_id, from_agent, to_agent, limit, offset, since
|
| 97 |
*/
|
| 98 |
export async function GET(request: NextRequest) {
|
| 99 |
+
const auth = requireRole(request, 'viewer')
|
| 100 |
+
if ('error' in auth) return NextResponse.json({ error: auth.error }, { status: auth.status })
|
| 101 |
+
|
| 102 |
try {
|
| 103 |
const db = getDatabase()
|
| 104 |
const { searchParams } = new URL(request.url)
|
src/app/api/cron/route.ts
CHANGED
|
@@ -131,6 +131,9 @@ function mapOpenClawJob(job: OpenClawCronJob): CronJob {
|
|
| 131 |
}
|
| 132 |
|
| 133 |
export async function GET(request: NextRequest) {
|
|
|
|
|
|
|
|
|
|
| 134 |
try {
|
| 135 |
const { searchParams } = new URL(request.url)
|
| 136 |
const action = searchParams.get('action')
|
|
|
|
| 131 |
}
|
| 132 |
|
| 133 |
export async function GET(request: NextRequest) {
|
| 134 |
+
const auth = requireRole(request, 'admin')
|
| 135 |
+
if ('error' in auth) return NextResponse.json({ error: auth.error }, { status: auth.status })
|
| 136 |
+
|
| 137 |
try {
|
| 138 |
const { searchParams } = new URL(request.url)
|
| 139 |
const action = searchParams.get('action')
|
src/app/api/events/route.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
|
|
| 1 |
import { eventBus, ServerEvent } from '@/lib/event-bus'
|
|
|
|
| 2 |
|
| 3 |
export const dynamic = 'force-dynamic'
|
| 4 |
export const runtime = 'nodejs'
|
|
@@ -7,7 +9,10 @@ export const runtime = 'nodejs'
|
|
| 7 |
* GET /api/events - Server-Sent Events stream for real-time DB mutations.
|
| 8 |
* Clients connect via EventSource and receive JSON-encoded events.
|
| 9 |
*/
|
| 10 |
-
export async function GET() {
|
|
|
|
|
|
|
|
|
|
| 11 |
const encoder = new TextEncoder()
|
| 12 |
|
| 13 |
// Cleanup function, set in start(), called in cancel()
|
|
|
|
| 1 |
+
import { NextRequest , NextResponse } from 'next/server'
|
| 2 |
import { eventBus, ServerEvent } from '@/lib/event-bus'
|
| 3 |
+
import { requireRole } from '@/lib/auth'
|
| 4 |
|
| 5 |
export const dynamic = 'force-dynamic'
|
| 6 |
export const runtime = 'nodejs'
|
|
|
|
| 9 |
* GET /api/events - Server-Sent Events stream for real-time DB mutations.
|
| 10 |
* Clients connect via EventSource and receive JSON-encoded events.
|
| 11 |
*/
|
| 12 |
+
export async function GET(request: NextRequest) {
|
| 13 |
+
const auth = requireRole(request, 'viewer')
|
| 14 |
+
if ('error' in auth) return NextResponse.json({ error: auth.error }, { status: auth.status })
|
| 15 |
+
|
| 16 |
const encoder = new TextEncoder()
|
| 17 |
|
| 18 |
// Cleanup function, set in start(), called in cancel()
|
src/app/api/logs/route.ts
CHANGED
|
@@ -175,6 +175,9 @@ async function readLogFile(filePath: string, source: string, maxLines: number):
|
|
| 175 |
}
|
| 176 |
|
| 177 |
export async function GET(request: NextRequest) {
|
|
|
|
|
|
|
|
|
|
| 178 |
try {
|
| 179 |
const { searchParams } = new URL(request.url)
|
| 180 |
const action = searchParams.get('action') || 'recent'
|
|
|
|
| 175 |
}
|
| 176 |
|
| 177 |
export async function GET(request: NextRequest) {
|
| 178 |
+
const auth = requireRole(request, 'viewer')
|
| 179 |
+
if ('error' in auth) return NextResponse.json({ error: auth.error }, { status: auth.status })
|
| 180 |
+
|
| 181 |
try {
|
| 182 |
const { searchParams } = new URL(request.url)
|
| 183 |
const action = searchParams.get('action') || 'recent'
|
src/app/api/notifications/deliver/route.ts
CHANGED
|
@@ -182,6 +182,9 @@ export async function POST(request: NextRequest) {
|
|
| 182 |
* GET /api/notifications/deliver - Get delivery status and statistics
|
| 183 |
*/
|
| 184 |
export async function GET(request: NextRequest) {
|
|
|
|
|
|
|
|
|
|
| 185 |
try {
|
| 186 |
const db = getDatabase();
|
| 187 |
const { searchParams } = new URL(request.url);
|
|
|
|
| 182 |
* GET /api/notifications/deliver - Get delivery status and statistics
|
| 183 |
*/
|
| 184 |
export async function GET(request: NextRequest) {
|
| 185 |
+
const auth = requireRole(request, 'viewer')
|
| 186 |
+
if ('error' in auth) return NextResponse.json({ error: auth.error }, { status: auth.status })
|
| 187 |
+
|
| 188 |
try {
|
| 189 |
const db = getDatabase();
|
| 190 |
const { searchParams } = new URL(request.url);
|
src/app/api/notifications/route.ts
CHANGED
|
@@ -7,6 +7,9 @@ import { requireRole } from '@/lib/auth';
|
|
| 7 |
* Query params: recipient, unread_only, type, limit, offset
|
| 8 |
*/
|
| 9 |
export async function GET(request: NextRequest) {
|
|
|
|
|
|
|
|
|
|
| 10 |
try {
|
| 11 |
const db = getDatabase();
|
| 12 |
const { searchParams } = new URL(request.url);
|
|
|
|
| 7 |
* Query params: recipient, unread_only, type, limit, offset
|
| 8 |
*/
|
| 9 |
export async function GET(request: NextRequest) {
|
| 10 |
+
const auth = requireRole(request, 'viewer')
|
| 11 |
+
if ('error' in auth) return NextResponse.json({ error: auth.error }, { status: auth.status })
|
| 12 |
+
|
| 13 |
try {
|
| 14 |
const db = getDatabase();
|
| 15 |
const { searchParams } = new URL(request.url);
|
src/app/api/pipelines/route.ts
CHANGED
|
@@ -23,7 +23,10 @@ export interface Pipeline {
|
|
| 23 |
/**
|
| 24 |
* GET /api/pipelines - List all pipelines with enriched step data
|
| 25 |
*/
|
| 26 |
-
export async function GET() {
|
|
|
|
|
|
|
|
|
|
| 27 |
try {
|
| 28 |
const db = getDatabase()
|
| 29 |
const pipelines = db.prepare(
|
|
|
|
| 23 |
/**
|
| 24 |
* GET /api/pipelines - List all pipelines with enriched step data
|
| 25 |
*/
|
| 26 |
+
export async function GET(request: NextRequest) {
|
| 27 |
+
const auth = requireRole(request, 'viewer')
|
| 28 |
+
if ('error' in auth) return NextResponse.json({ error: auth.error }, { status: auth.status })
|
| 29 |
+
|
| 30 |
try {
|
| 31 |
const db = getDatabase()
|
| 32 |
const pipelines = db.prepare(
|
src/app/api/pipelines/run/route.ts
CHANGED
|
@@ -35,6 +35,9 @@ interface PipelineRun {
|
|
| 35 |
* GET /api/pipelines/run - Get pipeline runs
|
| 36 |
*/
|
| 37 |
export async function GET(request: NextRequest) {
|
|
|
|
|
|
|
|
|
|
| 38 |
try {
|
| 39 |
const db = getDatabase()
|
| 40 |
const { searchParams } = new URL(request.url)
|
|
|
|
| 35 |
* GET /api/pipelines/run - Get pipeline runs
|
| 36 |
*/
|
| 37 |
export async function GET(request: NextRequest) {
|
| 38 |
+
const auth = requireRole(request, 'viewer')
|
| 39 |
+
if ('error' in auth) return NextResponse.json({ error: auth.error }, { status: auth.status })
|
| 40 |
+
|
| 41 |
try {
|
| 42 |
const db = getDatabase()
|
| 43 |
const { searchParams } = new URL(request.url)
|
src/app/api/quality-review/route.ts
CHANGED
|
@@ -3,6 +3,9 @@ import { getDatabase, db_helpers } from '@/lib/db'
|
|
| 3 |
import { requireRole } from '@/lib/auth'
|
| 4 |
|
| 5 |
export async function GET(request: NextRequest) {
|
|
|
|
|
|
|
|
|
|
| 6 |
try {
|
| 7 |
const db = getDatabase()
|
| 8 |
const { searchParams } = new URL(request.url)
|
|
|
|
| 3 |
import { requireRole } from '@/lib/auth'
|
| 4 |
|
| 5 |
export async function GET(request: NextRequest) {
|
| 6 |
+
const auth = requireRole(request, 'viewer')
|
| 7 |
+
if ('error' in auth) return NextResponse.json({ error: auth.error }, { status: auth.status })
|
| 8 |
+
|
| 9 |
try {
|
| 10 |
const db = getDatabase()
|
| 11 |
const { searchParams } = new URL(request.url)
|
src/app/api/sessions/route.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
| 1 |
-
import { NextResponse } from 'next/server'
|
| 2 |
import { getAllGatewaySessions } from '@/lib/sessions'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
export async function GET() {
|
| 5 |
try {
|
| 6 |
const gatewaySessions = getAllGatewaySessions()
|
| 7 |
|
|
|
|
| 1 |
+
import { NextRequest, NextResponse } from 'next/server'
|
| 2 |
import { getAllGatewaySessions } from '@/lib/sessions'
|
| 3 |
+
import { requireRole } from '@/lib/auth'
|
| 4 |
+
|
| 5 |
+
export async function GET(request: NextRequest) {
|
| 6 |
+
const auth = requireRole(request, 'viewer')
|
| 7 |
+
if ('error' in auth) return NextResponse.json({ error: auth.error }, { status: auth.status })
|
| 8 |
|
|
|
|
| 9 |
try {
|
| 10 |
const gatewaySessions = getAllGatewaySessions()
|
| 11 |
|
src/app/api/spawn/route.ts
CHANGED
|
@@ -99,6 +99,9 @@ export async function POST(request: NextRequest) {
|
|
| 99 |
|
| 100 |
// Get spawn history
|
| 101 |
export async function GET(request: NextRequest) {
|
|
|
|
|
|
|
|
|
|
| 102 |
try {
|
| 103 |
const { searchParams } = new URL(request.url)
|
| 104 |
const limit = parseInt(searchParams.get('limit') || '50')
|
|
|
|
| 99 |
|
| 100 |
// Get spawn history
|
| 101 |
export async function GET(request: NextRequest) {
|
| 102 |
+
const auth = requireRole(request, 'viewer')
|
| 103 |
+
if ('error' in auth) return NextResponse.json({ error: auth.error }, { status: auth.status })
|
| 104 |
+
|
| 105 |
try {
|
| 106 |
const { searchParams } = new URL(request.url)
|
| 107 |
const limit = parseInt(searchParams.get('limit') || '50')
|
src/app/api/standup/route.ts
CHANGED
|
@@ -211,10 +211,13 @@ export async function POST(request: NextRequest) {
|
|
| 211 |
* Query params: limit, offset
|
| 212 |
*/
|
| 213 |
export async function GET(request: NextRequest) {
|
|
|
|
|
|
|
|
|
|
| 214 |
try {
|
| 215 |
const db = getDatabase();
|
| 216 |
const { searchParams } = new URL(request.url);
|
| 217 |
-
|
| 218 |
const limit = parseInt(searchParams.get('limit') || '10');
|
| 219 |
const offset = parseInt(searchParams.get('offset') || '0');
|
| 220 |
|
|
|
|
| 211 |
* Query params: limit, offset
|
| 212 |
*/
|
| 213 |
export async function GET(request: NextRequest) {
|
| 214 |
+
const auth = requireRole(request, 'viewer');
|
| 215 |
+
if ('error' in auth) return NextResponse.json({ error: auth.error }, { status: auth.status });
|
| 216 |
+
|
| 217 |
try {
|
| 218 |
const db = getDatabase();
|
| 219 |
const { searchParams } = new URL(request.url);
|
| 220 |
+
|
| 221 |
const limit = parseInt(searchParams.get('limit') || '10');
|
| 222 |
const offset = parseInt(searchParams.get('offset') || '0');
|
| 223 |
|
src/app/api/status/route.ts
CHANGED
|
@@ -5,8 +5,12 @@ import { runCommand, runOpenClaw, runClawdbot } from '@/lib/command'
|
|
| 5 |
import { config } from '@/lib/config'
|
| 6 |
import { getDatabase } from '@/lib/db'
|
| 7 |
import { getAllGatewaySessions, getAgentLiveStatuses } from '@/lib/sessions'
|
|
|
|
| 8 |
|
| 9 |
export async function GET(request: NextRequest) {
|
|
|
|
|
|
|
|
|
|
| 10 |
try {
|
| 11 |
const { searchParams } = new URL(request.url)
|
| 12 |
const action = searchParams.get('action') || 'overview'
|
|
|
|
| 5 |
import { config } from '@/lib/config'
|
| 6 |
import { getDatabase } from '@/lib/db'
|
| 7 |
import { getAllGatewaySessions, getAgentLiveStatuses } from '@/lib/sessions'
|
| 8 |
+
import { requireRole } from '@/lib/auth'
|
| 9 |
|
| 10 |
export async function GET(request: NextRequest) {
|
| 11 |
+
const auth = requireRole(request, 'viewer')
|
| 12 |
+
if ('error' in auth) return NextResponse.json({ error: auth.error }, { status: auth.status })
|
| 13 |
+
|
| 14 |
try {
|
| 15 |
const { searchParams } = new URL(request.url)
|
| 16 |
const action = searchParams.get('action') || 'overview'
|
src/app/api/tasks/[id]/comments/route.ts
CHANGED
|
@@ -9,11 +9,14 @@ export async function GET(
|
|
| 9 |
request: NextRequest,
|
| 10 |
{ params }: { params: Promise<{ id: string }> }
|
| 11 |
) {
|
|
|
|
|
|
|
|
|
|
| 12 |
try {
|
| 13 |
const db = getDatabase();
|
| 14 |
const resolvedParams = await params;
|
| 15 |
const taskId = parseInt(resolvedParams.id);
|
| 16 |
-
|
| 17 |
if (isNaN(taskId)) {
|
| 18 |
return NextResponse.json({ error: 'Invalid task ID' }, { status: 400 });
|
| 19 |
}
|
|
|
|
| 9 |
request: NextRequest,
|
| 10 |
{ params }: { params: Promise<{ id: string }> }
|
| 11 |
) {
|
| 12 |
+
const auth = requireRole(request, 'viewer');
|
| 13 |
+
if ('error' in auth) return NextResponse.json({ error: auth.error }, { status: auth.status });
|
| 14 |
+
|
| 15 |
try {
|
| 16 |
const db = getDatabase();
|
| 17 |
const resolvedParams = await params;
|
| 18 |
const taskId = parseInt(resolvedParams.id);
|
| 19 |
+
|
| 20 |
if (isNaN(taskId)) {
|
| 21 |
return NextResponse.json({ error: 'Invalid task ID' }, { status: 400 });
|
| 22 |
}
|
src/app/api/tasks/[id]/route.ts
CHANGED
|
@@ -20,11 +20,14 @@ export async function GET(
|
|
| 20 |
request: NextRequest,
|
| 21 |
{ params }: { params: Promise<{ id: string }> }
|
| 22 |
) {
|
|
|
|
|
|
|
|
|
|
| 23 |
try {
|
| 24 |
const db = getDatabase();
|
| 25 |
const resolvedParams = await params;
|
| 26 |
const taskId = parseInt(resolvedParams.id);
|
| 27 |
-
|
| 28 |
if (isNaN(taskId)) {
|
| 29 |
return NextResponse.json({ error: 'Invalid task ID' }, { status: 400 });
|
| 30 |
}
|
|
|
|
| 20 |
request: NextRequest,
|
| 21 |
{ params }: { params: Promise<{ id: string }> }
|
| 22 |
) {
|
| 23 |
+
const auth = requireRole(request, 'viewer');
|
| 24 |
+
if ('error' in auth) return NextResponse.json({ error: auth.error }, { status: auth.status });
|
| 25 |
+
|
| 26 |
try {
|
| 27 |
const db = getDatabase();
|
| 28 |
const resolvedParams = await params;
|
| 29 |
const taskId = parseInt(resolvedParams.id);
|
| 30 |
+
|
| 31 |
if (isNaN(taskId)) {
|
| 32 |
return NextResponse.json({ error: 'Invalid task ID' }, { status: 400 });
|
| 33 |
}
|
src/app/api/tasks/route.ts
CHANGED
|
@@ -18,10 +18,13 @@ function hasAegisApproval(db: ReturnType<typeof getDatabase>, taskId: number): b
|
|
| 18 |
* Query params: status, assigned_to, priority, limit, offset
|
| 19 |
*/
|
| 20 |
export async function GET(request: NextRequest) {
|
|
|
|
|
|
|
|
|
|
| 21 |
try {
|
| 22 |
const db = getDatabase();
|
| 23 |
const { searchParams } = new URL(request.url);
|
| 24 |
-
|
| 25 |
// Parse query parameters
|
| 26 |
const status = searchParams.get('status');
|
| 27 |
const assigned_to = searchParams.get('assigned_to');
|
|
|
|
| 18 |
* Query params: status, assigned_to, priority, limit, offset
|
| 19 |
*/
|
| 20 |
export async function GET(request: NextRequest) {
|
| 21 |
+
const auth = requireRole(request, 'viewer');
|
| 22 |
+
if ('error' in auth) return NextResponse.json({ error: auth.error }, { status: auth.status });
|
| 23 |
+
|
| 24 |
try {
|
| 25 |
const db = getDatabase();
|
| 26 |
const { searchParams } = new URL(request.url);
|
| 27 |
+
|
| 28 |
// Parse query parameters
|
| 29 |
const status = searchParams.get('status');
|
| 30 |
const assigned_to = searchParams.get('assigned_to');
|
src/app/api/tokens/route.ts
CHANGED
|
@@ -170,6 +170,9 @@ function filterByTimeframe(records: TokenUsageRecord[], timeframe: string): Toke
|
|
| 170 |
}
|
| 171 |
|
| 172 |
export async function GET(request: NextRequest) {
|
|
|
|
|
|
|
|
|
|
| 173 |
try {
|
| 174 |
const { searchParams } = new URL(request.url)
|
| 175 |
const action = searchParams.get('action') || 'list'
|
|
|
|
| 170 |
}
|
| 171 |
|
| 172 |
export async function GET(request: NextRequest) {
|
| 173 |
+
const auth = requireRole(request, 'viewer')
|
| 174 |
+
if ('error' in auth) return NextResponse.json({ error: auth.error }, { status: auth.status })
|
| 175 |
+
|
| 176 |
try {
|
| 177 |
const { searchParams } = new URL(request.url)
|
| 178 |
const action = searchParams.get('action') || 'list'
|
src/app/api/workflows/route.ts
CHANGED
|
@@ -21,7 +21,10 @@ export interface WorkflowTemplate {
|
|
| 21 |
/**
|
| 22 |
* GET /api/workflows - List all workflow templates
|
| 23 |
*/
|
| 24 |
-
export async function GET() {
|
|
|
|
|
|
|
|
|
|
| 25 |
try {
|
| 26 |
const db = getDatabase()
|
| 27 |
const templates = db.prepare('SELECT * FROM workflow_templates ORDER BY use_count DESC, updated_at DESC').all() as WorkflowTemplate[]
|
|
|
|
| 21 |
/**
|
| 22 |
* GET /api/workflows - List all workflow templates
|
| 23 |
*/
|
| 24 |
+
export async function GET(request: NextRequest) {
|
| 25 |
+
const auth = requireRole(request, 'viewer')
|
| 26 |
+
if ('error' in auth) return NextResponse.json({ error: auth.error }, { status: auth.status })
|
| 27 |
+
|
| 28 |
try {
|
| 29 |
const db = getDatabase()
|
| 30 |
const templates = db.prepare('SELECT * FROM workflow_templates ORDER BY use_count DESC, updated_at DESC').all() as WorkflowTemplate[]
|
src/components/panels/memory-browser-panel.tsx
CHANGED
|
@@ -321,11 +321,16 @@ export function MemoryBrowserPanel() {
|
|
| 321 |
elements.push(<div key={`${i}-space`} className="mb-2"></div>)
|
| 322 |
} else if (trimmedLine.length > 0) {
|
| 323 |
if (inList) inList = false
|
| 324 |
-
// Handle inline formatting
|
| 325 |
let content = trimmedLine
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 326 |
// Simple bold formatting
|
| 327 |
content = content.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>')
|
| 328 |
-
// Simple italic formatting
|
| 329 |
content = content.replace(/\*(.*?)\*/g, '<em>$1</em>')
|
| 330 |
|
| 331 |
elements.push(
|
|
|
|
| 321 |
elements.push(<div key={`${i}-space`} className="mb-2"></div>)
|
| 322 |
} else if (trimmedLine.length > 0) {
|
| 323 |
if (inList) inList = false
|
| 324 |
+
// Handle inline formatting — escape HTML entities first to prevent XSS
|
| 325 |
let content = trimmedLine
|
| 326 |
+
.replace(/&/g, '&')
|
| 327 |
+
.replace(/</g, '<')
|
| 328 |
+
.replace(/>/g, '>')
|
| 329 |
+
.replace(/"/g, '"')
|
| 330 |
+
.replace(/'/g, ''')
|
| 331 |
// Simple bold formatting
|
| 332 |
content = content.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>')
|
| 333 |
+
// Simple italic formatting
|
| 334 |
content = content.replace(/\*(.*?)\*/g, '<em>$1</em>')
|
| 335 |
|
| 336 |
elements.push(
|
src/lib/auth.ts
CHANGED
|
@@ -1,7 +1,21 @@
|
|
| 1 |
-
import { randomBytes } from 'crypto'
|
| 2 |
import { getDatabase } from './db'
|
| 3 |
import { hashPassword, verifyPassword } from './password'
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
export interface User {
|
| 6 |
id: number
|
| 7 |
username: string
|
|
@@ -202,7 +216,7 @@ export function getUserFromRequest(request: Request): User | null {
|
|
| 202 |
|
| 203 |
// Check API key - return synthetic user
|
| 204 |
const apiKey = request.headers.get('x-api-key')
|
| 205 |
-
if (apiKey && apiKey
|
| 206 |
return {
|
| 207 |
id: 0,
|
| 208 |
username: 'api',
|
|
|
|
| 1 |
+
import { randomBytes, timingSafeEqual } from 'crypto'
|
| 2 |
import { getDatabase } from './db'
|
| 3 |
import { hashPassword, verifyPassword } from './password'
|
| 4 |
|
| 5 |
+
/**
|
| 6 |
+
* Constant-time string comparison to prevent timing attacks.
|
| 7 |
+
*/
|
| 8 |
+
export function safeCompare(a: string, b: string): boolean {
|
| 9 |
+
if (typeof a !== 'string' || typeof b !== 'string') return false
|
| 10 |
+
const bufA = Buffer.from(a)
|
| 11 |
+
const bufB = Buffer.from(b)
|
| 12 |
+
if (bufA.length !== bufB.length) {
|
| 13 |
+
timingSafeEqual(bufA, bufA)
|
| 14 |
+
return false
|
| 15 |
+
}
|
| 16 |
+
return timingSafeEqual(bufA, bufB)
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
export interface User {
|
| 20 |
id: number
|
| 21 |
username: string
|
|
|
|
| 216 |
|
| 217 |
// Check API key - return synthetic user
|
| 218 |
const apiKey = request.headers.get('x-api-key')
|
| 219 |
+
if (apiKey && safeCompare(apiKey, process.env.API_KEY || '')) {
|
| 220 |
return {
|
| 221 |
id: 0,
|
| 222 |
username: 'api',
|