Fully autonomous AI Agents system capable of performing complex penetration testing tasks
Go ai-agentsai-security-toolanthropicautonomous-agentsgolanggptgraphqlmulti-agent-systemoffensive-securityopen-sourceopenaipenetration-testingpenetration-testing-toolsreactsecurity-automationsecurity-testingsecurity-toolsself-hosted
fix(frontend): clamp page index, sync settings filters, harden inline rename
Sergey Kozyrenkoa8a74316130a
diff --git a/frontend/src/components/shared/inline-rename-input.tsx b/frontend/src/components/shared/inline-rename-input.tsxindex 5d033a05..1f8bcb8e 100644--- a/frontend/src/components/shared/inline-rename-input.tsx+++ b/frontend/src/components/shared/inline-rename-input.tsx@@ -4,6 +4,17 @@ import { type KeyboardEvent, type Ref } from 'react';import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput } from '@/components/ui/input-group';import { cn } from '@/lib/utils';+/**+ * Default upper bound on title length. Chosen as a balance between letting+ * users name things expressively and preventing accidental paste-bombs that+ * would break truncation in tables and breadcrumbs. Backend columns are+ * unbounded `varchar`, so this is purely a UX guard — the HTML `maxLength`+ * attribute below silently stops further typing rather than rejecting the+ * existing value (which lets existing records that exceed this limit still+ * be edited and re-saved without surprise validation errors).+ */+export const INLINE_RENAME_MAX_LENGTH = 200;+interface InlineRenameInputProps {/*** Auto-focus the input on mount. Needed for table-cell call sites that@@ -20,6 +31,14 @@ interface InlineRenameInputProps {defaultValue?: string;/** Ref to the underlying `<input>` element. Pair with `useInlineEditTitle().inputRef`. */inputRef?: Ref<HTMLInputElement>;+ /**+ * Max length applied via the native HTML `maxLength` attribute. Defaults+ * to {@link INLINE_RENAME_MAX_LENGTH}. The browser stops typing past the+ * limit without altering programmatically-set `defaultValue`, so this is+ * a UX guard, not a hard validation gate. Override only when a specific+ * surface has a stricter or looser constraint.+ */+ maxLength?: number;onCancel: () => void;/*** Save handler. Read the latest text from the bound `inputRef` — kept@@ -49,6 +68,7 @@ export const InlineRenameInput = ({className,defaultValue,inputRef,+ maxLength = INLINE_RENAME_MAX_LENGTH,onCancel,onSave,placeholder,@@ -73,6 +93,7 @@ export const InlineRenameInput = ({autoFocus={autoFocus}className="text-foreground"defaultValue={defaultValue}+ maxLength={maxLength}onKeyDown={handleKeyDown}placeholder={placeholder}ref={inputRef}diff --git a/frontend/src/components/ui/data-table.tsx b/frontend/src/components/ui/data-table.tsxindex b182fc4d..67a41396 100644--- a/frontend/src/components/ui/data-table.tsx+++ b/frontend/src/components/ui/data-table.tsx@@ -252,9 +252,17 @@ function DataTable<TData, TValue = unknown>({updateTableState(tableKey, { columnVisibility: internalColumnVisibility });}, [internalColumnVisibility, isColumnVisibilityControlled, tableKey]);+ // Only persist a non-default pageSize. `updateTableState` clears the+ // field when handed `undefined`, so the storage slot stays empty until+ // the user actively picks a different page size. Without this guard the+ // StrictMode dev double-invoke of `useEffectAfterMount` would seed+ // `{ pageSize: 10 }` on every fresh mount — harmless in prod, noisy in+ // dev tooling and surprising when inspecting storage.useEffectAfterMount(() => {- updateTableState(tableKey, { pageSize: pagination.pageSize });- }, [pagination.pageSize, tableKey]);+ updateTableState(tableKey, {+ pageSize: pagination.pageSize === initialPageSize ? undefined : pagination.pageSize,+ });+ }, [initialPageSize, pagination.pageSize, tableKey]);const columnVisibility = externalColumnVisibility ?? internalColumnVisibility;@@ -344,10 +352,40 @@ function DataTable<TData, TValue = unknown>({const pageSizeValue = pagination.pageSize >= data.length && data.length > 0 ? 'all' : String(pagination.pageSize);const totalRows = table.getFilteredRowModel().rows.length;- const rangeStart = totalRows > 0 ? pagination.pageIndex * pagination.pageSize + 1 : 0;- const rangeEnd = Math.min((pagination.pageIndex + 1) * pagination.pageSize, totalRows);const pageCount = table.getPageCount();+ // `pagination.pageIndex` is mirrored from `?page=` (controlled) or the+ // user's clicks (uncontrolled). Either source can point past the actual+ // end of the dataset — hand-typed URLs, a filter narrowing results, or a+ // page-size bump to "All" while we were on a high page. Derive a clamped+ // view for the display values so the user never sees "Page 999 of 31",+ // and reconcile the source of truth via the effect below.+ const safePageIndex = pageCount > 0 ? Math.min(Math.max(0, pagination.pageIndex), pageCount - 1) : 0;+ const rangeStart = totalRows > 0 ? safePageIndex * pagination.pageSize + 1 : 0;+ const rangeEnd = Math.min((safePageIndex + 1) * pagination.pageSize, totalRows);++ // Reconcile the canonical pageIndex once we know `pageCount`. The write+ // has to happen in an effect because `setSearchParams` (controlled mode)+ // and `setPagination` (uncontrolled) both mutate state outside the render+ // pipeline, which React forbids during render. The early return makes the+ // effect a no-op on every render where the URL is already in range, so+ // the cost on the happy path is one comparison.+ useEffect(() => {+ if (pageCount === 0) {+ return;+ }++ if (pagination.pageIndex === safePageIndex) {+ return;+ }++ if (isPageControlled) {+ onPageChange?.(safePageIndex);+ } else {+ setPagination((previous) => ({ ...previous, pageIndex: safePageIndex }));+ }+ }, [isPageControlled, onPageChange, pageCount, pagination.pageIndex, safePageIndex]);+return (<div className="w-full"><div className="flex items-center gap-4 py-4">@@ -524,7 +562,7 @@ function DataTable<TData, TValue = unknown>({</div>{pageCount > 0 ? (<div className="flex items-center justify-center text-xs font-medium lg:w-20">- Page {pagination.pageIndex + 1} of {pageCount}+ Page {safePageIndex + 1} of {pageCount}</div>) : (<divdiff --git a/frontend/src/hooks/use-table-query-filter.ts b/frontend/src/hooks/use-table-query-filter.tsindex 675ae691..1fd866c8 100644--- a/frontend/src/hooks/use-table-query-filter.ts+++ b/frontend/src/hooks/use-table-query-filter.ts@@ -151,15 +151,21 @@ export const useTableQueryFilter = (options: UseTableQueryFilterOptions = {}): Uconst next = new URLSearchParams(previous);next.set(paramName, stored);- if (clearPageParamOnChange) {- next.delete(URL_PARAMS.PAGE);- }-+ // Intentionally do NOT delete `?page=` here. The user's+ // explicit `?page=N` (from a shared link or refresh) is their+ // own request; the replay is restoring prior filter state,+ // not a fresh filter change. If the replayed filter happens+ // to make the requested page out-of-range, the page-index+ // clamp in `DataTable` reconciles it on the next render —+ // see the `safePageIndex` derivation. `clearPageParamOnChange`+ // still applies to `setFilter` below, where the user is+ // actively changing the filter and "page 5 of nothing" is+ // the failure mode we want to avoid.return next;},{ replace: true },);- }, [clearPageParamOnChange, filter, paramName, setSearchParams, storageKey]);+ }, [filter, paramName, setSearchParams, storageKey]);// Persist the URL filter into storage on every commit. Skipping the// first render is intentional: a fresh-mount empty `filter` woulddiff --git a/frontend/src/pages/knowledges/knowledges.tsx b/frontend/src/pages/knowledges/knowledges.tsxindex 14e04e2a..3b4e38ff 100644--- a/frontend/src/pages/knowledges/knowledges.tsx+++ b/frontend/src/pages/knowledges/knowledges.tsx@@ -259,7 +259,11 @@ const Knowledges = () => {);},enableSorting: false,- header: () => null,+ header: () => (+ <span className="text-muted-foreground inline-flex items-center justify-end text-sm font-medium">+ Flags+ </span>+ ),id: 'flags',maxSize: 200,meta: { columnMenuLabel: 'Flags' },diff --git a/frontend/src/pages/settings/settings-api-tokens.tsx b/frontend/src/pages/settings/settings-api-tokens.tsxindex 92b7e186..ea259a0b 100644--- a/frontend/src/pages/settings/settings-api-tokens.tsx+++ b/frontend/src/pages/settings/settings-api-tokens.tsx@@ -53,6 +53,7 @@ import {useUpdateApiTokenMutation,} from '@/graphql/types';import { usePagination } from '@/hooks/use-pagination';+import { useTableQueryFilter } from '@/hooks/use-table-query-filter';import { cn } from '@/lib/utils';import { baseUrl } from '@/models/api';@@ -208,6 +209,7 @@ const SettingsAPITokens = () => {const creatingInputRef = useRef<HTMLInputElement>(null);const { pageIndex: currentPage, setPage: handlePageChange } = usePagination();+ const { filter, setFilter } = useTableQueryFilter();useApiTokenCreatedSubscription({onData: ({ client }) => {@@ -792,6 +794,8 @@ const SettingsAPITokens = () => {data={creatingToken ? [createNewTokenPlaceholder, ...tokens] : tokens}filterColumn="name"filterPlaceholder="Filter token names..."+ filterValue={filter}+ onFilterChange={setFilter}onPageChange={handlePageChange}pageIndex={currentPage}renderRowContextMenu={renderRowContextMenu}diff --git a/frontend/src/pages/settings/settings-providers.tsx b/frontend/src/pages/settings/settings-providers.tsxindex 1b08dfdf..568186b0 100644--- a/frontend/src/pages/settings/settings-providers.tsx+++ b/frontend/src/pages/settings/settings-providers.tsx@@ -36,6 +36,7 @@ import { StatusCard } from '@/components/ui/status-card';import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip';import { ProviderType, useDeleteProviderMutation, useSettingsProvidersQuery } from '@/graphql/types';import { usePagination } from '@/hooks/use-pagination';+import { useTableQueryFilter } from '@/hooks/use-table-query-filter';type Provider = ProviderConfigFragmentFragment;const providerIcons: Record<ProviderType, React.ComponentType<any>> = {@@ -132,6 +133,7 @@ const SettingsProviders = () => {const navigate = useNavigate();const { pageIndex: currentPage, setPage: handlePageChange } = usePagination();+ const { filter, setFilter } = useTableQueryFilter();const handleProviderDelete = useCallback(async (providerId: string | undefined) => {@@ -477,6 +479,8 @@ const SettingsProviders = () => {data={providers}filterColumn="name"filterPlaceholder="Filter provider names..."+ filterValue={filter}+ onFilterChange={setFilter}onPageChange={handlePageChange}pageIndex={currentPage}renderRowContextMenu={renderRowContextMenu}