Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ dmypy.json

# Claude Code
.claude/settings.local.json
.worktrees/

# mkdocs
/site
Expand Down
35 changes: 34 additions & 1 deletion components/frontend/src/app/projects/[name]/keys/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/com
import { Input } from '@/components/ui/input';
import { Badge } from '@/components/ui/badge';
import { Label } from '@/components/ui/label';
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog';
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table';
import { ErrorMessage } from '@/components/error-message';
Expand All @@ -21,6 +22,17 @@ import { toast } from 'sonner';
import type { CreateKeyRequest } from '@/services/api/keys';
import { ROLE_DEFINITIONS } from '@/lib/role-colors';

const EXPIRATION_OPTIONS = [
{ value: '86400', label: '1 day' },
{ value: '604800', label: '7 days' },
{ value: '2592000', label: '30 days' },
{ value: '7776000', label: '90 days' },
{ value: '31536000', label: '1 year' },
{ value: 'none', label: 'No expiration' },
] as const;

const DEFAULT_EXPIRATION = '7776000'; // 90 days

export default function ProjectKeysPage() {
const params = useParams();
const projectName = params?.name as string;
Expand All @@ -35,6 +47,7 @@ export default function ProjectKeysPage() {
const [newKeyName, setNewKeyName] = useState('');
const [newKeyDesc, setNewKeyDesc] = useState('');
const [newKeyRole, setNewKeyRole] = useState<'view' | 'edit' | 'admin'>('edit');
const [newKeyExpiration, setNewKeyExpiration] = useState(DEFAULT_EXPIRATION);
const [oneTimeKey, setOneTimeKey] = useState<string | null>(null);
const [oneTimeKeyName, setOneTimeKeyName] = useState<string>('');
const [showDeleteDialog, setShowDeleteDialog] = useState(false);
Expand All @@ -47,6 +60,7 @@ export default function ProjectKeysPage() {
name: newKeyName.trim(),
description: newKeyDesc.trim() || undefined,
role: newKeyRole,
expirationSeconds: newKeyExpiration !== 'none' ? Number(newKeyExpiration) : undefined,
};

createKeyMutation.mutate(
Expand All @@ -58,14 +72,15 @@ export default function ProjectKeysPage() {
setOneTimeKeyName(data.name);
setNewKeyName('');
setNewKeyDesc('');
setNewKeyExpiration(DEFAULT_EXPIRATION);
setShowCreate(false);
Comment on lines +75 to 76
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Reset token lifetime when the dialog closes, not only on success

Line 75 resets the lifetime only after a successful create. If a user selects No expiration and closes/cancels, reopening can retain that prior value, increasing risk of accidentally creating long-lived keys.

Proposed fix
+  const handleCreateDialogOpenChange = useCallback((open: boolean) => {
+    setShowCreate(open);
+    if (!open) {
+      setNewKeyExpiration(DEFAULT_EXPIRATION);
+    }
+  }, []);
+
   {/* Create Key Dialog */}
-  <Dialog open={showCreate} onOpenChange={setShowCreate}>
+  <Dialog open={showCreate} onOpenChange={handleCreateDialogOpenChange}>
     <DialogContent className="sm:max-w-[425px]">
...
             <Button
               variant="outline"
-              onClick={() => setShowCreate(false)}
+              onClick={() => handleCreateDialogOpenChange(false)}
               disabled={createKeyMutation.isPending}
             >

As per coding guidelines, "Focus on major issues impacting performance, readability, maintainability and security. Avoid nitpicks and avoid verbosity."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@components/frontend/src/app/projects/`[name]/keys/page.tsx around lines 75 -
76, Reset the new key expiration whenever the create dialog is closed (both on
success and on cancel/close) rather than only after successful creation: ensure
any close handler that calls setShowCreate(false) also calls
setNewKeyExpiration(DEFAULT_EXPIRATION) (or add a centralized onClose function
used by both the success path and the cancel/close UI) so the component state
(setNewKeyExpiration and DEFAULT_EXPIRATION) is restored whenever the dialog is
dismissed.

},
onError: (error) => {
toast.error(error instanceof Error ? error.message : 'Failed to create key');
},
}
);
}, [newKeyName, newKeyDesc, newKeyRole, projectName, createKeyMutation]);
}, [newKeyName, newKeyDesc, newKeyRole, newKeyExpiration, projectName, createKeyMutation]);

const openDeleteDialog = useCallback((keyId: string, keyName: string) => {
setKeyToDelete({ id: keyId, name: keyName });
Expand Down Expand Up @@ -286,6 +301,24 @@ export default function ProjectKeysPage() {
})}
</div>
</div>
<div className="space-y-2">
<Label htmlFor="key-expiration">Token Lifetime</Label>
<Select value={newKeyExpiration} onValueChange={setNewKeyExpiration}>
<SelectTrigger className="w-full">
<SelectValue placeholder="Select lifetime" />
</SelectTrigger>
<SelectContent>
{EXPIRATION_OPTIONS.map((opt) => (
<SelectItem key={opt.value} value={opt.value}>
{opt.label}
</SelectItem>
))}
</SelectContent>
</Select>
<p className="text-xs text-muted-foreground">
How long the token remains valid. Choose &quot;No expiration&quot; for long-lived service keys.
</p>
</div>
</div>
<DialogFooter>
<Button
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ export { SessionsSection } from './sessions-section';
export { SharingSection } from './sharing-section';
export { SettingsSection } from './settings-section';
export { FeatureFlagsSection } from './feature-flags-section';
export { KeysSection } from './keys-section';
Loading
Loading