Skip to content

Add frontend for managing API keys#22

Merged
j4ys0n merged 12 commits into
mainfrom
claude/add-api-key-management-yJiMg
Dec 17, 2025
Merged

Add frontend for managing API keys#22
j4ys0n merged 12 commits into
mainfrom
claude/add-api-key-management-yJiMg

Conversation

@j4ys0n
Copy link
Copy Markdown
Owner

@j4ys0n j4ys0n commented Dec 16, 2025

No description provided.

- Add ApiKeyManager utility for safe JSON-based API key storage
- Add ApiKeyController with CRUD endpoints for API key management
- Create Vue 3 Composition API frontend for managing API keys
- Add /admin and /keys routes to serve the management interface
- Implement file locking to prevent concurrent write issues
- Add user-to-API-key association tracking
- Create separate Vue 3 project in frontend/ directory with own package.json
- Use Vite as build tool and Vue 3 Composition API with <script setup>
- Update Dockerfile to build both frontend and backend projects
- Update backend build script to copy frontend build output to dist/static
- Remove incorrect package-lock.json (project uses yarn)
- Remove CDN-based static HTML file
- Frontend builds to frontend/dist, then copied to dist/static during backend build
- Add jest, ts-jest, and @types/jest dependencies
- Create jest.config.js for TypeScript support
- Add comprehensive tests for ApiKeyManager (15 tests covering CRUD operations)
- Update GitHub Actions workflow to run tests on push and PR
- Test job runs before build job to ensure code quality
- All tests passing successfully
- Update GitHub Actions workflow to run only on PR events (opened, synchronize, reopened)
- Add in-memory cache to ApiKeyManager for faster API key lookups
- Keys are loaded into memory on initialization and kept in sync with disk
- Add apiKeyMiddleware to validate API keys before proxying LLM requests
- LLM proxy now validates API keys against stored keys (revocation support)
- All API key operations use cache, eliminating repeated disk reads
- Tests continue to pass with new caching behavior
Implement comprehensive per-API-key request tracking with:
- RequestTracker utility for CSV-based storage (epoch ms timestamps)
- Track start/end times per request (null endTime for failures)
- In-memory caching of last week's data
- Analytics API endpoint with date range query support
- Frontend analytics tab with table display and date pickers
- Request success/failure status tracking in middleware

Analytics features:
- Default view shows last week of data
- Custom date range picker for historical queries
- Table displays: start time (dd/mm/yyyy hh:mm:ss), elapsed (ms), status
- Summary statistics: total requests, successful, failed

Modified apiKeyMiddleware to intercept response completion and track timing data.
@j4ys0n
Copy link
Copy Markdown
Owner Author

j4ys0n commented Dec 16, 2025

Automated review 🤖

Summary of Changes

This pull request introduces a comprehensive frontend application for managing API keys within the LLM Proxy system. The changes include adding Vue.js-based UI components for authentication, API key creation/deletion, and analytics viewing. Backend support is enhanced with new controllers for API key management and analytics tracking, along with updated middleware for API key validation and request monitoring. CI workflows are also improved to include testing and better build processes.

Key Changes & Positives

Frontend Implementation: 🟢 Added complete Vue.js frontend with login, API key management, and analytics views
Backend Controllers: 🟢 Implemented dedicated controllers for API key CRUD operations and analytics retrieval
Authentication Middleware: 🟢 Enhanced auth middleware to support both JWT and API key validation
Request Tracking: 🟢 Added request tracking functionality to monitor usage statistics per API key
CI Workflow Improvements: 🟢 Updated GitHub Actions workflow to include automated testing and proper build sequence

Potential Issues & Recommendations

  1. Issue / Risk: Insecure local storage usage for auth tokens

    • Impact: Tokens stored in localStorage are vulnerable to XSS attacks
    • Recommendation: Use HttpOnly cookies with secure flags instead of localStorage
    • Status: 🔴 Problem
  2. Issue / Risk: Hardcoded API endpoints in frontend

    • Impact: Makes deployment less flexible and harder to maintain
    • Recommendation: Move API endpoint URLs to environment variables/config
    • Status: 🟡 Needs review
  3. Issue / Risk: Frontend lacks input sanitization/validation

    • Impact: Could lead to security vulnerabilities like XSS or injection
    • Recommendation: Implement robust client-side validation and sanitization
    • Status: 🟡 Needs review
  4. Issue / Risk: Missing rate limiting on API key endpoints

    • Impact: Potential abuse of key creation/deletion endpoints
    • Recommendation: Add rate limiting middleware to prevent spam
    • Status: 🟡 Needs review
  5. Issue / Risk: Analytics date filtering could cause performance issues

    • Impact: Large datasets might slow down query responses
    • Recommendation: Consider pagination or caching strategies for analytics queries
    • Status: 🟡 Needs review

Language/Framework Checks

TypeScript/Node

✅ Proper error handling in API controllers with try/catch blocks
✅ Type safety maintained through interfaces for API keys and request records
✅ Dependency injection pattern used in controller constructors
⚠️ Missing unit tests for core business logic in utils modules
⚠️ No input validation beyond basic field presence checks

Vue.js

✅ Component-based architecture with single-file components
✅ Reactive state management using Vue 3 Composition API
⚠️ Inline styles rather than CSS modules/scoped styles
⚠️ Direct DOM manipulation via document.createElement() in copy function

Go

❌ Not present in this diff

Python

❌ Not present in this diff

HCL/Terraform

❌ Not present in this diff

YAML/CI

✅ Proper job sequencing with test step before build
✅ Path filtering prevents unnecessary builds on documentation changes
⚠️ Limited test coverage configuration (missing coverage thresholds)

Docker

✅ Multi-stage build approach separates dev/test from prod
⚠️ Base image tag uses latest tag instead of pinned versions
⚠️ Missing .dockerignore rules for excluding development files

Security & Privacy

🔴 Token Storage Vulnerability: LocalStorage usage for auth tokens exposes session to XSS attacks
🟡 Input Validation: Basic validation but no sanitization or escaping implemented
⚠️ Environment Variables: No explicit mention of secret management practices
⚠️ CORS Configuration: Not reviewed in diff but important for frontend security

Build/CI & Ops

✅ Automated Testing: Jest configured with proper test discovery
✅ Build Process: Multi-step build including frontend compilation
⚠️ Artifact Caching: No explicit caching strategy mentioned for build steps
⚠️ Deployment Strategy: Not covered in diff but would benefit from rollback procedures

Tests

🟢 Unit tests added for API key utility functions
⚠️ Missing integration tests for API endpoints
⚠️ No end-to-end browser tests for frontend interactions
⚠️ Test coverage gaps in auth middleware and analytics controllers

Approval Recommendation

Approve with caveats

The PR introduces valuable frontend capabilities for API key management and analytics. However, several security concerns need addressing:

  1. Critical: Replace localStorage with secure session storage for auth tokens
  2. Major: Add comprehensive input validation and sanitization
  3. Medium: Implement rate limiting on sensitive API endpoints
  4. Medium: Add more thorough testing coverage for backend logic

Once these security and quality improvements are addressed, the PR will be ready for production use. The feature implementation itself is well-structured and follows modern patterns.

Security Enhancements:
- Implement HttpOnly cookie-based authentication (XSS protection)
- Add comprehensive input validation using Joi library
- Configure CORS with credential support
- Replace DOM manipulation with proper Vue patterns

Validation:
- Username: 3-50 chars, alphanumeric only
- Password: 8-128 chars
- API keys: 64-char hex string format validation
- Timestamps: reasonable range validation
- All endpoints validate inputs before processing

Testing:
- Add unit tests for analytics controller
- Test coverage for validation logic
- Test auth middleware (token and API key)
- All tests passing with Jest

Infrastructure:
- Add .dockerignore for optimized builds
- Update dependencies (cookie-parser, cors, joi)
- Add cookie-parser middleware
- CORS origin configurable via CORS_ORIGIN env var

Frontend Updates:
- Remove localStorage entirely (security risk)
- Use cookies with credentials: 'include'
- Simplified clipboard with fallback message
- Check authentication on mount via API call

Backend Updates:
- New /auth/login endpoint (cookie-based)
- New /auth/logout endpoint
- Legacy /auth/token maintained for API clients
- TokenMiddleware supports both cookies and Bearer tokens
- All validation errors return descriptive messages

Documentation:
- Comprehensive README update
- Security practices section
- Secret management best practices
- API endpoint documentation
- Development and testing guide
- Troubleshooting section
@j4ys0n
Copy link
Copy Markdown
Owner Author

j4ys0n commented Dec 17, 2025

Automated review 🤖

Summary of Changes

This pull request introduces a comprehensive frontend UI for managing API keys within the LLM proxy system. It adds a Vue 3-based administration panel allowing users to create, view, and delete API keys, along with analytics tracking for API usage. The backend is enhanced with new API endpoints for key management and analytics, including validation, persistence, and request tracking capabilities. The README documentation has been significantly expanded to cover the new features and updated deployment instructions.

Key Changes & Positives

  • 🟢 Adds complete frontend UI with Vue 3 for API key management and analytics dashboard
  • 🟢 Implements robust API key lifecycle management (create, list, delete) with validation
  • 🟢 Introduces request analytics tracking with CSV-based storage and date filtering
  • 🟢 Enhances security with cookie-based authentication for web UI and Bearer token for API
  • 🟢 Updates documentation with detailed setup guides, security practices, and API references
  • 🟢 Improves CI pipeline with dedicated test job and proper workflow triggers
  • 🟢 Adds comprehensive unit tests for API key management and analytics components

Potential Issues & Recommendations

  1. Issue / Risk: Frontend lacks proper loading states during API operations

    • Impact: User experience degradation during slow network conditions
    • Recommendation: Implement loading spinners and disabled buttons during async operations
    • Status: 🟡 Needs review
  2. Issue / Risk: Clipboard functionality fallback is minimal

    • Impact: Users on insecure contexts (HTTP) might see confusing messages
    • Recommendation: Provide more informative UX guidance for clipboard failures
    • Status: 🟡 Needs review
  3. Issue / Risk: Analytics data retention policy unclear

    • Impact: Long-term storage growth without cleanup mechanism
    • Recommendation: Add automatic cleanup of old analytics data beyond 7-day window
    • Status: 🟡 Needs review
  4. Issue / Risk: Missing rate limiting on API key endpoints

    • Impact: Potential abuse of key creation/deletion endpoints
    • Recommendation: Implement rate limiting for key management endpoints
    • Status: 🔴 Problem
  5. Issue / Risk: Hardcoded API key length validation

    • Impact: Less flexible than configurable validation rules
    • Recommendation: Move key format validation to config or constants
    • Status: 🟡 Needs review

Language/Framework Checks

  • TypeScript/Node: ✅ Proper use of interfaces, async/await, and modular architecture
  • Vue 3: ✅ Modern composition API usage with reactive refs and computed properties
  • Express/Node: ✅ Good middleware pattern with token and API key validation
  • Testing: ✅ Comprehensive Jest test suite with mocks and integration testing

Security & Privacy

  • ✅ HttpOnly cookies for session management
  • ✅ Secure JWT token handling with proper expiration
  • ✅ Input validation using Joi schemas
  • ✅ API key validation occurs in-memory for immediate revocation
  • � API keys stored with associated usernames for audit trail
  • � All sensitive data properly sanitized before logging

Build/CI & Ops

  • ✅ Updated Dockerfile builds both frontend and backend
  • ✅ Enhanced CI workflow with separate test job
  • ✅ Proper .dockerignore excludes unnecessary files
  • � No explicit healthchecks or readiness probes defined
  • � No automated backup strategy for analytics data

Tests

  • ✅ Full unit test coverage for API key management
  • ✅ Comprehensive analytics controller tests
  • ✅ Integration-ready test structure
  • � Missing end-to-end tests for frontend interactions
  • � No performance tests for high-volume key operations

Approval Recommendation

Approve with caveats

✅ Core functionality works well with good security practices and comprehensive testing.

⚠️ Blockers/Concerns:

  • Rate limiting missing on key management endpoints
  • Analytics data retention policy needs clarification
  • Clipboard UX could be improved for failure cases

The PR delivers significant value with its new frontend and robust backend infrastructure. Addressing the blocking issues would improve production readiness.

- Downgrade Joi from 18.0.2 to 17.13.3
- Joi 18 requires Node >= 20, project uses Node 18.20.8
- All tests passing with Joi 17.13.3
@j4ys0n
Copy link
Copy Markdown
Owner Author

j4ys0n commented Dec 17, 2025

Automated review 🤖

Summary of Changes

This pull request introduces a comprehensive frontend UI for managing API keys within the LLM proxy system. It adds a Vue 3-based administration panel with features for creating, listing, and deleting API keys, along with analytics tracking capabilities. The backend is enhanced with new API endpoints for key management and analytics, including input validation, authentication middleware, and request tracking functionality. The Docker build process is updated to include frontend compilation, and CI workflows are improved with dedicated testing steps.

Key Changes & Positives

  • 🟢 Adds complete Vue 3 frontend for API key management with tabbed interface
  • 🟢 Implements robust API key lifecycle management (create/list/delete)
  • 🟢 Introduces analytics dashboard showing request tracking per key
  • 🟢 Enhances security with cookie-based authentication and API key validation
  • 🟢 Updates Docker build to compile and bundle frontend assets
  • 🟢 Improves CI pipeline with separate test job and proper workflow triggers
  • 🟢 Adds comprehensive unit tests for API key and analytics components
  • 🟢 Includes extensive documentation updates with detailed API reference

Potential Issues & Recommendations

  1. Issue / Risk: Frontend lacks loading states during API operations

    • Impact: Poor UX during slow network conditions
    • Recommendation: Add loading spinners and disabled buttons during async operations
    • Status: 🟡 Needs review
  2. Issue / Risk: Clipboard copy fallback mechanism isn't fully tested

    • Impact: Potential failure in non-HTTPS environments
    • Recommendation: Add more robust browser feature detection and improve error messaging
    • Status: 🟡 Needs review
  3. Issue / Risk: Analytics date filtering doesn't handle timezone differences properly

    • Impact: Incorrect date range queries in multi-zone deployments
    • Recommendation: Normalize timestamps to UTC before filtering
    • Status: 🟡 Needs review
  4. Issue / Risk: Missing rate limiting on API key endpoints

    • Impact: Potential abuse of key creation/deletion endpoints
    • Recommendation: Implement rate limiting middleware for sensitive endpoints
    • Status: 🔴 Problem
  5. Issue / Risk: Hardcoded frontend route references in backend

    • Impact: Fragile routing if frontend paths change
    • Recommendation: Move hardcoded paths to environment variables or config
    • Status: 🔴 Problem

Language/Framework Checks

  • TypeScript/Node: ✅ Proper use of interfaces, async/await, and error handling
  • Vue 3: ✅ Composition API usage, reactive state management, proper emits
  • Express/Node: ✅ Middleware pattern, proper error responses, CORS configuration
  • Joi: ✅ Comprehensive input validation schemas with clear error messages
  • Docker: ✅ Multi-stage build with proper layer optimization, .dockerignore inclusion

Security & Privacy

  • 🟢 HttpOnly cookies for authentication prevent XSS attacks
  • 🟢 API key validation occurs in-memory with immediate revocation capability
  • 🟢 Input validation prevents injection attacks across all endpoints
  • 🟢 Secure cookie flags based on NODE_ENV setting
  • 🔴 No rate limiting implemented for key management endpoints
  • 🔴 Frontend exposes raw API key values in UI (could be mitigated with masking)

Build/CI & Ops

  • 🟢 Updated Dockerfile builds frontend and includes it in distribution
  • 🟢 CI workflow now includes explicit test step with proper triggers
  • 🟢 README updated with comprehensive installation and configuration instructions
  • 🟢 Package.json updated with proper build script and test command

Tests

  • ✅ Added unit tests for API key manager with edge cases
  • ✅ Added integration tests for analytics controller
  • ✅ Added comprehensive validation tests
  • 🟡 Missing snapshot tests for frontend components
  • 🟡 Need E2E tests for full authentication flow

Approval Recommendation

Approve with caveats

✅ Should approve after addressing:

  • Rate limiting for key management endpoints
  • Fix hardcoded frontend route references
  • Improve clipboard error handling in frontend
  • Add proper loading states in UI
  • Consider adding E2E tests for core flows

The PR significantly enhances the product with valuable administrative capabilities while maintaining good architectural practices. The main concerns are around operational security and some UX details that would benefit from refinement.

The afterEach cleanup was removing the entire __tests__ directory
by calling fs.remove(path.dirname(testFilePath)). This deleted the
test file itself after running tests.

Removed the problematic line - only clean up the test data files,
not the directory containing the test file.
@j4ys0n
Copy link
Copy Markdown
Owner Author

j4ys0n commented Dec 17, 2025

Automated review 🤖

Summary of Changes

This pull request introduces a comprehensive frontend UI for managing API keys within the LLM proxy system. It adds a Vue 3-based administration panel with features for creating, listing, and deleting API keys, along with analytics tracking capabilities. The backend is enhanced with new API endpoints for key management and analytics, alongside improved authentication mechanisms including cookie-based session handling. The documentation has been significantly expanded to reflect these new features and updated deployment instructions.

Key Changes & Positives

  • 🟢 Adds complete Vue 3 frontend for API key management with tabbed interface (keys/analytics)
  • 🟢 Implements robust API key lifecycle management (create/list/delete) with validation
  • 🟢 Introduces analytics dashboard showing request tracking per key with CSV persistence
  • 🟢 Enhances authentication with cookie-based sessions for web UI and Bearer tokens for API clients
  • 🟢 Updates README with detailed setup instructions, security practices, and API reference
  • 🟢 Adds comprehensive unit and integration tests for new components and controllers
  • 🟢 Improves CI workflow with dedicated test job and proper Docker build sequence

Potential Issues & Recommendations

  1. Issue / Risk: Frontend lacks loading states during API operations

    • Impact: Poor UX during slow network conditions
    • Recommendation: Add loading spinners and disabled buttons during async operations
    • Status: 🟡 Needs review
  2. Issue / Risk: Clipboard functionality fallback is limited to alerts

    • Impact: User experience degradation in non-HTTPS environments
    • Recommendation: Implement more robust fallback (textarea selection) or warn users upfront
    • Status: 🟡 Needs review
  3. Issue / Risk: Analytics date filtering doesn't validate date ranges properly

    • Impact: Potential incorrect data retrieval
    • Recommendation: Add client-side validation for date range consistency
    • Status: 🔴 Problem
  4. Issue / Risk: Missing rate limiting on sensitive endpoints

    • Impact: Potential abuse of key management and analytics endpoints
    • Recommendation: Implement rate limiting middleware for key management routes
    • Status: 🔴 Problem
  5. Issue / Risk: API key deletion doesn't invalidate cached tokens immediately

    • Impact: Possible continued access after deletion
    • Recommendation: Invalidate related session caches upon key deletion
    • Status: 🟡 Needs review

Language/Framework Checks

  • TypeScript/Node: ✅ Good use of interfaces, proper error handling, async/await patterns
  • Vue 3: ✅ Modern composition API usage, reactive state management
  • Express/Node: ✅ Proper middleware chaining, structured route organization
  • Testing: ✅ Jest framework with good coverage for controllers and utils

Security & Privacy

  • 🟢 HttpOnly cookies implemented for web UI authentication
  • 🟢 Secure flag applied conditionally based on NODE_ENV
  • 🟢 Input validation added for all API endpoints
  • 🟢 API keys stored securely with proper formatting (64-char hex)
  • 🔴 JWT secret hardcoded in some places (needs improvement)

Build/CI & Ops

  • ✅ Updated Dockerfile builds both frontend and backend correctly
  • ✅ Added proper .dockerignore rules
  • ✅ Enhanced CI workflow with separate test job
  • ✅ Improved package.json build script includes frontend assets

Tests

  • ✅ Added comprehensive unit tests for API key management
  • ✅ Added analytics controller tests with edge cases
  • ✅ Tests cover validation, error handling, and happy paths
  • 🟡 Missing integration tests for full flow between frontend/backend

Approval Recommendation

Approve with caveats

The PR introduces valuable API key management functionality with a well-designed frontend and robust backend implementation. However, several security and UX concerns need addressing:

  • Fix analytics date range validation issue
  • Address potential rate limiting gaps on sensitive endpoints
  • Improve clipboard fallback UX
  • Consider immediate cache invalidation on key deletion
  • Review JWT secret handling best practices

Once these items are addressed, the PR will be ready for merging. The core functionality is solid and provides significant value to users.

tsconfig.json is required for the TypeScript build to work.
Removing it from .dockerignore caused tsc to fail in Docker builds.
@j4ys0n
Copy link
Copy Markdown
Owner Author

j4ys0n commented Dec 17, 2025

Automated review 🤖

Summary of Changes

This pull request introduces a comprehensive frontend UI for managing API keys within the LLM proxy system. It adds a Vue 3-based administration panel with features for creating, listing, and deleting API keys, along with analytics tracking capabilities. The backend is enhanced with new API endpoints for key management and analytics, including validation schemas, authentication middleware, and request tracking functionality. The documentation has been significantly updated to reflect these new features and usage patterns.

Key Changes & Positives 🟢

  • Frontend Implementation: Adds a complete Vue 3 UI with tabs for API key management and analytics dashboard (🟢)
  • New Backend Controllers: Implements dedicated controllers for API key CRUD operations and analytics retrieval (🟢)
  • Enhanced Authentication: Introduces cookie-based authentication alongside existing Bearer token support (🟢)
  • Request Analytics: Adds request tracking with CSV persistence and date-range filtering (🟢)
  • Comprehensive Documentation: Updates README with detailed instructions, security practices, and API reference (🟢)

Potential Issues & Recommendations

  1. Issue / Risk: Frontend lacks proper loading states during API calls

    • Impact: User experience degradation during slow network conditions
    • Recommendation: Implement loading spinners and disabled buttons during async operations
    • Status: 🟡 Needs review
  2. Issue / Risk: API key deletion confirmation UX could be improved

    • Impact: Potential accidental key deletions
    • Recommendation: Replace confirm dialog with modal overlay showing key details
    • Status: 🟡 Needs review
  3. Issue / Risk: Analytics table sorting/filtering limitations

    • Impact: Limited usability for large datasets
    • Recommendation: Add client-side pagination and column sorting
    • Status: 🟡 Needs review
  4. Issue / Risk: Clipboard fallback mechanism in frontend

    • Impact: May fail silently in insecure contexts
    • Recommendation: Improve error handling and user feedback for clipboard operations
    • Status: 🟡 Needs review

Language/Framework Checks

  • TypeScript/Node: ✅ Proper use of interfaces, async/await, and error handling
  • Vue 3: ✅ Composition API usage, reactive state management, scoped styles
  • Express/Node: ✅ Middleware pattern, route organization, CORS configuration
  • Joi: ✅ Schema validation for inputs, proper error messages
  • Testing: ✅ Jest unit tests for controllers and utility classes

Security & Privacy

  • Authentication: ✅ HttpOnly cookies with secure flags, JWT-based session management
  • Input Validation: ✅ Joi schemas prevent malformed requests
  • API Keys: ✅ 64-character hex keys, in-memory validation cache
  • CORS: ✅ Configurable origins with credentials support

Build/CI & Ops

  • Docker: ✅ Multi-stage build with frontend compilation included
  • Workflow: ✅ CI pipeline includes testing step, builds on PR events
  • Deployment: ✅ Updated docker-compose example with new ports and mounts

Tests

  • Unit Tests: ✅ Coverage for API key management, analytics controller, and validation
  • Test Strategy: ✅ Mocked dependencies, edge case testing for validation
  • Missing: ✅ Integration tests for full frontend/backend flows

Approval Recommendation

Approve with caveats

Approved - Core functionality works well and follows modern practices

⚠️ Caveats:

  • Frontend UX improvements needed for better user experience
  • Additional error handling for clipboard operations
  • Consider adding pagination for analytics tables
  • More comprehensive integration testing would improve confidence

@j4ys0n j4ys0n merged commit dcb08f8 into main Dec 17, 2025
2 checks passed
@j4ys0n j4ys0n deleted the claude/add-api-key-management-yJiMg branch December 17, 2025 03:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants