Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix: clear CI and CodeQL findings

Mecff8a00c61d
diff --git a/control-api/package-lock.json b/control-api/package-lock.json
index 211f524b5..aa041be5d 100644
--- a/control-api/package-lock.json
+++ b/control-api/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-api",
- "version": "0.1.604",
+ "version": "0.1.605",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-api",
- "version": "0.1.604",
+ "version": "0.1.605",
"dependencies": {
"@clerum/display-field": "file:../packages/display-field",
"@clerum/grok-provider-attempt-contract": "file:../packages/grok-provider-attempt-contract",
diff --git a/control-api/package.json b/control-api/package.json
index 64d00e152..adeb0d846 100644
--- a/control-api/package.json
+++ b/control-api/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-api",
- "version": "0.1.604",
+ "version": "0.1.605",
"description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets",
"main": "dist/main.js",
"engines": {
diff --git a/control-api/src/routes/gfs/resources.ts b/control-api/src/routes/gfs/resources.ts
index e5a7f1d94..11543b3e3 100644
--- a/control-api/src/routes/gfs/resources.ts
+++ b/control-api/src/routes/gfs/resources.ts
@@ -6,9 +6,12 @@
* extraction of the drive-lock + tree-walk skeleton is a known follow-up.
*/
import type { Request, Response, Router } from 'express'
+import { ipKeyGenerator, rateLimit } from 'express-rate-limit'
+import { createHash } from 'node:crypto'
import { withTransaction } from '../../db.js'
import { asyncHandler } from '../../http/asyncHandler.js'
-import { requireAuthForControlUI } from '../../middleware/controlUIAuth.js'
+import { type UiAuthedRequest, requireAuthForControlUI } from '../../middleware/controlUIAuth.js'
+import { rateLimitMiddleware } from '../../middleware/rateLimitMiddleware.js'
import {
type GfsCaller,
type GrantsDb,
@@ -22,6 +25,8 @@ import {
} from './grants.js'
const NAME_MAX = 255
+const GFS_RESOURCE_READ_RATE_LIMIT_PER_MINUTE = 120
+const GFS_RESOURCE_WRITE_RATE_LIMIT_PER_MINUTE = 30
// eslint-disable-next-line no-control-regex
const CONTROL_CHARS = /[\x00-\x1f\x7f]/
export class ResourcePatchError extends Error {
@@ -135,6 +140,26 @@ function directoryPath(rows: AncestorRow[]): string {
}
const sameChain = (a: AncestorRow[], b: AncestorRow[]) =>
a.length === b.length && a.every((row, i) => row.resource_id === b[i]?.resource_id)
+
+function gfsResourceRateLimitKey(prefix: string, req: Request): string {
+ const subject = (req as UiAuthedRequest).adminAuth?.sub
+ if (subject) {
+ const subjectHash = createHash('sha256').update(subject).digest('hex').slice(0, 32)
+ return `${prefix}:admin:${subjectHash}`
+ }
+ return `${prefix}:ip:${ipKeyGenerator(req.ip ?? 'unknown')}`
+}
+
+function gfsResourceRateLimitHandler(_req: Request, res: Response): void {
+ const raw = res.getHeader('Retry-After')
+ const retryAfterSeconds =
+ typeof raw === 'number' && Number.isSafeInteger(raw) && raw > 0
+ ? raw
+ : typeof raw === 'string' && /^\d+$/.test(raw)
+ ? Math.max(1, Number(raw))
+ : 60
+ res.status(429).json({ error: 'Too Many Requests', retryAfterSeconds })
+}
async function refreshSubtreePaths(
db: GrantsDb,
drive: string,
@@ -348,9 +373,41 @@ export async function applyResourcePatch(
}
export function registerGfsResourceRoutes(router: Router): void {
+ // The Postgres buckets enforce the limit across replicas. The direct
+ // express-rate-limit guards are an in-process backstop and make the bound
+ // visible to CodeQL before the route reaches its ACL work.
+ const affordancesRateLimit = rateLimitMiddleware({
+ bucketType: 'gfs_resources_read',
+ maxPerMinute: GFS_RESOURCE_READ_RATE_LIMIT_PER_MINUTE,
+ getBucketKey: req => gfsResourceRateLimitKey('gfsresources-read', req),
+ })
+ const affordancesEdgeRateLimit = rateLimit({
+ windowMs: 60_000,
+ limit: GFS_RESOURCE_READ_RATE_LIMIT_PER_MINUTE,
+ standardHeaders: 'draft-7',
+ legacyHeaders: false,
+ keyGenerator: req => gfsResourceRateLimitKey('gfsresources-read-edge', req),
+ handler: gfsResourceRateLimitHandler,
+ })
+ const resourcePatchRateLimit = rateLimitMiddleware({
+ bucketType: 'gfs_resources_mutation',
+ maxPerMinute: GFS_RESOURCE_WRITE_RATE_LIMIT_PER_MINUTE,
+ getBucketKey: req => gfsResourceRateLimitKey('gfsresources-write', req),
+ })
+ const resourcePatchEdgeRateLimit = rateLimit({
+ windowMs: 60_000,
+ limit: GFS_RESOURCE_WRITE_RATE_LIMIT_PER_MINUTE,
+ standardHeaders: 'draft-7',
+ legacyHeaders: false,
+ keyGenerator: req => gfsResourceRateLimitKey('gfsresources-write-edge', req),
+ handler: gfsResourceRateLimitHandler,
+ })
+
router.get(
'/gfs/resources/:id/affordances',
requireAuthForControlUI,
+ affordancesEdgeRateLimit,
+ affordancesRateLimit,
asyncHandler(async (req, res) => {
const id = String(req.params.id)
if (!UUID_RE.test(id)) {
@@ -374,7 +431,13 @@ export function registerGfsResourceRoutes(router: Router): void {
})
})
)
- router.patch('/gfs/resources/:id', requireAuthForControlUI, asyncHandler(handlePatch))
+ router.patch(
+ '/gfs/resources/:id',
+ requireAuthForControlUI,
+ resourcePatchEdgeRateLimit,
+ resourcePatchRateLimit,
+ asyncHandler(handlePatch)
+ )
}
export async function handlePatch(req: Request, res: Response): Promise<void> {
diff --git a/control-ui/components/GfsGrantPanel.tsx b/control-ui/components/GfsGrantPanel.tsx
index 56135944f..9753d10cd 100644
--- a/control-ui/components/GfsGrantPanel.tsx
+++ b/control-ui/components/GfsGrantPanel.tsx
@@ -563,7 +563,10 @@ export function GfsGrantPanel({ resource }: GfsGrantPanelProps): React.JSX.Eleme
if (!inherited) return
if (nextRole === roleForPermissions(row.permissions)) return
const affected = planInheritedRoleChange(inherited, nextRole === 'editor')
- if (affected.length === 0 && !row.direct) return
+ if (affected.length === 0) {
+ if (row.direct) await updateAccessRole(row.direct, nextRole)
+ return
+ }
const updates: Array<{ source: GfsInheritedAccessSource; permissions: string[] }> = []
for (const source of affected) {
diff --git a/control-ui/components/__tests__/GfsGrantPanel.inherited.test.tsx b/control-ui/components/__tests__/GfsGrantPanel.inherited.test.tsx
index 577997f9a..72a350441 100644
--- a/control-ui/components/__tests__/GfsGrantPanel.inherited.test.tsx
+++ b/control-ui/components/__tests__/GfsGrantPanel.inherited.test.tsx
@@ -770,6 +770,27 @@ describe('GfsGrantPanel inherited access', () => {
expect(mockDeleteGfsShare).not.toHaveBeenCalled()
})
+ it('updates only the direct grant when the inherited floor already has the target role', async () => {
+ // Direct Editor grant on the file + inherited Read floor on campaigns:
+ // lowering the merged role to Read must not open an empty parent-folder
+ // confirmation; only the direct file grant needs alignment.
+ driveScenario({ campaigns: VIEWER, fileGrant: EDITOR })
+ const row = await openRoleDialog()
+
+ await chooseRole(row, 'Read')
+
+ expect(screen.queryByRole('alertdialog')).toBeNull()
+ await waitFor(() => expect(mockPutGfsGrant).toHaveBeenCalledTimes(1))
+ expect(mockPutGfsGrant).toHaveBeenCalledWith({
+ drive: 'main',
+ resourceId: FILE_ID,
+ subject: miguel,
+ permissions: VIEWER,
+ inherit: false,
+ })
+ expect(mockGetGfsAffordances).not.toHaveBeenCalled()
+ })
+
it('states the true partial outcome when a folder update fails mid-run', async () => {
driveScenario({ campaigns: EDITOR, marketing: EDITOR })
mockPutGfsGrant.mockImplementation(async body => {
diff --git a/control-ui/components/__tests__/gfsInheritedAccess.test.ts b/control-ui/components/__tests__/gfsInheritedAccess.test.ts
new file mode 100644
index 000000000..54e30296a
--- /dev/null
+++ b/control-ui/components/__tests__/gfsInheritedAccess.test.ts
@@ -0,0 +1,75 @@
+import { beforeEach, describe, expect, it, vi } from 'vitest'
+import { getGfsGrants, getGfsResourceByPath, getGfsShares } from '@lib/api'
+import { loadGfsInheritedAccess } from '../gfsInheritedAccess'
+
+vi.mock('@lib/api', () => ({
+ getGfsGrants: vi.fn(),
+ getGfsResourceByPath: vi.fn(),
+ getGfsShares: vi.fn(),
+}))
+
+const mockGetGfsGrants = vi.mocked(getGfsGrants)
+const mockGetGfsResourceByPath = vi.mocked(getGfsResourceByPath)
+const mockGetGfsShares = vi.mocked(getGfsShares)
+
+function resourceView(resourceId: string, name: string, path: string) {
+ return {
+ resourceId,
+ rid: resourceId,
+ gfsUri: `gfs://main/${resourceId}`,
+ drive: 'main',
+ name,
+ kind: 'directory',
+ path,
+ version: 1,
+ updatedAt: '2026-01-01T00:00:00Z',
+ }
+}
+
+describe('loadGfsInheritedAccess', () => {
+ beforeEach(() => {
+ vi.clearAllMocks()
+ mockGetGfsShares.mockResolvedValue({ items: [] })
+ })
+
+ it('skips an ancestor ACL failure and continues with higher ancestors', async () => {
+ mockGetGfsResourceByPath.mockImplementation(async (_drive, path) => {
+ if (path === '/nested') return resourceView('nested-folder', 'nested', '/nested')
+ if (path === '/') return resourceView('root-folder', '', '/')
+ throw new Error('unexpected path')
+ })
+ mockGetGfsGrants.mockImplementation(async resourceId => {
+ if (resourceId === 'nested-folder') throw new Error('403 manage_acl_required')
+ return {
+ items: [
+ {
+ id: 'root-grant',
+ drive: 'main',
+ resourceId: 'root-folder',
+ subject: { type: 'user', id: 'member-1' },
+ permissions: ['read'],
+ inherit: true,
+ },
+ ],
+ }
+ })
+
+ await expect(loadGfsInheritedAccess('/nested/report.md', 'main')).resolves.toEqual([
+ {
+ subject: { type: 'user', id: 'member-1' },
+ permissions: ['read'],
+ inheritedFrom: ['main'],
+ sources: [
+ {
+ resourceId: 'root-folder',
+ name: 'main',
+ permissions: ['read'],
+ grantId: 'root-grant',
+ shareIds: [],
+ },
+ ],
+ },
+ ])
+ expect(mockGetGfsResourceByPath.mock.calls.map(([, path]) => path)).toEqual(['/nested', '/'])
+ })
+})
diff --git a/control-ui/package-lock.json b/control-ui/package-lock.json
index f00f3900c..2f7f229cf 100644
--- a/control-ui/package-lock.json
+++ b/control-ui/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-ui",
- "version": "0.1.608",
+ "version": "0.1.609",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-ui",
- "version": "0.1.608",
+ "version": "0.1.609",
"dependencies": {
"@clerum/display-field": "file:../packages/display-field",
"@clerum/frontend-components": "file:../packages/frontend-components",
diff --git a/control-ui/package.json b/control-ui/package.json
index fb19480cd..38857b5dc 100644
--- a/control-ui/package.json
+++ b/control-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-ui",
- "version": "0.1.608",
+ "version": "0.1.609",
"private": true,
"scripts": {
"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",
diff --git a/desktop-app/ui/src/gfs/GfsInheritedAccessDialog/index.tsx b/desktop-app/ui/src/gfs/GfsInheritedAccessDialog/index.tsx
index 58970abf3..51a818e61 100644
--- a/desktop-app/ui/src/gfs/GfsInheritedAccessDialog/index.tsx
+++ b/desktop-app/ui/src/gfs/GfsInheritedAccessDialog/index.tsx
@@ -100,7 +100,7 @@ export function GfsInheritedAccessDialog({
</p>
<div className="da-gfs-parent-update-dialog__folders">
{request.folders.map(folder => (
- <div className="da-gfs-parent-update-dialog__folder" key={folder.name}>
+ <div className="da-gfs-parent-update-dialog__folder" key={folder.resourceId}>
<span className="da-gfs-parent-update-dialog__name">{folder.name}</span>
<span className="da-gfs-parent-update-dialog__change">
<span className="da-gfs-parent-update-dialog__role">
diff --git a/desktop-app/ui/src/hooks/domain/__tests__/useGfsBrowserController.test.tsx b/desktop-app/ui/src/hooks/domain/__tests__/useGfsBrowserController.test.tsx
index a8fcc644a..a5ccb5414 100644
--- a/desktop-app/ui/src/hooks/domain/__tests__/useGfsBrowserController.test.tsx
+++ b/desktop-app/ui/src/hooks/domain/__tests__/useGfsBrowserController.test.tsx
@@ -1132,7 +1132,7 @@ describe('useGfsBrowserController', () => {
await waitFor(() => expect(screen.getByTestId('accessible-count').textContent).toBe('0'))
expect(screen.getByTestId('accessible-error').textContent).toBe('none')
expect(screen.getByTestId('accessible-notice').textContent).toContain(
- 'Automatic EvenDrive discovery is not available'
+ 'Automatic GFS discovery is not available in this desktop runtime'
)
await act(async () => {
@@ -1166,7 +1166,7 @@ describe('useGfsBrowserController', () => {
await waitFor(() =>
expect(screen.getByTestId('accessible-notice').textContent).toContain(
- 'Automatic EvenDrive discovery is not available'
+ 'Automatic GFS discovery is not available from this server yet'
)
)
expect(screen.getByTestId('accessible-error').textContent).toBe('none')
diff --git a/desktop-app/ui/src/pages/FilesPage.tsx b/desktop-app/ui/src/pages/FilesPage.tsx
index ba71ec004..07ff2f8fe 100644
--- a/desktop-app/ui/src/pages/FilesPage.tsx
+++ b/desktop-app/ui/src/pages/FilesPage.tsx
@@ -667,6 +667,7 @@ export function FilesPage({
return
}
const sources = inherited.sources
+ const [firstSource] = sources
const subject = inherited.subject
const subjectKey = subject.id ? `${subject.type}:${subject.id}` : subject.type
const label = request.label
@@ -712,7 +713,7 @@ export function FilesPage({
}
pushToast?.(
sources.length === 1
- ? `Access removed on ${sources[0].name} and everything inside it`
+ ? `Access removed on ${firstSource?.name ?? current?.name ?? 'this file'} and everything inside it`
: `Access removed on ${sources.length} folders and everything inside them`,
'success'
)