Skip to content

Justin/credit admin page#4729

Merged
chitalian merged 32 commits intomainfrom
justin/credit-admin-page
Sep 29, 2025
Merged

Justin/credit admin page#4729
chitalian merged 32 commits intomainfrom
justin/credit-admin-page

Conversation

@chitalian
Copy link
Contributor

No description provided.

@vercel
Copy link

vercel bot commented Sep 11, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
helicone Ready Ready Preview Comment Sep 29, 2025 5:28am
helicone-eu Ready Ready Preview Comment Sep 29, 2025 5:28am
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
helicone-bifrost Skipped Skipped Sep 29, 2025 5:28am

@claude

This comment was marked as resolved.

greptile-apps[bot]

This comment was marked as resolved.

@promptless
Copy link
Contributor

promptless bot commented Sep 11, 2025

📝 Documentation updates detected!

New suggestion: Add admin API documentation for wallet management endpoints from PR #4729

@vercel vercel bot temporarily deployed to Preview – helicone-bifrost September 11, 2025 21:24 Inactive
@vercel vercel bot temporarily deployed to Preview – helicone-eu September 11, 2025 21:25 Inactive
@vercel vercel bot temporarily deployed to Preview – helicone-bifrost September 11, 2025 21:25 Inactive
@vercel vercel bot temporarily deployed to Preview – helicone September 11, 2025 21:25 Inactive
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
@vercel vercel bot temporarily deployed to Preview – helicone-eu September 11, 2025 21:32 Inactive
@vercel vercel bot temporarily deployed to Preview – helicone September 11, 2025 21:32 Inactive
@vercel vercel bot temporarily deployed to Preview – helicone-bifrost September 11, 2025 21:32 Inactive
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
@vercel vercel bot temporarily deployed to Preview – helicone-bifrost September 11, 2025 21:32 Inactive
@vercel vercel bot temporarily deployed to Preview – helicone-eu September 11, 2025 21:32 Inactive
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
@vercel vercel bot temporarily deployed to Preview – helicone September 11, 2025 21:32 Inactive
@vercel vercel bot temporarily deployed to Preview – helicone-eu September 11, 2025 21:32 Inactive
@vercel vercel bot temporarily deployed to Preview – helicone-bifrost September 11, 2025 21:32 Inactive
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
@vercel vercel bot temporarily deployed to Preview – helicone-bifrost September 11, 2025 21:32 Inactive
@vercel vercel bot temporarily deployed to Preview – helicone September 11, 2025 21:32 Inactive
greptile-apps[bot]

This comment was marked as resolved.

return []; // No PTB endpoints available
}

console.log("HELICONE_ORG_ID", this.env.HELICONE_ORG_ID);
Copy link
Collaborator

Choose a reason for hiding this comment

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

some console logs on this file

@vercel vercel bot temporarily deployed to Preview – helicone September 28, 2025 17:41 Inactive
@vercel vercel bot temporarily deployed to Preview – helicone-bifrost September 28, 2025 17:41 Inactive
@vercel vercel bot temporarily deployed to Preview – helicone-eu September 28, 2025 17:41 Inactive
@vercel vercel bot temporarily deployed to Preview – helicone-eu September 28, 2025 17:44 Inactive
@vercel vercel bot temporarily deployed to Preview – helicone-bifrost September 28, 2025 17:44 Inactive
@vercel vercel bot temporarily deployed to Preview – helicone September 28, 2025 17:44 Inactive
@Helicone Helicone deleted a comment from claude bot Sep 28, 2025
@chitalian
Copy link
Contributor Author

@greptile

@chitalian
Copy link
Contributor Author

@claude please re-review

@claude
Copy link
Contributor

claude bot commented Sep 28, 2025

Claude finished @chitalian's task —— View job


Re-reviewing Credit Admin Page PR

Todo List:

  • Read and analyze key files for current state
  • Check for syntax errors and compilation issues
  • Review security vulnerabilities (SQL injection, exposed secrets)
  • Assess admin authentication and authorization
  • Review overall architecture and code quality
  • Provide comprehensive review feedback

🔍 Review Summary

Good news! Previous critical syntax errors have been resolved, and the overall implementation is much improved. However, several issues remain that should be addressed:

What's Working Well

  1. Fixed Compilation Issues: The variable name collision (params declared twice) in adminController.ts:1716 has been resolved
  2. Proper SQL Injection Protection: The Wallet.ts now uses hardcoded switch statements instead of dynamic SQL, which is excellent security practice
  3. Strong Authentication: Admin endpoints properly use authCheckThrow() and HELICONE_MANUAL_ACCESS_KEY validation
  4. Good Architecture: Clean separation between Jawn (auth proxy) → Worker API → Wallet Durable Objects
  5. Input Validation: Table name whitelisting and pagination parameter validation are implemented correctly

⚠️ Issues to Address

1. Security Concerns (Medium Priority)

  • Production Stripe Product ID in Config: worker/wrangler.toml:97 contains prod_StWk1FmJ88b9Ju which should be externalized to environment variables
  • Debug Console Log: adminController.ts:475 has console.log("getTopOrgs"); that should be removed for production

2. SQL Injection Risk (High Priority)

  • ClickHouse Query: adminController.ts:138 still uses dynamic IN clause construction:
    WHERE organization_id IN (${orgIds.map(() => "?").join(",")})
    Should use parameterized queries or ANY($1) syntax instead

3. Code Quality (Low Priority)

  • Pagination Limits: Could add stricter validation on page sizes (currently allows up to 1000 items)

🏗️ Architecture Assessment

The admin credit management system follows a solid architecture:

Admin User → Web Frontend → Jawn API (auth) → Worker API (admin token) → Wallet DO

Strengths:

  • Proper admin authentication at multiple layers
  • Clean separation of concerns
  • Good error handling and Result types
  • Comprehensive wallet state inspection capabilities

Frontend Implementation (adminWallet.tsx):

  • Well-structured React component with proper loading states
  • Good use of TanStack Query for data fetching
  • Clean UI with comprehensive wallet inspection tools

📋 Recommended Actions

  1. Fix SQL injection in ClickHouse query (High priority)
  2. Externalize Stripe product ID from wrangler.toml
  3. Remove debug console.log statement
  4. Consider adding rate limiting for admin endpoints
  5. Add audit logging for admin wallet inspections

🎯 Overall Assessment

This PR represents a significant improvement from the initial state. The core functionality is solid, authentication is properly implemented, and the previous critical compilation errors have been resolved. The remaining issues are manageable and don't prevent the core functionality from working safely.

Recommendation: Approve with minor fixes - The SQL injection issue should be addressed before merge, but the overall implementation is production-ready.


Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Greptile Overview

Summary

This PR introduces a comprehensive admin wallet management interface for Helicone's credit system. The changes span across multiple layers: backend API endpoints, frontend components, and worker infrastructure.

Key Changes:

  • Admin Controller: Added new endpoints for wallet management including dashboard data, wallet details, and table inspection capabilities
  • Frontend Dashboard: New React component providing a detailed view of organizations with pass-through billing, including balance tracking and Stripe integration
  • Worker Integration: Enhanced wallet durable object with table data access methods for admin inspection
  • Type Definitions: Updated TypeScript interfaces and auto-generated API types

Architecture:
The implementation follows a three-tier architecture where the web frontend calls Jawn backend endpoints, which then communicate with the Worker API to access wallet durable objects. This provides admins with visibility into credit purchases, spending, escrow amounts, and detailed transaction data.

Main Concerns:

  • SQL Injection Vulnerabilities: Multiple endpoints in the admin controller construct queries with string interpolation instead of parameterized queries
  • Parameter Validation Issues: Inconsistent validation and usage of pagination parameters
  • Security: Admin endpoints rely on proper authentication but contain exploitable query construction

Confidence Score: 2/5

  • This PR contains critical SQL injection vulnerabilities that make it unsafe to merge without fixes
  • Score reflects multiple SQL injection vulnerabilities in admin endpoints that could allow unauthorized database access, despite otherwise well-structured wallet management functionality
  • valhalla/jawn/src/controllers/private/adminController.ts requires immediate attention for SQL injection fixes before merge

Important Files Changed

File Analysis

Filename        Score        Overview
valhalla/jawn/src/controllers/private/adminController.ts 2/5 Added wallet admin endpoints with SQL injection vulnerabilities, improper parameter validation, and security concerns
valhalla/jawn/src/managers/creditsManager.ts 4/5 Credit balance management functions using external Worker API calls - implementation looks sound
web/components/templates/admin/adminWallet.tsx 3/5 React component for admin wallet dashboard with query parameter handling issues but otherwise well-structured
worker/src/lib/durable-objects/Wallet.ts 4/5 Comprehensive wallet implementation with proper SQL handling, transaction management, and security controls

Sequence Diagram

sequenceDiagram
    participant Admin as Admin User
    participant Web as Web Frontend
    participant Jawn as Jawn Backend
    participant Worker as Worker API
    participant Wallet as Wallet DO
    participant Stripe as Stripe API
    participant CH as ClickHouse DB
    
    Admin->>Web: Access /admin/wallet
    Web->>Jawn: POST /v1/admin/gateway/dashboard_data
    Jawn->>CH: Query organizations with payments
    Jawn->>CH: Query ClickHouse spending data
    CH->>Jawn: Return spending metrics
    Jawn->>Web: Return dashboard summary
    Web->>Admin: Display org list with balances
    
    Admin->>Web: Click "View Details" for org
    Web->>Jawn: POST /v1/admin/wallet/{orgId}
    Jawn->>Worker: GET /admin/wallet/{orgId}/state
    Worker->>Wallet: getWalletState(orgId)
    Wallet->>Worker: Return wallet state (balance, escrow, etc.)
    Worker->>Jawn: Return wallet details
    Jawn->>Web: Return wallet state
    Web->>Admin: Display wallet details dialog
    
    Admin->>Web: Select table to inspect
    Web->>Jawn: POST /v1/admin/wallet/{orgId}/tables/{tableName}
    Jawn->>Worker: GET /admin/wallet/{orgId}/tables/{tableName}
    Worker->>Wallet: getTableData(tableName, page, pageSize)
    Wallet->>Worker: Return raw table data
    Worker->>Jawn: Return table data
    Jawn->>Web: Return paginated table data
    Web->>Admin: Display raw table data
    
    Admin->>Web: Click Stripe link
    Web->>Stripe: Open customer dashboard (external)
    
    Note over Admin,Stripe: Admin can view comprehensive credit<br/>management across multiple systems
Loading

16 files reviewed, 5 comments

Edit Code Review Agent Settings | Greptile

Comment on lines +1680 to +1682
// Validate pagination parameters
const validatedPage = Math.max(0, page ?? 0);
const validatedPageSize = Math.min(Math.max(1, pageSize ?? 50), 100);
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Incorrect validation order creates duplicate URLSearchParams instance and doesn't use validated parameters

Prompt To Fix With AI
This is a comment left during a code review.
Path: valhalla/jawn/src/controllers/private/adminController.ts
Line: 1680:1682

Comment:
logic: Incorrect validation order creates duplicate URLSearchParams instance and doesn't use validated parameters

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +1715 to +1718
// Build query params for pagination
const params = new URLSearchParams();
if (page !== undefined) params.set("page", page.toString());
if (pageSize !== undefined) params.set("pageSize", pageSize.toString());
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: URLSearchParams created twice - first validated params are unused in favor of potentially invalid raw params

Prompt To Fix With AI
This is a comment left during a code review.
Path: valhalla/jawn/src/controllers/private/adminController.ts
Line: 1715:1718

Comment:
logic: URLSearchParams created twice - first validated params are unused in favor of potentially invalid raw params

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +137 to +140
const response = await (jawn as any).POST(
`/v1/admin/wallet/${selectedOrg}/tables/${selectedTable}?page=${tablePage}&pageSize=50`,
{},
);
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Query parameters incorrectly constructed - pagination params should use validated values from state

Prompt To Fix With AI
This is a comment left during a code review.
Path: web/components/templates/admin/adminWallet.tsx
Line: 137:140

Comment:
logic: Query parameters incorrectly constructed - pagination params should use validated values from state

How can I resolve this? If you propose a fix, please make it concise.

@vercel vercel bot temporarily deployed to Preview – helicone-bifrost September 29, 2025 05:19 Inactive
@chitalian chitalian merged commit cc5b58d into main Sep 29, 2025
8 of 9 checks passed
@chitalian chitalian deleted the justin/credit-admin-page branch September 29, 2025 05:23
juliettech13 pushed a commit that referenced this pull request Sep 29, 2025
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